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
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
FieldsModifier and TypeFieldDescriptionprivate booleanThis is used to close the stream once it has been read.private longThis is the length of the bytes that exist in the range.Fields inherited from class FilterInputStream
in -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintThis returns the number of bytes that can be read from the range.voidclose()This is used to close the range once all of the content has been fully read.intread()This will read data from the underlying stream up to the number of bytes this range is allowed to read.intread(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.longskip(long size) This is the number of bytes to skip from the buffer.Methods inherited from class FilterInputStream
mark, markSupported, read, resetMethods inherited from class InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
length
private long lengthThis is the length of the bytes that exist in the range. -
closed
private boolean closedThis is used to close the stream once it has been read.
-
-
Constructor Details
-
Range
Constructor for theRangeobject. 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 datalength- this is the number of bytes that can be read
-
-
Method Details
-
read
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:
readin classFilterInputStream- Returns:
- this returns the octet from the underlying stream
- Throws:
IOException
-
read
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:
readin classFilterInputStream- Parameters:
array- this is the array to read the bytes in tooff- this is the start offset to append the bytes tosize- this is the number of bytes that are required- Returns:
- this returns the number of bytes that were read
- Throws:
IOException
-
available
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:
availablein classFilterInputStream- Returns:
- this returns the number of bytes within the range
- Throws:
IOException
-
skip
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:
skipin classFilterInputStream- Parameters:
size- this returns the number of bytes to skip- Returns:
- this returns the number of bytes that were skipped
- Throws:
IOException
-
close
This is used to close the range once all of the content has been fully read. TheRangeobject 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterInputStream- Throws:
IOException
-