Menu

#7 ByteArrayInputStream

open
nobody
None
5
2014-08-17
2002-12-23
Ricardo Fig
No

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

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.