/** {@inheritDoc} */ public int read() throws IOException { synchronized (file) { int retval = -1; if (currentPosition < endPosition) { file.seek(currentPosition); currentPosition++; retval = file.read(); } return retval; } }
/** {@inheritDoc} */ public int read(byte[] b, int offset, int length) throws IOException { // only allow a read of the amount available. if (length > available()) { length = available(); } int amountRead = -1; // only read if there are bytes actually available, otherwise // return -1 if the EOF has been reached. if (available() > 0) { synchronized (file) { file.seek(currentPosition); amountRead = file.read(b, offset, length); } } // update the current cursor position. if (amountRead > 0) { currentPosition += amountRead; } return amountRead; }