Package ome.util.mem

Class ByteArray


  • public class ByteArray
    extends ReadOnlyByteArray
    A read-write slice of a given array. This class extends ReadOnlyByteArray to allow for elements to be written to the array slice. This class works just like its parent; so you get relative indexing and any changes to the original array will be visible in the corresponding ByteArray object, and vice-versa, any invocation of the set methods will be reflected into the original array.
    Since:
    OME2.2
    • Constructor Summary

      Constructors 
      Constructor Description
      ByteArray​(byte[] base, int offset, int length)
      Creates a read-write slice of base.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void set​(int index, byte value)
      Writes value into the element at the index position within this slice.
      void set​(int index, byte[] buf)
      Copies the values in buf into this slice, starting from index.
      int set​(int index, int maxLength, java.io.InputStream in)
      Writes up to maxLength bytes from the supplied stream into this slice, starting from index.
      • Methods inherited from class java.lang.Object

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

      • ByteArray

        public ByteArray​(byte[] base,
                         int offset,
                         int length)
        Creates a read-write slice of base. The offset argument marks the start of the slice, at base[offset]. The length argument defines the length of the slice, the last element being base[offset+length-1]. Obviously enough, these two arguments must define an interval [offset, offset+length] in [0, base.length].
        Parameters:
        base - The original array.
        offset - The start of the slice.
        length - The length of the slice.
    • Method Detail

      • set

        public void set​(int index,
                        byte value)
        Writes value into the element at the index position within this slice.
        Parameters:
        index - The index, within this slice, at which to write. Must be in the [0, ReadOnlyByteArray.length) interval.
        value - The value to write.
      • set

        public void set​(int index,
                        byte[] buf)
        Copies the values in buf into this slice, starting from index. This method first checks to see whether buf.length bytes can be written into this slice starting from index. If the check fails an ArrayIndexOutOfBoundsException is thrown and no data is copied at all.
        Parameters:
        index - The index, within this slice, from which to start writing. Must be in the [0, ReadOnlyByteArray.length) interval.
        buf - A buffer containing the values to write. Mustn't be null and must fit into this slice. If the length is 0, then this method does nothing.
        Throws:
        java.lang.NullPointerException - If a null buffer is specified.
      • set

        public int set​(int index,
                       int maxLength,
                       java.io.InputStream in)
                throws java.io.IOException
        Writes up to maxLength bytes from the supplied stream into this slice, starting from index. To be precise, this method will attempt to write m bytes into this slice (starting from the element at index), m being the minimum of the following numbers: maxLength, this.length - index (that is, bytes from index to the end of the slice), and the number of bytes to the end of the supplied stream.
        Parameters:
        index - The index, within this slice, from which to start writing. Must be in the [0, ReadOnlyByteArray.length) interval.
        maxLength - The maximum amount of bytes to write. If not positive, this method does nothing and returns 0.
        in - The stream from which to read data. Mustn't be null.
        Returns:
        The amount of bytes actually written or -1 if the end of the stream has been reached.
        Throws:
        java.io.IOException - If an I/O error occurred while reading data from the stream.
        java.lang.NullPointerException - If the specified input stream is null.