private void skipToOffset() throws IOException { long skipped = 0; long toSkip = offset; while (toSkip > 0) { skipped = skip(toSkip); toSkip -= skipped; } // Mark the offset location so we will return here on reset super.mark(0); if (log.isDebugEnabled()) { log.debug("Skipped to segment offset " + offset); } }
@Override public int read() throws IOException { // Ensure we don't read beyond the segment length if (bytesReadPastMarkPoint + getRelativeMarkPoint() >= segmentLength) { return -1; } else { return super.read(); } }
/** * Resets the input stream to the last mark point, or the beginning of the stream if * there is no mark point, by creating a new FileInputStream based on the * underlying file. * * @throws UnrecoverableIOException * when the FileInputStream cannot be re-created. */ @Override public void reset() throws IOException { try { this.fis.close(); this.fis = new FileInputStream(file); long skipped = 0; long toSkip = markPoint; while (toSkip > 0) { skipped = skip(toSkip); toSkip -= skipped; } if (log.isDebugEnabled()) { log.debug("Reset to mark point " + markPoint + " after returning " + bytesReadPastMarkPoint + " bytes"); } this.bytesReadPastMarkPoint = 0; } catch (IOException e) { throw new UnrecoverableIOException("Input stream is not repeatable: " + e.getMessage()); } }
/** * Returns an input stream containing this object's data, or null if there is * no data associated with the object. * <p> * If you are downloading data from a service, you should consider verifying the * integrity of the data you read from this stream using one of the * {@link #verifyData(InputStream)} methods. * * @return * input stream containing the object's service-side data, or null if no data. * * @throws ServiceException */ public InputStream getDataInputStream() throws ServiceException { if (dataInputStream == null && dataInputFile != null) { try { // Use a repeatable file data input stream, so transmissions can be retried if necessary. dataInputStream = new RepeatableFileInputStream(dataInputFile); } catch (FileNotFoundException e) { throw new ServiceException("Cannot open file input stream", e); } } return dataInputStream; }
/** * Resets the input stream to the last mark point, or the beginning of the stream if * there is no mark point, by creating a new FileInputStream based on the * underlying file. * * @throws UnrecoverableIOException * when the FileInputStream cannot be re-created. */ @Override public void reset() throws IOException { try { this.fis.close(); this.fis = new FileInputStream(file); long skipped = 0; long toSkip = markPoint; while (toSkip > 0) { skipped = skip(toSkip); toSkip -= skipped; } if (log.isDebugEnabled()) { log.debug("Reset to mark point " + markPoint + " after returning " + bytesReadPastMarkPoint + " bytes"); } this.bytesReadPastMarkPoint = 0; } catch (IOException e) { throw new UnrecoverableIOException("Input stream is not repeatable: " + e.getMessage()); } }
/** * Returns an input stream containing this object's data, or null if there is * no data associated with the object. * <p> * If you are downloading data from a service, you should consider verifying the * integrity of the data you read from this stream using one of the * {@link #verifyData(InputStream)} methods. * * @return * input stream containing the object's service-side data, or null if no data. * * @throws ServiceException */ public InputStream getDataInputStream() throws ServiceException { if (dataInputStream == null && dataInputFile != null) { try { // Use a repeatable file data input stream, so transmissions can be retried if necessary. dataInputStream = new RepeatableFileInputStream(dataInputFile); } catch (FileNotFoundException e) { throw new ServiceException("Cannot open file input stream", e); } } return dataInputStream; }
@Override public int read() throws IOException { // Ensure we don't read beyond the segment length if (bytesReadPastMarkPoint + getRelativeMarkPoint() >= segmentLength) { return -1; } else { return super.read(); } }
private void skipToOffset() throws IOException { long skipped = 0; long toSkip = offset; while (toSkip > 0) { skipped = skip(toSkip); toSkip -= skipped; } // Mark the offset location so we will return here on reset super.mark(0); if (log.isDebugEnabled()) { log.debug("Skipped to segment offset " + offset); } }
@Override public int read(byte[] bytes, int off, int len) throws IOException { bytesReadPastMarkPoint += off; // Ensure we don't read beyond the segment length if (bytesReadPastMarkPoint + getRelativeMarkPoint() >= segmentLength) { return -1; } if (bytesReadPastMarkPoint + getRelativeMarkPoint() + len > segmentLength) { len = (int) (segmentLength - (bytesReadPastMarkPoint + getRelativeMarkPoint() + off)); } return super.read(bytes, off, len); }
@Override public int read(byte[] bytes, int off, int len) throws IOException { bytesReadPastMarkPoint += off; // Ensure we don't read beyond the segment length if (bytesReadPastMarkPoint + getRelativeMarkPoint() >= segmentLength) { return -1; } if (bytesReadPastMarkPoint + getRelativeMarkPoint() + len > segmentLength) { len = (int) (segmentLength - (bytesReadPastMarkPoint + getRelativeMarkPoint() + off)); } return super.read(bytes, off, len); }