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

public abstract class ByteWriter extends Object
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 Classes
    Modifier and Type
    Class
    Description
    private static final class 
    Writer for byte values.
    private static final class 
    Writer for double values.
    private static final class 
    Writer for float values.
    private static final class 
    Writer for int values.
    private static final class 
    Writer for long values.
    private static final class 
    Writer for short values.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    For subclass constructors.
  • Method Summary

    Modifier and Type
    Method
    Description
    static ByteWriter
    create(Buffer source, ByteBuffer target)
    Creates a new writer for copying bytes from the given source to the given target buffers.
    static ByteWriter
    create(Vector source, byte[] target)
    Creates a new writer for copying bytes from the given source vector to the given target array.
    private static void
    reset(Buffer source, Buffer target)
    Prepares the given source and target buffers to a new transfer.
    abstract int
    Copies bytes from the source buffer to the target buffer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ByteWriter

      private ByteWriter()
      For subclass constructors.
  • Method Details

    • create

      public static ByteWriter create(Vector source, byte[] target)
      Creates a new writer for copying bytes from the given source vector to the given target array. This is a convenience method delegating to create(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

      public static ByteWriter create(Buffer source, ByteBuffer target)
      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

      private static void reset(Buffer source, Buffer target)
      Prepares the given source and target buffers to a new transfer.