From: Jochen H. <Hoe...@In...> - 2004-05-13 16:24:55
|
On Wednesday 12 May 2004 19:37, dddddd dddddd wrote: > I use version 0.06 > > I have found a solution to the problem but I had to change the way I read > the entry. > > This is what I was doing: > byte[] finalFile = null; > try { > > ByteArrayInputStream bais = new ByteArrayInputStream(archivo); > ZipInputStream zip = new ZipInputStream(bais); > ZipEntry anEntry = zip.getNextEntry(); > > while (anEntry != null) { > long decompressedSize = anEntry.getSize(); > byte[] uncompressedBuf = new byte[(int)decompressedSize]; > zip.read(uncompressedBuf); What you want is new DataInputStream(zip).readFully(uncompressedBuf); The read method in InputStream is allowed to return early. From the JDK1.4 spec (InputStream.java): public int read(byte[] b) throws IOException Reads some number of bytes from the input stream and stores them into the buffer array b. The number of bytes actually read is returned as an integer. This method blocks until input data is available, end of file is detected, or an exception is thrown. If b is null, a NullPointerException is thrown. If the length of b is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value -1 is returned; otherwise, at least one byte is read and stored into b. The only thing the ZipInputStream spec says about zip.read (emphasis by me): Reads from the current ZIP entry into an array of bytes. Blocks until *some* input is available. Regards, Jochen -- Jochen Hoenicke, University of Oldenburg, 26111 Oldenburg, Germany Email: hoe...@in... Tel: +49 441 798 3124 |