Package omero.util

Class ReadOnlyByteArray


  • public class ReadOnlyByteArray
    extends java.lang.Object
    A read-only slice of a given array. Given a base array and an interval [offset, offset+length] contained within [0, base.length], an instance of this class provides read access to the elements from base[offset] to base[offset+length-1]. However, you access the elements by specifying relative indeces to the get method — so get(0) returns base[offset], get(1) returns base[offset+1], and so on. One thing to bear in mind is that changes to the original base array will be reflected to the corresponding ReadOnlyByteArray object as this class simply keeps a reference to the original base array, without making an internal copy. This can be useful in those situations when you want to emulate a memory pointer.
    Since:
    OME2.2
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected byte[] base
      The original array.
      int length
      The length of the slice.
      protected int offset
      Marks the start of the slice.
    • Constructor Summary

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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void checkIndex​(int i)
      Makes sure that i is in [0, length).
      byte get​(int index)
      Reads the element at the index position within this slice.
      • Methods inherited from class java.lang.Object

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

      • base

        protected final byte[] base
        The original array.
      • offset

        protected final int offset
        Marks the start of the slice.
      • length

        public final int length
        The length of the slice.
    • Constructor Detail

      • ReadOnlyByteArray

        public ReadOnlyByteArray​(byte[] base,
                                 int offset,
                                 int length)
        Creates a read-only 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

      • checkIndex

        protected void checkIndex​(int i)
        Makes sure that i is in [0, length). Throws an exception if this constraint is not met.
        Parameters:
        i - The index to verify.
      • get

        public byte get​(int index)
        Reads the element at the index position within this slice.
        Parameters:
        index - The index. Must be in the [0, length) interval.
        Returns:
        The element at the index position in this slice.