Class ByteWriter
java.lang.Object
org.apache.sis.internal.storage.io.ByteWriter
- Direct Known Subclasses:
ByteWriter.Bytes,ByteWriter.Doubles,ByteWriter.Floats,ByteWriter.Integers,ByteWriter.Longs,ByteWriter.Shorts
Copies bytes from a source
Buffer of arbitrary kind to a target ByteBuffer.
This class can be used when the source Buffer subclass is unknown at compile-time.
If the source buffer has a greater capacity than the target buffer, then write()
can be invoked in a loop until all data have been transferred.- Since:
- 1.0
- Version:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classWriter forbytevalues.private static final classWriter fordoublevalues.private static final classWriter forfloatvalues.private static final classWriter forintvalues.private static final classWriter forlongvalues.private static final classWriter forshortvalues. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ByteWritercreate(Buffer source, ByteBuffer target) Creates a new writer for copying bytes from the given source to the given target buffers.static ByteWriterCreates a new writer for copying bytes from the given source vector to the given target array.private static voidPrepares the given source and target buffers to a new transfer.abstract intwrite()Copies bytes from the source buffer to the target buffer.
-
Constructor Details
-
ByteWriter
private ByteWriter()For subclass constructors.
-
-
Method Details
-
create
Creates a new writer for copying bytes from the given source vector to the given target array. This is a convenience method delegating tocreate(Buffer, ByteBuffer).- Parameters:
source- the vector from which to copy data.target- the array where to copy data.- Returns:
- a writer from given source to target.
-
create
Creates a new writer for copying bytes from the given source to the given target buffers. Data will be read from the current position of source buffer up to that buffer limit. Data will be written starting at position 0 of target buffer up to that buffer capacity. The position and limit of target buffer are ignored. The position and limit of both buffers may be modified by this method.- Parameters:
source- the buffer from which to copy data.target- the buffer where to copy data.- Returns:
- a writer from given source to target.
-
write
public abstract int write()Copies bytes from the source buffer to the target buffer. The target buffer position is not overwritten; it is caller responsibility to update it (if desired) from the value returned by this method.- Returns:
- the number of bytes copied, or 0 if done.
-
reset
Prepares the given source and target buffers to a new transfer.
-