+2006-07-12 Tom Tromey <tromey@redhat.com>
+
+ PR libgcj/27271:
+ * java/util/zip/ZipFile.java (getInputStream): Call addDummyByte
+ on PartialInputStream.
+ (PartialInputStream.dummyByteCount): New field.
+ (PartialInputStream.fillBuffer): Handle dummy byte.
+ (PartialInputStream.read): Likewise.
+ (PartialInputStream.addDummyByte): New method.
+
2006-06-14 Tom Tromey <tromey@redhat.com>
PR java/28024:
case ZipOutputStream.STORED:
return inp;
case ZipOutputStream.DEFLATED:
+ inp.addDummyByte();
final Inflater inf = new Inflater(true);
final int sz = (int) entry.getSize();
return new InflaterInputStream(inp, inf)
private long bufferOffset;
private int pos;
private long end;
+ // We may need to supply an extra dummy byte to our reader.
+ // See Inflater. We use a count here to simplify the logic
+ // elsewhere in this class. Note that we ignore the dummy
+ // byte in methods where we know it is not needed.
+ private int dummyByteCount;
public PartialInputStream(RandomAccessFile raf, int bufferSize)
throws IOException
{
synchronized (raf)
{
- raf.seek(bufferOffset);
- raf.readFully(buffer, 0, (int) Math.min(buffer.length, end - bufferOffset));
+ long len = end - bufferOffset;
+ if (len == 0 && dummyByteCount > 0)
+ {
+ buffer[0] = 0;
+ dummyByteCount = 0;
+ }
+ else
+ {
+ raf.seek(bufferOffset);
+ raf.readFully(buffer, 0, (int) Math.min(buffer.length, len));
+ }
}
}
public int read() throws IOException
{
- if (bufferOffset + pos >= end)
+ if (bufferOffset + pos >= end + dummyByteCount)
return -1;
if (pos == buffer.length)
{
public int read(byte[] b, int off, int len) throws IOException
{
- if (len > end - (bufferOffset + pos))
+ if (len > end + dummyByteCount - (bufferOffset + pos))
{
- len = (int) (end - (bufferOffset + pos));
+ len = (int) (end + dummyByteCount - (bufferOffset + pos));
if (len == 0)
return -1;
}
throw new AssertionError(uee);
}
}
+
+ public void addDummyByte()
+ {
+ dummyByteCount = 1;
+ }
}
}