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 extendsReadOnlyByteArray
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 correspondingByteArray
object, and vice-versa, any invocation of theset
methods 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 void
set(int index, byte value)
Writesvalue
into the element at theindex
position within this slice.void
set(int index, byte[] buf)
Copies the values inbuf
into this slice, starting fromindex
.int
set(int index, int maxLength, java.io.InputStream in)
Writes up tomaxLength
bytes 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
. 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
-
set
public void set(int index, byte value)
Writesvalue
into the element at theindex
position 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 inbuf
into this slice, starting fromindex
. This method first checks to see whetherbuf.length
bytes can be written into this slice starting fromindex
. If the check fails anArrayIndexOutOfBoundsException
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,
interval.ReadOnlyByteArray.length
)buf
- A buffer containing the values to write. Mustn't benull
and must fit into this slice. If the length is0
, then this method does nothing.- Throws:
java.lang.NullPointerException
- If anull
buffer is specified.
-
set
public int set(int index, int maxLength, java.io.InputStream in) throws java.io.IOException
Writes up tomaxLength
bytes from the supplied stream into this slice, starting fromindex
. To be precise, this method will attempt to writem
bytes into this slice (starting from the element atindex
),m
being the minimum of the following numbers:maxLength
,this.
(that is, bytes fromlength
- indexindex
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,
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
-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 specifiedinput stream
isnull
.
-
-