edu.upc.dama.dex.core
Class TextStream.TextReader

java.lang.Object
  extended by java.io.Reader
      extended by edu.upc.dama.dex.core.TextStream.TextReader
All Implemented Interfaces:
java.io.Closeable, java.lang.Readable
Enclosing class:
TextStream

public static class TextStream.TextReader
extends java.io.Reader

Reader implementation for TextStream.

This way we can use TextStream as a common Java Writer:

 long oid = ... // object OID
 long text = ... // TEXT attribute id
 dbg.getAttribute(oid, text, v);
 TextStream tstrm = v.getTextStream();
 StringBuffer sb = new StringBuffer();
 char[] buff = new char[200];
 int len = 0;
 BufferedReader br = new BufferedReader(new TextReader(tstrm));
 while ((len = br.read(buff, 0, 200)) != -1) {
     sb.append(buff, 0, len);
 }
 br.close(); // it already closes underlaying Reader and TextStream
 


Field Summary
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
TextStream.TextReader(TextStream strm)
          Creates a new instance.
 
Method Summary
 void close()
          Close the stream.
 boolean markSupported()
          Tell whether this stream supports the mark() operation.
 int read(char[] chars, int i, int i1)
          Read characters into a portion of an array.
 
Methods inherited from class java.io.Reader
mark, read, read, read, ready, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextStream.TextReader

public TextStream.TextReader(TextStream strm)
Creates a new instance.

Parameters:
strm - Underlaying reader TextStream.
Throws:
java.lang.IllegalArgumentException - If the given TextStream is not a reader stream.
Method Detail

markSupported

public boolean markSupported()
Tell whether this stream supports the mark() operation.

Overrides:
markSupported in class java.io.Reader
Returns:
true if and only if this stream supports the mark operation.

read

public int read(char[] chars,
                int i,
                int i1)
         throws java.io.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 java.io.Reader
Parameters:
chars - Destination buffer.
i - Offset at which to start storing characters
i1 - Maximum number of characters to read
Returns:
The number of characters read, or -1 if the end of the stream has been reached.
Throws:
java.io.IOException

close

public void close()
           throws java.io.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 java.io.Closeable
Specified by:
close in class java.io.Reader
Throws:
java.io.IOException