mirror of
https://github.com/corda/corda.git
synced 2025-06-13 12:48:18 +00:00
override InputStream.available for FileInputStream and the instance returned by ZipFile.getInputStream
This commit is contained in:
@ -16,6 +16,7 @@ public class FileInputStream extends InputStream {
|
||||
// }
|
||||
|
||||
private int fd;
|
||||
private int remaining;
|
||||
|
||||
public FileInputStream(FileDescriptor fd) {
|
||||
this.fd = fd.value;
|
||||
@ -23,12 +24,17 @@ public class FileInputStream extends InputStream {
|
||||
|
||||
public FileInputStream(String path) throws IOException {
|
||||
fd = open(path);
|
||||
remaining = (int) new File(path).length();
|
||||
}
|
||||
|
||||
public FileInputStream(File file) throws IOException {
|
||||
this(file.getPath());
|
||||
}
|
||||
|
||||
public int available() throws IOException {
|
||||
return remaining;
|
||||
}
|
||||
|
||||
private static native int open(String path) throws IOException;
|
||||
|
||||
private static native int read(int fd) throws IOException;
|
||||
@ -39,7 +45,11 @@ public class FileInputStream extends InputStream {
|
||||
public static native void close(int fd) throws IOException;
|
||||
|
||||
public int read() throws IOException {
|
||||
return read(fd);
|
||||
int c = read(fd);
|
||||
if (c >= 0 && remaining > 0) {
|
||||
-- remaining;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
public int read(byte[] b, int offset, int length) throws IOException {
|
||||
@ -51,7 +61,11 @@ public class FileInputStream extends InputStream {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
|
||||
return read(fd, b, offset, length);
|
||||
int c = read(fd, b, offset, length);
|
||||
if (c > 0 && remaining > 0) {
|
||||
remaining -= c;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
|
Reference in New Issue
Block a user