Class FileBuffer.Range
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- org.simpleframework.common.buffer.FileBuffer.Range
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
- Enclosing class:
- FileBuffer
private class FileBuffer.Range extends java.io.FilterInputStream
TheRange
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.
-
-
Constructor Summary
Constructors Constructor Description Range(java.io.InputStream source, long length)
Constructor for theRange
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
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.
-
-
-
Constructor Detail
-
Range
public Range(java.io.InputStream source, long length)
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 Detail
-
read
public int read() throws java.io.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 classjava.io.FilterInputStream
- Returns:
- this returns the octet from the underlying stream
- Throws:
java.io.IOException
-
read
public int read(byte[] array, int off, int size) throws java.io.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 classjava.io.FilterInputStream
- 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:
java.io.IOException
-
available
public int available() throws java.io.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 classjava.io.FilterInputStream
- Returns:
- this returns the number of bytes within the range
- Throws:
java.io.IOException
-
skip
public long skip(long size) throws java.io.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 classjava.io.FilterInputStream
- Parameters:
size
- this returns the number of bytes to skip- Returns:
- this returns the number of bytes that were skipped
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
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 interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
-