re PR libgcj/27271 (i/o error (java.util.zip.ZipException: Deflated stream ends early.))
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. From-SVN: r115378
This commit is contained in:
parent
93e890688c
commit
e9186fbe67
2 changed files with 35 additions and 5 deletions
|
@ -445,6 +445,7 @@ public class ZipFile implements ZipConstants
|
|||
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)
|
||||
|
@ -520,6 +521,11 @@ public class ZipFile implements ZipConstants
|
|||
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
|
||||
|
@ -540,8 +546,17 @@ public class ZipFile implements ZipConstants
|
|||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -555,7 +570,7 @@ public class ZipFile implements ZipConstants
|
|||
|
||||
public int read() throws IOException
|
||||
{
|
||||
if (bufferOffset + pos >= end)
|
||||
if (bufferOffset + pos >= end + dummyByteCount)
|
||||
return -1;
|
||||
if (pos == buffer.length)
|
||||
{
|
||||
|
@ -569,9 +584,9 @@ public class ZipFile implements ZipConstants
|
|||
|
||||
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;
|
||||
}
|
||||
|
@ -681,5 +696,10 @@ public class ZipFile implements ZipConstants
|
|||
throw new AssertionError(uee);
|
||||
}
|
||||
}
|
||||
|
||||
public void addDummyByte()
|
||||
{
|
||||
dummyByteCount = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue