Package omero.util
Class ReadOnlyByteArray
- java.lang.Object
-
- omero.util.ReadOnlyByteArray
-
public class ReadOnlyByteArray extends java.lang.Object
A read-only slice of a given array. Given abase
array 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 theget
method soget(0)
returnsbase[offset]
,get(1)
returnsbase[offset+1]
, and so on. One thing to bear in mind is that changes to the originalbase
array will be reflected to the correspondingReadOnlyByteArray
object as this class simply keeps a reference to the originalbase
array, 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 void
checkIndex(int i)
Makes sure thati
is in[0, length)
.byte
get(int index)
Reads the element at theindex
position within this slice.
-
-
-
Constructor Detail
-
ReadOnlyByteArray
public ReadOnlyByteArray(byte[] base, int offset, int length)
Creates a read-only slice ofbase
. Theoffset
argument marks the start of the slice, atbase[offset]
. Thelength
argument 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 thati
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 theindex
position within this slice.- Parameters:
index
- The index. Must be in the[0,
interval.length
)- Returns:
- The element at the
index
position in this slice.
-
-