com.imagero.uio.buffer
Class InputStreamBufferManager

java.lang.Object
  extended bycom.imagero.uio.buffer.AbstractBufferManager
      extended bycom.imagero.uio.buffer.InputStreamBufferManager
All Implemented Interfaces:
BufferManager

public class InputStreamBufferManager
extends AbstractBufferManager


Field Summary
 
Fields inherited from class com.imagero.uio.buffer.AbstractBufferManager
defaultBufferSize
 
Fields inherited from interface com.imagero.uio.buffer.BufferManager
empty
 
Constructor Summary
InputStreamBufferManager(java.io.InputStream in)
          create BufferManager for given InputStream (with standard length of 50k)
InputStreamBufferManager(int bufferSize, java.io.InputStream in)
          create BufferManager for given InputStream
 
Method Summary
 void close()
          closes underlined InputStream and drops all Buffers
protected  void fillBuffer(int tillIndex)
          read all Buffers from current index till tillIndex from InputStream
 byte[] getData(int i)
          get data (as byte array) from i'th Buffer
protected  byte[] getDataImpl(int i)
          read all data sequential
 int getDataLength(int i)
          get length of i'th Buffer
 long getDataStart(int i)
          get start of i'th Buffer in byte
I assume here that length of each Buffer (except last one) equals to dsLength
 int getIndex(long pos)
          get index of Buffer which contains pos
 long getLength()
          get length of data of all already read Buffer together (may change)
 
Methods inherited from class com.imagero.uio.buffer.AbstractBufferManager
clear, clear, clearImpl, createAccessManager, flush, getCount, getDefaultBufferSize, getEnd, getMaxCache, getStart, setDefaultBufferSize, setDirty, setDirty, setMaxCache
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InputStreamBufferManager

public InputStreamBufferManager(java.io.InputStream in)
create BufferManager for given InputStream (with standard length of 50k)

Parameters:
in - InputStream

InputStreamBufferManager

public InputStreamBufferManager(int bufferSize,
                                java.io.InputStream in)
create BufferManager for given InputStream

Parameters:
bufferSize - standard length of Buffer
in - InputStream
Method Detail

getData

public byte[] getData(int i)
               throws java.io.IOException
get data (as byte array) from i'th Buffer

Parameters:
i - Buffer index
Returns:
byte array
Throws:
java.io.IOException - if i'th Buffer not exists and couldn't be read from InputStream

getDataImpl

protected byte[] getDataImpl(int i)
                      throws java.io.IOException
read all data sequential

Parameters:
i - Buffer index
Returns:
byte array
Throws:
java.io.IOException

fillBuffer

protected void fillBuffer(int tillIndex)
read all Buffers from current index till tillIndex from InputStream

Parameters:
tillIndex -

getDataLength

public int getDataLength(int i)
get length of i'th Buffer

Parameters:
i - Buffer index
Returns:
int
Throws:
java.lang.ArrayIndexOutOfBoundsException - if i'th Buffer not exists (e.g. wasn't yet read)

getIndex

public int getIndex(long pos)
get index of Buffer which contains pos

Parameters:
pos -
Returns:
index of Buffer or -1

getLength

public long getLength()
get length of data of all already read Buffer together (may change)


getDataStart

public long getDataStart(int i)
get start of i'th Buffer in byte
I assume here that length of each Buffer (except last one) equals to dsLength

Parameters:
i -
Returns:
int
                          n-1
dataStart(n) = Σ getDataLength(i)
                          i=0

close

public void close()
closes underlined InputStream and drops all Buffers