Hello,
I am working in a framework, that reads any file
automatically...
and I receive a String from every file read it.
well.
If I do the follow:
String file; // this is the receiving file as string
ZipInputStream zipFile = null;
try {
zipFile = new ZipInputStream(new
ByteArrayInputStream(file.getBytes()));
} catch (Exception e) {
e.printStackTrace();
}
--------
At this point everything is ok, I can also use the
ZipEntry:
ZipEntry entry;
while ((entry = zipFile.getNextEntry())!=null) {
------
And of course at this point everything seems to be ok...
because it gets the first entry.
but here is the problem... when I invoke a read method,
then it crash....
protected String readBytes(InputStream in) {
byte[] buffer = new byte[1000];
String buf = new String();
try {
for (int len = in.read(buffer); len > 0; len = in.read
(buffer)) {
buf += new String(buffer, 0, len);
}
} catch (IOException e) {
e.printStackTrace();
}
return buf; //out.toByteArray();
}
------
this crash ar the "for (int.... in.read(buffer)...."
net.sf.jazzlib.ZipException
at net.sf.jazzlib.InflaterInputStream.read
(InflaterInputStream.java:194)
at net.sf.jazzlib.ZipInputStream.read
(ZipInputStream.java:293)
at java.io.FilterInputStream.read
(FilterInputStream.java:88)
-----
How can I solve this problem?
this is a bug?
thank you...
(if I do the same, but instead of the bytearray, I open the
file directly, then it works perfect... but I need to do it
using the framwork..)
thank in advance
my email is r.fig@fact.es
Logged In: NO
Obviously, String.getBytes() uses an encoding. Zipped data
is binary, not character, and should not be passed through
an encoding if you still want to unzip.