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STUU9yRgRLsV92T3yXoj8otc7WUV4OdSbr6tfYCevraZE3FJ5a9etSMxrpm5ZprlheLvd3p6d0xOQvlqCyXWKnq6/5IpfT5ZeMu3W1yrzGkFPVuakV09V5pRTX63Mqww9VXqzSOBC5JdLc9Kr/2FpnvKaqZOlOSb4w2y8pSanN7fuUtdZhRW0+SJrPvgGCzHxxXKfP/gExIt5upw/pHC3ieBBCm5rTkh897753fnjJHIg/4HtZRe3/im95U8sTVXPghun/+5szq8R3LMyRQTdwJ3Ah5oOrAAjKWCxmLOadV/hyQnSAf7aAAdTHigB2erAr/k8/fCOwjhbZ7ZNw/x+tVymKzjZRkQ/ayQaW3HGk/HN+m9QSwcI78e6fhgEAACNDwAAUEsBAhQAFAAIAAgAeGgQQ+/Hun4YBAAAjQ8AAAEAAAAAAAAAAAAAAAAAAAAAADFQSwUGAAAAAAEAAQAvAAAARwQAAAAA");
    byte[] resByte=new byte[11474836];

    resByte=Base64.decode(request.toString().getBytes());

    InputStream input = new ByteArrayInputStream(resByte);

    byte[] readByte = new byte[11474836];

    ZipInputStream zip = new ZipInputStream(input);
    int noofbyteRead = 0;

    if ( zip.getNextEntry() != null )
    {
        noofbyteRead = zip.read(readByte);
    }
    byte[] writeByte = new byte[ noofbyteRead ];
    System.arraycopy( readByte,0,writeByte,0,noofbyteRead);

    zip.close();
    input.close();


    /* String actualXmlmessage = new String(writeByte);*/
    String s1 = new String(writeByte);
    System.out.println(s1);

s1只显示一半的内容。为什么它没有阅读完整的内容?

4

1 回答 1

0

在回答这个问题之前,让我先发表一些评论:

无需String从 String 常量创建新的。

String request= "UEsDBBQACAAIAHhoE....." ;

Base64.decode不接收byte[]保存结果。因此,它很可能正在创建它返回的那个。因此,resByte不需要初始化。 resByte的声明应该只是

byte[] resByte;

也就是说,没有更多细节,指令String s1 = new String(writeByte);将使用平台默认编码(如果您没有手动设置,这取决于操作系统和操作系统配置)。如果您的编码是 UTF-16(其中每个字符对应于 2 个字节),那么您将获得的字符数正好是writeByte.

如果s1看起来乱码(这与“一半内容”甚至“只是内容”有很大不同,您应该在问题中指出这一点),那么这几乎是肯定的。

解决方案是使用:

String s1= new String(writeByte,charSetName) ;

wherecharSetName对应于原始输入的字符集(不仅在它被 base-64 编码之前,甚至在它被压缩之前)。

于 2013-08-18T08:46:43.520 回答