Package ome.util.mem
Class ByteArray
- java.lang.Object
-
- ome.util.mem.ReadOnlyByteArray
-
- ome.util.mem.ByteArray
-
public class ByteArray extends ReadOnlyByteArray
A read-write slice of a given array. This class extendsReadOnlyByteArrayto 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 correspondingByteArrayobject, and vice-versa, any invocation of thesetmethods will be reflected into the original array.- Since:
- OME2.2
-
-
Field Summary
-
Fields inherited from class ome.util.mem.ReadOnlyByteArray
base, length, offset
-
-
Constructor Summary
Constructors Constructor Description ByteArray(byte[] base, int offset, int length)Creates a read-write slice ofbase.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidset(int index, byte value)Writesvalueinto the element at theindexposition within this slice.voidset(int index, byte[] buf)Copies the values inbufinto this slice, starting fromindex.intset(int index, int maxLength, java.io.InputStream in)Writes up tomaxLengthbytes from the supplied stream into this slice, starting fromindex.-
Methods inherited from class ome.util.mem.ReadOnlyByteArray
checkIndex, get
-
-
-
-
Constructor Detail
-
ByteArray
public ByteArray(byte[] base, int offset, int length)Creates a read-write 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
-
set
public void set(int index, byte value)Writesvalueinto the element at theindexposition within this slice.- Parameters:
index- The index, within this slice, at which to write. Must be in the[0,interval.ReadOnlyByteArray.length)value- The value to write.
-
set
public void set(int index, byte[] buf)Copies the values inbufinto this slice, starting fromindex. This method first checks to see whetherbuf.lengthbytes can be written into this slice starting fromindex. If the check fails anArrayIndexOutOfBoundsExceptionis 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,interval.ReadOnlyByteArray.length)buf- A buffer containing the values to write. Mustn't benulland must fit into this slice. If the length is0, then this method does nothing.- Throws:
java.lang.NullPointerException- If anullbuffer is specified.
-
set
public int set(int index, int maxLength, java.io.InputStream in) throws java.io.IOExceptionWrites up tomaxLengthbytes from the supplied stream into this slice, starting fromindex. To be precise, this method will attempt to writembytes into this slice (starting from the element atindex),mbeing the minimum of the following numbers:maxLength,this.(that is, bytes fromlength- indexindexto 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,interval.ReadOnlyByteArray.length)maxLength- The maximum amount of bytes to write. If not positive, this method does nothing and returns0.in- The stream from which to read data. Mustn't benull.- Returns:
- The amount of bytes actually written or
-1if 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 specifiedinput streamisnull.
-
-