org.netbeans.mdr.persistence.btreeimpl.btreestorage
Class CachedPageInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.netbeans.mdr.persistence.btreeimpl.btreestorage.CachedPageInputStream
All Implemented Interfaces:
java.io.Closeable

public class CachedPageInputStream
extends java.io.InputStream

A stream composed of segments stored in CachedPages. The pages are pinned while members of a CachedPageInputStream. When done with the stream, close it to unpin the pages.


Constructor Summary
CachedPageInputStream()
           
 
Method Summary
 void addPage(CachedPage pg, int offst, int len)
          Add a page to the stream
 int available()
          report how many bytes are still unread
 void close()
          close the stream.
protected  void finalize()
          if the stream was never closed, unpin the pages now
 void mark(int readlimit)
          mark a spot in the stream, which reset will return to
 boolean markSupported()
          this class supports mark (since it's easy)
 int read()
          read a byte from the stream
 int read(byte[] b)
          read bytes into an array
 int read(byte[] b, int offset, int length)
          read bytes into an array
 void reset()
          return to where mark was last called, or to the beginning if mark was never called.
 
Methods inherited from class java.io.InputStream
skip
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachedPageInputStream

public CachedPageInputStream()
Method Detail

addPage

public void addPage(CachedPage pg,
                    int offst,
                    int len)
Add a page to the stream

Parameters:
pg - the page to add
offst - the offset in the page where the stream data begins

close

public void close()
           throws java.io.IOException
close the stream. This unpins all of the pages from the cache.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.InputStream
Throws:
java.io.IOException - if there is an error unpinning the pages.

read

public int read()
read a byte from the stream

Specified by:
read in class java.io.InputStream
Returns:
The next byte in the stream, or -1 if at EOF.

read

public int read(byte[] b)
read bytes into an array

Overrides:
read in class java.io.InputStream
Parameters:
b - up to b.length bytes are read into this array
Returns:
The number of bytes read. If at EOF, -1 is returned

read

public int read(byte[] b,
                int offset,
                int length)
read bytes into an array

Overrides:
read in class java.io.InputStream
Parameters:
b - up to length bytes are read into this array
offset - the offset into the array at whch to start storing bytes
maximum - number of bytes to read
Returns:
The number of bytes read. If at EOF, -1 is returned

markSupported

public boolean markSupported()
this class supports mark (since it's easy)

Overrides:
markSupported in class java.io.InputStream
Returns:
true, since we support mark

mark

public void mark(int readlimit)
mark a spot in the stream, which reset will return to

Overrides:
mark in class java.io.InputStream
Parameters:
readlimit - ignored

available

public int available()
report how many bytes are still unread

Overrides:
available in class java.io.InputStream
Returns:
number of bytes left in stream

reset

public void reset()
return to where mark was last called, or to the beginning if mark was never called.

Overrides:
reset in class java.io.InputStream

finalize

protected void finalize()
                 throws StorageException
if the stream was never closed, unpin the pages now

Overrides:
finalize in class java.lang.Object
Throws:
StorageException


Copyright © 2005-2008 Apache Software Foundation. All Rights Reserved.