Package com.itextpdf.text.io
Class GroupedRandomAccessSource
java.lang.Object
com.itextpdf.text.io.GroupedRandomAccessSource
- All Implemented Interfaces:
RandomAccessSource
- Direct Known Subclasses:
PagedChannelRandomAccessSource
A RandomAccessSource that is based on a set of underlying sources, treating the sources as if they were a contiguous block of data.
- Since:
- 5.3.5
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Used to track each source, along with useful meta data -
Field Summary
FieldsModifier and TypeFieldDescriptionCached value to make multiple reads from the same underlying source more efficientprivate final long
Cached size of the underlying channelprivate final GroupedRandomAccessSource.SourceEntry[]
The underlying sources (along with some meta data to quickly determine where each source begins and ends) -
Constructor Summary
ConstructorsConstructorDescriptionGroupedRandomAccessSource
(RandomAccessSource[] sources) Constructs a newGroupedRandomAccessSource
based on the specified set of sources -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this source.int
get
(long position) Gets a byte at the specified positionint
get
(long position, byte[] bytes, int off, int len) Gets an array at the specified position.getSourceEntryForOffset
(long offset) Returns the SourceEntry that contains the byte at the specified offset sourceReleased is called as a notification callback so subclasses can take care of cleanup when the source is no longer the active sourceprotected int
getStartingSourceIndex
(long offset) For a given offset, return the index of the source that contains the specified offset.long
length()
protected void
sourceInUse
(RandomAccessSource source) Called when a given source is about to become the active source.protected void
sourceReleased
(RandomAccessSource source) Called when a given source is no longer the active source.
-
Field Details
-
sources
The underlying sources (along with some meta data to quickly determine where each source begins and ends) -
currentSourceEntry
Cached value to make multiple reads from the same underlying source more efficient -
size
private final long sizeCached size of the underlying channel
-
-
Constructor Details
-
GroupedRandomAccessSource
Constructs a newGroupedRandomAccessSource
based on the specified set of sources- Parameters:
sources
- the sources used to build this group- Throws:
IOException
-
-
Method Details
-
getStartingSourceIndex
protected int getStartingSourceIndex(long offset) For a given offset, return the index of the source that contains the specified offset. This is an optimization feature to help optimize the access of the correct source without having to iterate through every single source each time. It is safe to always return 0, in which case the full set of sources will be searched. Subclasses should override this method if they are able to compute the source index more efficiently (for exampleFileChannelRandomAccessSource
takes advantage of fixed size page buffers to compute the index)- Parameters:
offset
- the offset- Returns:
- the index of the input source that contains the specified offset, or 0 if unknown
-
getSourceEntryForOffset
private GroupedRandomAccessSource.SourceEntry getSourceEntryForOffset(long offset) throws IOException Returns the SourceEntry that contains the byte at the specified offset sourceReleased is called as a notification callback so subclasses can take care of cleanup when the source is no longer the active source- Parameters:
offset
- the offset of the byte to look for- Returns:
- the SourceEntry that contains the byte at the specified offset
- Throws:
IOException
- if there is a problem with IO (usually the result of the sourceReleased() call)
-
sourceReleased
Called when a given source is no longer the active source. This gives subclasses the abilty to release resources, if appropriate.- Parameters:
source
- the source that is no longer the active source- Throws:
IOException
- if there are any problems
-
sourceInUse
Called when a given source is about to become the active source. This gives subclasses the abilty to retrieve resources, if appropriate.- Parameters:
source
- the source that is about to become the active source- Throws:
IOException
- if there are any problems
-
get
Gets a byte at the specified position The source that contains the byte at position is retrieved, the correct offset into that source computed, then the value from that offset in the underlying source is returned.- Specified by:
get
in interfaceRandomAccessSource
- Parameters:
position
-- Returns:
- the byte, or -1 if EOF is reached
- Throws:
IOException
-
get
Gets an array at the specified position. If the number of bytes requested cannot be read, the bytes that can be read will be placed in bytes and the number actually read will be returned.- Specified by:
get
in interfaceRandomAccessSource
- Parameters:
position
- the position in the RandomAccessSource to read frombytes
- output bufferoff
- offset into the output buffer where results will be placedlen
- the number of bytes to read- Returns:
- the number of bytes actually read, or -1 if the file is at EOF
- Throws:
IOException
-
length
public long length()- Specified by:
length
in interfaceRandomAccessSource
- Returns:
- the length of this source
-
close
Closes this source. The underlying data structure or source (if any) will also be closed Closes all of the underlying sources- Specified by:
close
in interfaceRandomAccessSource
- Throws:
IOException
-