Package omero.util
Class ReadOnlyByteArray
- java.lang.Object
-
- omero.util.ReadOnlyByteArray
-
public class ReadOnlyByteArray extends java.lang.ObjectA read-only slice of a given array. Given abasearray and an interval[offset, offset+length]contained within[0, base.length], an instance of this class provides read access to the elements frombase[offset]tobase[offset+length-1]. However, you access the elements by specifying relative indeces to thegetmethod soget(0)returnsbase[offset],get(1)returnsbase[offset+1], and so on. One thing to bear in mind is that changes to the originalbasearray will be reflected to the correspondingReadOnlyByteArrayobject as this class simply keeps a reference to the originalbasearray, without making an internal copy. This can be useful in those situations when you want to emulate a memory pointer.- Since:
- OME2.2
-
-
Constructor Summary
Constructors Constructor Description ReadOnlyByteArray(byte[] base, int offset, int length)Creates a read-only slice ofbase.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckIndex(int i)Makes sure thatiis in[0, length).byteget(int index)Reads the element at theindexposition within this slice.
-
-
-
Constructor Detail
-
ReadOnlyByteArray
public ReadOnlyByteArray(byte[] base, int offset, int length)Creates a read-only slice ofbase. Theoffsetargument marks the start of the slice, atbase[offset]. Thelengthargument defines the length of the slice, the last element beingbase[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 thatiis 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 theindexposition within this slice.- Parameters:
index- The index. Must be in the[0,interval.length)- Returns:
- The element at the
indexposition in this slice.
-
-