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 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 -
Method Summary
Modifier and TypeMethodDescriptionint
This returns the number of bytes that can be read from the range.void
close()
This is used to close the range once all of the content has been fully read.int
read()
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.io.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 theRange
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 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:
read
in 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:
read
in 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:
available
in 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:
skip
in 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. TheRange
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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFilterInputStream
- Throws:
IOException
-