java.lang.Object
org.sejda.io.BaseSeekableSource
org.sejda.io.MemoryMappedSeekableSource
- All Implemented Interfaces:
Closeable,AutoCloseable,Channel,ReadableByteChannel,SeekableSource
A
SeekableSource implementation based on MappedByteBuffer. To overcome the int limit of the MappedByteBuffer, this source implement a pagination algorithm allowing to
open files of any size. The size of the pages can be configured using the SeekableSources.MEMORY_MAPPED_PAGE_SIZE_PROPERTY system property.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ThreadBoundCopiesSupplier<MemoryMappedSeekableSource>private static final org.slf4j.Loggerprivate static final longprivate final List<ByteBuffer>private final longprivate longprivate final longprivate Consumer<? super ByteBuffer> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()longposition()position(long position) Sets the source position.intread()Reads a byte of data from this source.intread(ByteBuffer dst) private intreadPage(ByteBuffer dst, int pageNumber, int bufferPosition) longsize()view(long startingPosition, long length) Methods inherited from class org.sejda.io.BaseSeekableSource
id, isOpen, requireOpenMethods 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
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
MB_256
private static final long MB_256- See Also:
-
pageSize
private final long pageSize -
pages
-
position
private long position -
size
private final long size -
localCopiesSupplier
-
unmapper
-
-
Constructor Details
-
MemoryMappedSeekableSource
- Throws:
IOException
-
MemoryMappedSeekableSource
- Throws:
IOException
-
MemoryMappedSeekableSource
-
-
Method Details
-
position
public long position()- Returns:
- the current source position as a positive long
-
size
public long size()- Returns:
- The source size, measured in bytes
-
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.- Parameters:
position- a non-negative long for the new position- Returns:
- this source
-
read
- Throws:
IOException
-
readPage
-
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).- Returns:
- the next byte of data, or
-1if there is no more data. - Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Overrides:
closein classBaseSeekableSource- Throws:
IOException
-
view
- 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
-