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.ArrayReader
The actualDataTransfer
implementation. -
Constructor Summary
ConstructorsConstructorDescriptionMemoryDataTransfer
(String filename, Buffer data) Creates a in-memory data input for the given buffer. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Does nothing - keep the channel open.void
createDataArray
(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.int
Returns the size of the Java primitive type which is the element of the array.filename()
Delegates to the actual implementation.boolean
isOpen()
The channel is always open.int
read
(ByteBuffer dst) Returns -1 since an empty channel has reached the end-of-stream.(package private) DataTransfer
reader()
Returns the most efficientDataTransfer
instance to use.void
Readslength
values from the buffer and stores them into the array known to subclass, starting at indexoffset
.void
seek
(long position) Moves to the given byte position in the buffer.void
Sets the destination to the given data array, which may benull
.view()
Returns the view created by the last call toDataTransfer.createView()
, ornull
if none.
-
Field Details
-
reader
The actualDataTransfer
implementation.
-
-
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 efficientDataTransfer
instance to use. -
seek
Moves to the given byte position in the buffer.- Specified by:
seek
in 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:
filename
in interfaceDataTransfer
-
dataSizeShift
public int dataSizeShift()Description copied from interface:DataTransfer
Returns 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:
dataSizeShift
in interfaceDataTransfer
-
dataArray
Description copied from interface:DataTransfer
Returns 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:
dataArray
in interfaceDataTransfer
-
dataArrayAsBuffer
Description copied from interface:DataTransfer
ReturnsDataTransfer.dataArray()
wrapped in a buffer.- Specified by:
dataArrayAsBuffer
in interfaceDataTransfer
-
view
Description copied from interface:DataTransfer
Returns the view created by the last call toDataTransfer.createView()
, ornull
if none.- Specified by:
view
in interfaceDataTransfer
-
createView
Description copied from interface:DataTransfer
Creates a new buffer of the type required by the array to fill. This method is guaranteed to be invoked exactly once, after theChannelData.buffer
contains enough data.- Specified by:
createView
in interfaceDataTransfer
-
createDataArray
public void createDataArray(int length) Description copied from interface:DataTransfer
Creates a destination array of the given length.- Specified by:
createDataArray
in interfaceDataTransfer
-
setDest
Description copied from interface:DataTransfer
Sets the destination to the given data array, which may benull
.- Specified by:
setDest
in interfaceDataTransfer
-
readFully
Readslength
values from the buffer and stores them into the array known to subclass, starting at indexoffset
.- Specified by:
readFully
in interfaceDataTransfer
- Parameters:
view
- ignored.offset
- the starting position withindest
to write.length
- the number of values to read.
-
read
Returns -1 since an empty channel has reached the end-of-stream.- Specified by:
read
in interfaceReadableByteChannel
-
isOpen
public boolean isOpen()The channel is always open. -
close
Does nothing - keep the channel open.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-