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U9yRgRLsV92T3yXoj8otc7WUV4OdSbr6tfYCevraZE3FJ5a9etSMxrpm5ZprlheLvd3p6d0xOQvlqCyXWKnq6/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
仅显示一半内容。为什么不阅读全部内容?
答案 0 :(得分: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) ;
其中charSetName
对应于非常原始输入的字符集(不仅在它是base-64编码之前,甚至在它被压缩之前)。