Package com.itextpdf.text.io
Class MappedChannelRandomAccessSource
java.lang.Object
com.itextpdf.text.io.MappedChannelRandomAccessSource
- All Implemented Interfaces:
RandomAccessSource
A RandomAccessSource that represents a memory mapped section of an underlying FileChannel.
This source can be closed and will automatically re-open as needed.
This class is an internal implementation detail of the
FileChannelRandomAccessSource class and
shouldn't be used by general iText users.- Since:
- 5.3.5
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final FileChannelThe underlying channelprivate final longThe number of bytes this source maps toprivate final longThe offset into the channel that this source maps toprivate ByteBufferRandomAccessSourceIf the map is active, the actual map. -
Constructor Summary
ConstructorsConstructorDescriptionMappedChannelRandomAccessSource(FileChannel channel, long offset, long length) Create a new source based on the channel. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this source.private static booleanUtility method that determines whether a given IOException is the result of a failure to map a memory mapped file.intget(long position) Gets a byte at the specified positionintget(long position, byte[] bytes, int off, int len) Gets an array at the specified position.longlength()(package private) voidopen()Map the region of the channeltoString()
-
Field Details
-
channel
The underlying channel -
offset
private final long offsetThe offset into the channel that this source maps to -
length
private final long lengthThe number of bytes this source maps to -
source
If the map is active, the actual map. null other wise.
-
-
Constructor Details
-
MappedChannelRandomAccessSource
Create a new source based on the channel. Mapping will not occur until data is actually read.- Parameters:
channel- the underlying channeloffset- the offset of the maplength- the length of the map
-
-
Method Details
-
open
Map the region of the channel- Throws:
IOException- if there is a problem with creating the map
-
exceptionIsMapFailureException
Utility method that determines whether a given IOException is the result of a failure to map a memory mapped file. It would be better if the runtime provided a special exception for this case, but it doesn't, so we have to rely on parsing the exception message.- Parameters:
e- the exception to check- Returns:
- true if the exception was the result of a failure to map a memory mapped file
-
get
Gets a byte at the specified position- Specified by:
getin 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:
getin 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:
lengthin interfaceRandomAccessSource- Returns:
- the length of this source
-
close
Closes this source. The underlying data structure or source (if any) will also be closed- Specified by:
closein interfaceRandomAccessSource- Throws:
IOException
-
toString
-