Class ByteWriter

java.lang.Object
org.apache.sis.internal.storage.io.ByteWriter

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
Author:
Martin Desruisseaux (Geomatys)
  • 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.