staroski 4 de set. de 2023
Usa um ZipInputStream para ler cada Tag dessas.
fmbjava 5 de set. de 2023 1 like
bom dia
obrigado staroski pela dica , vou pesquisar essa alguns exemplos ZipInputStream
abraço
fmbjava 5 de set. de 2023
Boa tarde
Analisei esse ZipInputStream mas não consegui usar ele na tag das nfe para descompactar, tenho impressão que é somente arquivo .zip e não xml.
abraço
lucashpmelo 5 de set. de 2023
Boa tarde, não sou desenvolvedor Java, mas acredito que no seu caso deveria ser usado o GZIPInputStream . Igual é feito nessa duvida no Stack Overflow:
java, compression, gzip
lucashpmelo 5 de set. de 2023
@fmbjava , fiz alguns testes seguindo esse exemplo do GZIPInputStream e parece ter dado certo:
import java.io.* ;
import java.util.Base64 ;
import java.util.zip.GZIPInputStream ;
import java.util.zip.GZIPOutputStream ;
public class Main
{
public static String compress ( String str ) throws IOException {
if ( str == null || str . length () == 0 ) {
return str ;
}
ByteArrayOutputStream out = new ByteArrayOutputStream ();
GZIPOutputStream gzip = new GZIPOutputStream ( out );
gzip . write ( str . getBytes ());
gzip . close ();
String outStr = new String ( Base64 . getEncoder (). encode ( out . toByteArray ()));
return outStr ;
}
public static String decompress ( String str ) throws IOException {
if ( str == null || str . length () == 0 ) {
return str ;
}
GZIPInputStream gis = new GZIPInputStream ( new ByteArrayInputStream ( Base64 . getDecoder (). decode ( str )));
ByteArrayOutputStream out = new ByteArrayOutputStream ();
byte [] buffer = new byte [ 256 ] ;
int n ;
while (( n = gis . read ( buffer )) >= 0 ) {
out . write ( buffer , 0 , n );
}
return new String ( out . toByteArray ());
}
public static void main ( String [] args ) throws IOException {
String compressed = compress ( "<?xml version='1.0' encoding='utf-8'?><soap12:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap12='http://www.w3.org/2003/05/soap-envelope'><soap12:Body><nfeDistDFeInteresse xmlns='http://www.portalfiscal.inf.br/nfe/wsdl/NFeDistribuicaoDFe'><nfeDadosMsg><distDFeInt xmlns='http://www.portalfiscal.inf.br/nfe' versao='1.01'><tpAmb>1</tpAmb><cUFAutor>35</cUFAutor><CNPJ>XXXXXXXXXXXXXX</CNPJ><consChNFe><chNFe>00000000000000000000000000000000000000000000</chNFe></consChNFe></distDFeInt></nfeDadosMsg></nfeDistDFeInteresse></soap12:Body></soap12:Envelope>" );
System . out . println ( "XML para String Gzip:" );
System . out . println ( compressed );
String decomp = decompress ( "H4sIAAAAAAAAAJVSUUvDMBD+K33LU3vtxkBGljE3C4obggh7TdN0DbRJyWXr/PfGdlY7FPVecnfc9913H6HLc10FJ2lRGb0gSRSTQGphcqUPC3J0RXhDloyi4U0ymd/pk6xMIwMP0jg/o1qQ0rlmDtC2bdROI2MPMInjBPbbx2dRypqHSqPjWkgyoPLfUR/D/eIf5qcQz+B9IpQXYWSQemvyV0Z1ITcK3SaV99pJKxEv2keMjbGOV4VCwatI6SLKLHgktJhXsEs7CquyoxLceCrS8/Lc4BYPjObDhr9zk85zbjrLE8/omlWdsYRCn1Dxkq6Ozlg2nVEYCrrePT2w/SgodE0qjMZ16eX6tHvif4Tf0UPhCw18XuaL0c3wjbO+OzIfrn4NewNFEXh4bQIAAA==" );
System . out . println ( "String Gzip para XML:" );
System . out . println ( decomp );
}
}
Como não tenho o Java instalado na minha maquina acabei usando uma dessas IDEs Online, não sei se existe alguma diferença.
JDoodle is an Online Compiler, Editor, IDE for Java, C, C++, PHP, Perl, Python, Ruby and many more. You can run your programs on the fly online, and you can save and share them with others. Quick and Easy way to compile and run programs online.
fmbjava 6 de set. de 2023 1 like
bom dia
lucas show de bola , deu certinho meu amigo , agradeço pela ajuda.
abraço