Class MemoryDataTransfer
java.lang.Object
org.apache.sis.internal.storage.io.MemoryDataTransfer
- All Implemented Interfaces:
Closeable,AutoCloseable,Channel,ReadableByteChannel,DataTransfer
A
DataTransfer with all data in the given buffer, without channel.
Implementation note:
This class implements also an empty
ReadableByteChannel as safety. When using ChannelDataInput
without channel, only an existing Buffer pre-filled with the data should be used. If we have a bug in
our reading process, the empty channel will cause an EOFException to be thrown instead of a
NullPointerException.- Since:
- 0.7
- Version:
- 1.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ChannelDataInput.ArrayReaderThe actualDataTransferimplementation. -
Constructor Summary
ConstructorsConstructorDescriptionMemoryDataTransfer(String filename, Buffer data) Creates a in-memory data input for the given buffer. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Does nothing - keep the channel open.voidcreateDataArray(int length) Creates a destination array of the given length.Creates a new buffer of the type required by the array to fill.Returns the data as achar[],short[],int[],long[],float[]ordouble[]array.ReturnsDataTransfer.dataArray()wrapped in a buffer.intReturns the size of the Java primitive type which is the element of the array.filename()Delegates to the actual implementation.booleanisOpen()The channel is always open.intread(ByteBuffer dst) Returns -1 since an empty channel has reached the end-of-stream.(package private) DataTransferreader()Returns the most efficientDataTransferinstance to use.voidReadslengthvalues from the buffer and stores them into the array known to subclass, starting at indexoffset.voidseek(long position) Moves to the given byte position in the buffer.voidSets the destination to the given data array, which may benull.view()Returns the view created by the last call toDataTransfer.createView(), ornullif none.
-
Field Details
-
reader
The actualDataTransferimplementation.
-
-
Constructor Details
-
MemoryDataTransfer
MemoryDataTransfer(String filename, Buffer data) throws IOException Creates a in-memory data input for the given buffer.- Throws:
IOException
-
-
Method Details
-
reader
DataTransfer reader()Returns the most efficientDataTransferinstance to use. -
seek
Moves to the given byte position in the buffer.- Specified by:
seekin interfaceDataTransfer- Parameters:
position- the position where to move.- Throws:
IOException- if the stream cannot be moved to the given position.
-
filename
Delegates to the actual implementation.- Specified by:
filenamein interfaceDataTransfer
-
dataSizeShift
public int dataSizeShift()Description copied from interface:DataTransferReturns the size of the Java primitive type which is the element of the array. The size is expressed as the number of bits to shift:java dataSize = 1 << dataSizeShift;- Specified by:
dataSizeShiftin interfaceDataTransfer
-
dataArray
Description copied from interface:DataTransferReturns the data as achar[],short[],int[],long[],float[]ordouble[]array. This is either the array given in argument to the subclass constructor, or the array created byDataTransfer.createDataArray(int).- Specified by:
dataArrayin interfaceDataTransfer
-
dataArrayAsBuffer
Description copied from interface:DataTransferReturnsDataTransfer.dataArray()wrapped in a buffer.- Specified by:
dataArrayAsBufferin interfaceDataTransfer
-
view
Description copied from interface:DataTransferReturns the view created by the last call toDataTransfer.createView(), ornullif none.- Specified by:
viewin interfaceDataTransfer
-
createView
Description copied from interface:DataTransferCreates a new buffer of the type required by the array to fill. This method is guaranteed to be invoked exactly once, after theChannelData.buffercontains enough data.- Specified by:
createViewin interfaceDataTransfer
-
createDataArray
public void createDataArray(int length) Description copied from interface:DataTransferCreates a destination array of the given length.- Specified by:
createDataArrayin interfaceDataTransfer
-
setDest
Description copied from interface:DataTransferSets the destination to the given data array, which may benull.- Specified by:
setDestin interfaceDataTransfer
-
readFully
Readslengthvalues from the buffer and stores them into the array known to subclass, starting at indexoffset.- Specified by:
readFullyin interfaceDataTransfer- Parameters:
view- ignored.offset- the starting position withindestto write.length- the number of values to read.
-
read
Returns -1 since an empty channel has reached the end-of-stream.- Specified by:
readin interfaceReadableByteChannel
-
isOpen
public boolean isOpen()The channel is always open. -
close
Does nothing - keep the channel open.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException
-