Skip to content

Commit

Permalink
Merge pull request #1415 from maxencelaurent/issue1414
Browse files Browse the repository at this point in the history
Issue1414 - Override InputStream.available() in DataInputStream
  • Loading branch information
lprimak authored and Pandrex247 committed Mar 27, 2017
1 parent 53d357e commit 8c0d509
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,22 @@ public int read(byte[] b, int off, int len) throws IOException {
return doRead(b, off, len);
}

@Override
public int available() throws IOException {
RandomAccessFile file = this.file;
if (file == null) {
file = RandomAccessDataFile.this.filePool.acquire();
file.seek(RandomAccessDataFile.this.offset + this.position);
}
try {
return (int) (file.length() - this.position);
} finally {
if (this.file == null) {
RandomAccessDataFile.this.filePool.release(file);
}
}
}

/**
* Perform the actual read.
* @param b the bytes to read or {@code null} when reading a single byte
Expand Down

0 comments on commit 8c0d509

Please sign in to comment.