com.imagero.uio
Class RandomAccessByteArray

java.lang.Object
  extended bycom.imagero.uio.AbstractRandomAccessRO
      extended bycom.imagero.uio.AbstractRandomAccess
          extended bycom.imagero.uio.RandomAccessByteArray
All Implemented Interfaces:
java.io.DataInput, java.io.DataOutput, Input, RandomAccess, RandomAccessRO

public class RandomAccessByteArray
extends AbstractRandomAccess

Makes possible to access byte array as RandomAccess


Field Summary
 
Fields inherited from interface com.imagero.uio.RandomAccessRO
BIG_ENDIAN, LITTLE_ENDIAN
 
Constructor Summary
RandomAccessByteArray(byte[] data, int byteOrder)
          create new RandomAccessByteArray
RandomAccessByteArray(byte[] data, int off, int length, int byteOrder)
          create new RandomAccessByteArray
 
Method Summary
protected  int _read()
           
 void close()
          does nothing
 long getFilePointer()
          Since this is an interface and is not restricted to files, "getFilePointer" is wrong name for this method.
 int getOffset()
           
 long length()
          Returns the length of this byte array.
 int read()
          Reads a byte of data from this byte array.
 int read(byte[] b)
           
 int read(byte[] b, int off, int length)
           
 void seek(long pos)
          Sets the array-pointer offset, measured from the beginning of this byte array, at which the next read or write occurs.
 void setLength(long newLength)
          Sets the length of byte array.
 void setOffset(int offset)
           
 int skip(int n)
           
 void write(byte[] b)
          Writes max b.length bytes from the specified byte array to this array, starting at the current array pointer.
 void write(byte[] b, int off, int length)
          Writes len bytes from the specified byte array starting at offset off to this byte array.
 void write(int b)
          Writes the specified byte to this array.
 
Methods inherited from class com.imagero.uio.AbstractRandomAccess
_setByteOrder, setByteOrder, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
 
Methods inherited from class com.imagero.uio.AbstractRandomAccessRO
getByteOrder, readBoolean, readByte, readByteLine, readByteOrder, readChar, readDouble, readFloat, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, skipBytes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.imagero.uio.RandomAccessRO
getByteOrder, readByteLine, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully
 
Methods inherited from interface java.io.DataInput
readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, skipBytes
 

Constructor Detail

RandomAccessByteArray

public RandomAccessByteArray(byte[] data,
                             int byteOrder)
                      throws java.io.IOException
create new RandomAccessByteArray

Parameters:
data - byte array
Throws:
java.io.IOException

RandomAccessByteArray

public RandomAccessByteArray(byte[] data,
                             int off,
                             int length,
                             int byteOrder)
                      throws java.io.IOException
create new RandomAccessByteArray

Parameters:
data - byte array
off - index of the first byte
length - number of bytes
Throws:
java.io.IOException
Method Detail

read

public int read()
Reads a byte of data from this byte array. The byte is returned as an integer in the range 0 to 255 (0x00-0x0ff).

Returns:
the next byte of data, or -1 if the end of the file has been reached.

_read

protected int _read()
             throws java.io.EOFException
Specified by:
_read in class AbstractRandomAccessRO
Throws:
java.io.EOFException

setLength

public void setLength(long newLength)
               throws java.io.IOException
Sets the length of byte array. no array copying is performed.

Parameters:
newLength - The desired length of the file
Throws:
java.io.IOException - if length is more then length of array minus offset

read

public int read(byte[] b)
         throws java.io.IOException
Throws:
java.io.IOException

read

public int read(byte[] b,
                int off,
                int length)
         throws java.io.IOException
Throws:
java.io.IOException

write

public void write(byte[] b)
           throws java.io.IOException
Writes max b.length bytes from the specified byte array to this array, starting at the current array pointer. This method doesn't write beyond array bounds, but off and length are not checked.

Parameters:
b - the data.
Throws:
java.io.IOException

write

public void write(byte[] b,
                  int off,
                  int length)
Writes len bytes from the specified byte array starting at offset off to this byte array.
This method doesn't write beyond array bounds, but off and length are not checked and no exception is thrown.

Parameters:
b - the data.
off - the start offset in the data.
length - the number of bytes to write

write

public void write(int b)
           throws java.io.IOException
Writes the specified byte to this array. The write starts at the current array pointer.

Parameters:
b - the byte to be written.
Throws:
java.io.IOException

close

public void close()
does nothing


getOffset

public int getOffset()

setOffset

public void setOffset(int offset)

skip

public int skip(int n)
         throws java.io.IOException
Throws:
java.io.IOException

getFilePointer

public long getFilePointer()
                    throws java.io.IOException
Description copied from interface: RandomAccessRO
Since this is an interface and is not restricted to files, "getFilePointer" is wrong name for this method. But I leaved it so for easier porting from RandomAccessFile

Returns:
current cursor position
Throws:
java.io.IOException

seek

public void seek(long pos)
Sets the array-pointer offset, measured from the beginning of this byte array, at which the next read or write occurs. The offset may NOT be set beyond the end of the byte array.

Parameters:
pos - the offset position, measured in bytes from the beginning of the byte array, at which to set the array pointer.

length

public long length()
Returns the length of this byte array.

Returns:
the length of this byte array, measured in bytes.