com.imagero.uio
Class RandomAccessBuffer

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

public class RandomAccessBuffer
extends AbstractRandomAccess

Makes possible to represent (multiple) Buffers as RandomAccess


Field Summary
 
Fields inherited from interface com.imagero.uio.RandomAccessRO
BIG_ENDIAN, LITTLE_ENDIAN
 
Constructor Summary
RandomAccessBuffer(Buffer[] ds, int byteOrder)
          create new RABuffer
RandomAccessBuffer(MutableBufferManager bufferManager, int byteOrder)
          create new RABuffer
 
Method Summary
protected  int _read()
           
protected  void _setByteOrder(int byteOrder)
          not all images are tiffs, so we don't throw exception if called from constructor
 void close()
          sets dirty flag in bufferManager and closes it
 void flush()
           
 long getFilePointer()
          Since this is an interface and is not restricted to files, "getFilePointer" is wrong name for this method.
 long length()
          Returns the data length (please note, that real length is not always known)
protected  boolean nextArray()
           
 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 pointer offset, measured in bytes from the begin of the data, at which the next read or write occurs.
 void setByteOrder(int byteOrder)
          set byte order
 void setLength(long newLength)
          just ignored, no exception is thrown
 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 RandomAccess.
 void write(int b)
          Writes the specified byte to this array.
 
Methods inherited from class com.imagero.uio.AbstractRandomAccess
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

RandomAccessBuffer

public RandomAccessBuffer(Buffer[] ds,
                          int byteOrder)
                   throws java.io.IOException
create new RABuffer

Throws:
java.io.IOException

RandomAccessBuffer

public RandomAccessBuffer(MutableBufferManager bufferManager,
                          int byteOrder)
                   throws java.io.IOException
create new RABuffer

Parameters:
bufferManager -
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.

nextArray

protected boolean nextArray()

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)
          throws java.io.IOException
Sets the pointer offset, measured in bytes from the begin of the data, at which the next read or write occurs.

Parameters:
pos - the offset position, measured in bytes from the begin of the data, at which to set the pointer.
Throws:
java.io.IOException

length

public long length()
Returns the data length (please note, that real length is not always known)

Returns:
the data length, measured in bytes.

setLength

public void setLength(long newLength)
               throws java.io.IOException
just ignored, no exception is thrown

Parameters:
newLength - new length of data
Throws:
java.io.IOException

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)
           throws java.io.IOException
Writes len bytes from the specified byte array starting at offset off to this RandomAccess.

This method doesn't write beyond array bounds, but off and length are not checked.

Parameters:
b - the data.
off - the start offset in the data.
length - the number of bytes to write
Throws:
java.io.IOException - if end of last array reached

flush

public void flush()
           throws java.io.IOException
Throws:
java.io.IOException

setByteOrder

public void setByteOrder(int byteOrder)
                  throws java.io.IOException
Description copied from interface: RandomAccessRO
set byte order

Specified by:
setByteOrder in interface RandomAccessRO
Overrides:
setByteOrder in class AbstractRandomAccess
Throws:
java.io.IOException

_setByteOrder

protected void _setByteOrder(int byteOrder)
                      throws java.io.IOException
Description copied from class: AbstractRandomAccess
not all images are tiffs, so we don't throw exception if called from constructor

Overrides:
_setByteOrder in class AbstractRandomAccess
Parameters:
byteOrder -
Throws:
java.io.IOException

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 - if end of last array reached

close

public void close()
sets dirty flag in bufferManager and closes it


skip

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

_read

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