private RandomAccessFile in;
- private int mark = 0;
+ private long mark = 0;
/**
* Construct RandomAccessInputStream from file.
@Override
public final int available() throws IOException {
- return getLength() - getPos();
+ long available = length() - position();
+ if (available > Integer.MAX_VALUE) {
+ return Integer.MAX_VALUE;
+ }
+ return (int) available;
}
@Override
* @return length of file in byte.
* @exception IOException if an I/O error has occurred.
*/
+ public final long length() throws IOException {
+ return in.length();
+ }
+
public final int getLength() throws IOException {
- return (int) in.length();
+ return (int) length();
}
+
/**
* Get cursor position.
*
* @return position in byte.
* @exception IOException if an I/O error has occurred.
*/
+ public final long position() throws IOException {
+ return in.getFilePointer();
+ }
+
+ @Deprecated
public final int getPos() throws IOException {
- return (int) in.getFilePointer();
+ return (int) position();
}
@Override
public final synchronized void mark(final int markpos) {
try {
- mark = getPos();
+ mark = position();
} catch (IOException e) {
throw new RuntimeException(e.toString());
}
out.seek(pos);
}
+ /**
+ * Get file position;
+ * @return position
+ * @throws IOException if on I/O error occurred
+ */
+ public final long position() throws IOException {
+ return out.getFilePointer();
+ }
+
+ /**
+ * Get file length.
+ * @return length of file.
+ * @throws IOException when on I/O error occurred
+ */
+ public final long length() throws IOException {
+ return out.length();
+ }
}
@Test
public void testGetLength() throws Exception {
RandomAccessInputStream instance = new RandomAccessInputStream(dataFile, "r");
- int expResult = 136856;
- int result = instance.getLength();
+ long expResult = 136856L;
+ long result = instance.length();
assertEquals(result, expResult);
}
@Test
public void testGetPos() throws Exception {
RandomAccessInputStream instance = new RandomAccessInputStream(dataFile, "r");
- int expResult = 0;
- int result = instance.getPos();
+ long expResult = 0L;
+ long result = instance.position();
assertEquals(result, expResult);
}