Class FileBuffer.Range

java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.simpleframework.common.buffer.FileBuffer.Range
All Implemented Interfaces:
Closeable, AutoCloseable
Enclosing class:
FileBuffer

private class FileBuffer.Range extends FilterInputStream
The Range object is used to provide a stream that can read a range of bytes from a provided input stream. This allows buffer segments to be allocated from the main buffer. Providing a range in this manner ensures that only one backing file is needed for the primary buffer allocated.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private boolean
    This is used to close the stream once it has been read.
    private long
    This is the length of the bytes that exist in the range.

    Fields inherited from class java.io.FilterInputStream

    in
  • Constructor Summary

    Constructors
    Constructor
    Description
    Range(InputStream source, long length)
    Constructor for the Range object.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    This returns the number of bytes that can be read from the range.
    void
    This is used to close the range once all of the content has been fully read.
    int
    This will read data from the underlying stream up to the number of bytes this range is allowed to read.
    int
    read(byte[] array, int off, int size)
    This will read data from the underlying stream up to the number of bytes this range is allowed to read.
    long
    skip(long size)
    This is the number of bytes to skip from the buffer.

    Methods inherited from class java.io.FilterInputStream

    mark, markSupported, read, reset

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • length

      private long length
      This is the length of the bytes that exist in the range.
    • closed

      private boolean closed
      This is used to close the stream once it has been read.
  • Constructor Details

    • Range

      public Range(InputStream source, long length)
      Constructor for the Range object. This ensures that only a limited number of bytes can be consumed from a backing input stream giving the impression of an independent stream of bytes for a segmented region of the parent buffer.
      Parameters:
      source - this is the input stream used to read data
      length - this is the number of bytes that can be read
  • Method Details

    • read

      public int read() throws IOException
      This will read data from the underlying stream up to the number of bytes this range is allowed to read. When all of the bytes are exhausted within the stream this returns -1.
      Overrides:
      read in class FilterInputStream
      Returns:
      this returns the octet from the underlying stream
      Throws:
      IOException
    • read

      public int read(byte[] array, int off, int size) throws IOException
      This will read data from the underlying stream up to the number of bytes this range is allowed to read. When all of the bytes are exhausted within the stream this returns -1.
      Overrides:
      read in class FilterInputStream
      Parameters:
      array - this is the array to read the bytes in to
      off - this is the start offset to append the bytes to
      size - this is the number of bytes that are required
      Returns:
      this returns the number of bytes that were read
      Throws:
      IOException
    • available

      public int available() throws IOException
      This returns the number of bytes that can be read from the range. This will be the actual number of bytes the range contains as the underlying file will not block reading.
      Overrides:
      available in class FilterInputStream
      Returns:
      this returns the number of bytes within the range
      Throws:
      IOException
    • skip

      public long skip(long size) throws IOException
      This is the number of bytes to skip from the buffer. This will allow up to the number of remaining bytes within the range to be read. When all the bytes have been read this will return zero indicating no bytes were skipped.
      Overrides:
      skip in class FilterInputStream
      Parameters:
      size - this returns the number of bytes to skip
      Returns:
      this returns the number of bytes that were skipped
      Throws:
      IOException
    • close

      public void close() throws IOException
      This is used to close the range once all of the content has been fully read. The Range object forces the close of the stream once all the content has been consumed to ensure that excessive file descriptors are used. Also this will ensure that the files can be deleted.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class FilterInputStream
      Throws:
      IOException