Ajuda-Base64.decode não funciona

0 respostas
juliocesarsrosa

ola galera !! estou com um problema e gostaria da ajuda de vcs…
tenho uma variavel que recebe uma string… que depois é codificada em base 64 …

ou seja eu codifico em base 64 para depois testar a descodificação… em base64
a codificação funciona ele bagunça os caracteres… certinho… porem nao consigo descodificalos depois …
segue meu código

package com.eversystems.il.tester.jms;

import static com.eversystems.il.util.IntegLayerErrorCodes.ERROR_XML_IN;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;

import com.eversystems.il.handle.core.HandleException;
import com.eversystems.il.main.IntegLayerException;
import com.eversystems.il.util.DateUtil;
import com.eversystems.il.util.StringUtil;
import com.sun.org.apache.xml.internal.security.exceptions.Base64DecodingException;
import com.sun.org.apache.xml.internal.security.utils.Base64;


public class FT01Teste {

	public static void main(String[] args) throws IOException, IntegLayerException, Base64DecodingException  {
		FT01Teste ft01Teste = new FT01Teste();
		String codigoProduto = "DC";
		String source;
		
		if (codigoProduto.equals("DC")) {

			source = "c:\\";

			buildFile(source);

		}
	}

	private static void buildFile(String source)throws HandleException, IOException, Base64DecodingException {
			FT01Teste ft01Teste = new FT01Teste();
		String value = "Testando conteudo do arquivo Texto...";
	
		value = Base64.encode(value.getBytes());  
		
		File file = new File(source+ft01Teste.buildFileName(ft01Teste));
		
		file.createNewFile();
		FileWriter fw = new FileWriter(file);
		fw.write(decodeFile(value));
		fw.close();
		
		}


	private String buildFileName(FT01Teste ft01Teste) throws HandleException{
		String fileName = "";
		String name = "julio";
		String clientCode = "4563456";
		String data = "";
		String nome = "cesar.txt";
		String codigo = "32131";
		
		try {
			name = StringUtil.truncString(nome, '.');
			clientCode = codigo;
			data = DateUtil.toString(new Date(), "ddMMyyyy");
			
			fileName = name+clientCode+"_"+data+".txt";
		} catch (Exception e) {
			throw new HandleException(ERROR_XML_IN, "Dados invalidos para formar o nome do arquivo: name:"+name+" clientCode:"+clientCode+"\n", e);
		}
		
		
		return fileName;
	}
	
	
	
	
	private static String decodeFile(String value) throws Base64DecodingException{// aki ele nao esta conseguindo decodificar... 
		byte[] decodeFile = Base64.decode(value.getBytes());
		new ByteArrayInputStream(decodeFile);

		return value;
		
	}
	
	

}

algm sabe o que pode ser??

obrigado

Criado 2 de junho de 2011
Respostas 0
Participantes 1