java.lang.Object
org.sejda.io.BufferedSeekableSource
- All Implemented Interfaces:
Closeable,AutoCloseable,Channel,ReadableByteChannel,SeekableSource
SeekableSource wrapping an existing one and providing buffered read. When a read method is called, a SeekableSources.INPUT_BUFFER_SIZE_PROPERTY long chunk of
bytes is read from the underlying source and stored in memory. Subsequent reads are served from the in memory buffer until they fall outside its range, at that point a new
buffer is read from the wrapped source.- Author:
- Andrea Vacondio
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()id()booleanisOpen()longposition()position(long newPosition) Sets the source position.intread()Reads a byte of data from this source.intread(ByteBuffer dst) voidlongsize()view(long startingPosition, long length) protected SeekableSourcewrapped()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.sejda.io.SeekableSource
asInputStream, asNewInputStream, back, back, forward, peek, peekBack, reset
-
Constructor Details
-
BufferedSeekableSource
-
-
Method Details
-
isOpen
public boolean isOpen() -
requireOpen
- Specified by:
requireOpenin interfaceSeekableSource- Throws:
IOException
-
id
- Specified by:
idin interfaceSeekableSource- Returns:
- the unique id for this source
-
position
public long position()- Specified by:
positionin interfaceSeekableSource- Returns:
- the current source position as a positive long
-
position
Description copied from interface:SeekableSourceSets the source position. Setting the position to a value that is greater than the source's size is legal but does not change the size of the source. A later attempt to read bytes at such a position will immediately return an end-of-file indication.- Specified by:
positionin interfaceSeekableSource- Parameters:
newPosition- a non-negative long for the new position- Returns:
- this source
- Throws:
IOException
-
size
public long size()- Specified by:
sizein interfaceSeekableSource- Returns:
- The source size, measured in bytes
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException
-
read
- Specified by:
readin interfaceReadableByteChannel- Throws:
IOException
-
read
Description copied from interface:SeekableSourceReads a byte of data from this source. The byte is returned as an integer in the range 0 to 255 (0x00-0xff).- Specified by:
readin interfaceSeekableSource- Returns:
- the next byte of data, or
-1if there is no more data. - Throws:
IOException
-
wrapped
-
view
- Specified by:
viewin interfaceSeekableSource- Returns:
- a readable view of a portion of this
SeekableSource. Reading from the view doesn't affect theSeekableSourceposition. Closing theSeekableSourcemakes all the views unreadable but closing the view has no effect on theSeekableSource. A view may or may not work on a thread bound copy of theSeekableSourceso as a general rule it should not be created and handed to other threads. - Throws:
IOException- if something goes wrong while creating the view
-