org.wso2.carbon.registry.core.jdbc.utils
Class DumpReader

java.lang.Object
  extended by java.io.Reader
      extended by org.wso2.carbon.registry.core.jdbc.utils.DumpReader
All Implemented Interfaces:
Closeable, Readable

public class DumpReader
extends Reader

A wrapper for the Reader that will cache the extra bytes consumed by xml stream reader in registry.restore(path, reader) operation which restore the resources from a dump.xml This keep track of the actual reading child resource (using setReadingChildResourceIndex) and consuming child resource with normal read functions, if the consumed ones have higher values than actually reading ones, this will buffer the extra bytes and release it after actual reading ones finished using it.


Field Summary
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
DumpReader(Reader reader)
          Constructor of the Dump Reader wrapping another reader.
 
Method Summary
 void close()
          Close the stream.
static int getMaxBufferedSize()
          Return the maximum size of the buffer when reading from the main reader.
static int getTotalBuffered()
          Return the total number of buffered bytes from the main reader.
static int getTotalBufferedRead()
          Return the total number of bytes read from the buffer (buffered when reading from the main reader)
static int getTotalRead()
          Return the total number of read bytes from the main reader.
 boolean isLastResource(int readingChildResourceIndex)
          To check whether the stream is in the last child resource.
 int read()
          Read a single character.
 int read(char[] cBuf, int off, int len)
          Read characters into a portion of an array.
 boolean ready()
          Tell whether this stream is ready to be read.
 void setCheckingChildByParent(boolean checkingChildByParent)
          Set whether the check is done by the parent, in that case we buffer all the bytes read since they will be re-read from the child side anyway.
 void setReadingChildResourceIndex(int readingChildResourceIndex)
          Set the reading child index
 
Methods inherited from class java.io.Reader
mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DumpReader

public DumpReader(Reader reader)
Constructor of the Dump Reader wrapping another reader.

Parameters:
reader - the wrapped reader, could be file reader, http reader or another dump reader
Method Detail

read

public int read(char[] cBuf,
                int off,
                int len)
         throws IOException
Read characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

Specified by:
read in class Reader
Parameters:
cBuf - destination buffer
off - offset at which to start storing characters
len - maximum number of characters to read
Returns:
the number of characters read, or -1 if the end of the stream has been reached
Throws:
IOException - if an I/O error occurs

read

public int read()
         throws IOException
Read a single character. This method will block until a character is available, an I/O error occurs, or the end of the stream is reached.

Subclasses that intend to support efficient single-character input should override this method.

Overrides:
read in class Reader
Returns:
the character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached
Throws:
IOException - if an I/O error occurs

close

public void close()
           throws IOException
Close the stream. Once a stream has been closed, further read(), ready(), mark(), or reset() invocations will throw an IOException. Closing a previously-closed stream, however, has no effect.

Specified by:
close in interface Closeable
Specified by:
close in class Reader
Throws:
IOException - if an I/O error occurs

setReadingChildResourceIndex

public void setReadingChildResourceIndex(int readingChildResourceIndex)
Set the reading child index

Parameters:
readingChildResourceIndex - the reading child index

setCheckingChildByParent

public void setCheckingChildByParent(boolean checkingChildByParent)
Set whether the check is done by the parent, in that case we buffer all the bytes read since they will be re-read from the child side anyway. Normally in a dump restore parent check child to read the child name to construct the child path.

Parameters:
checkingChildByParent - true if child is checked by parent, false otherwise

isLastResource

public boolean isLastResource(int readingChildResourceIndex)
                       throws IOException
To check whether the stream is in the last child resource. If so it will be consume all the bytes up to tag. This should be called only if he checkingChildByParent is set.

Parameters:
readingChildResourceIndex - the reading child index
Returns:
true, if this is the last child resource, false otherwise
Throws:
IOException - throws if the operation failed.

ready

public boolean ready()
              throws IOException
Tell whether this stream is ready to be read.

Overrides:
ready in class Reader
Returns:
true if the next read() is guaranteed not to block for input, false otherwise. Note that returning false does not guarantee that the next read will block.
Throws:
IOException - if an I/O error occurs

getTotalRead

public static int getTotalRead()
Return the total number of read bytes from the main reader.

Returns:
the total number of read bytes.

getTotalBuffered

public static int getTotalBuffered()
Return the total number of buffered bytes from the main reader.

Returns:
the total number of buffed bytes.

getMaxBufferedSize

public static int getMaxBufferedSize()
Return the maximum size of the buffer when reading from the main reader.

Returns:
the maximum size of the buffer.

getTotalBufferedRead

public static int getTotalBufferedRead()
Return the total number of bytes read from the buffer (buffered when reading from the main reader)

Returns:
the total number of bytes read from the buffer.


Copyright © 2011 WSO2 Inc. All Rights Reserved.