org.utgenome.util
Class ReaderInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.utgenome.util.ReaderInputStream
All Implemented Interfaces:
Closeable

public class ReaderInputStream
extends InputStream

Adapts a Reader as an InputStream. Adapted from StringInputStream.


Constructor Summary
ReaderInputStream(Reader reader)
          Construct a ReaderInputStream for the specified Reader.
ReaderInputStream(Reader reader, Charset charset)
          Construct a ReaderInputStream for the specified Reader, with the specified encoding.
ReaderInputStream(Reader reader, String encoding)
          Construct a ReaderInputStream for the specified Reader, with the specified encoding.
 
Method Summary
 int available()
           
 void close()
          Closes the Stringreader.
 void mark(int limit)
          Marks the read limit of the StringReader.
 boolean markSupported()
           
 int read()
          Reads from the Reader, returning the same value.
 int read(byte[] b, int off, int len)
          Reads from the Reader into a byte array
 void reset()
          Resets the StringReader.
 
Methods inherited from class java.io.InputStream
read, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReaderInputStream

public ReaderInputStream(Reader reader)
Construct a ReaderInputStream for the specified Reader.

Parameters:
reader - Reader. Must not be null.

ReaderInputStream

public ReaderInputStream(Reader reader,
                         String encoding)
Construct a ReaderInputStream for the specified Reader, with the specified encoding.

Parameters:
reader - non-null Reader.
encoding - non-null String encoding.

ReaderInputStream

public ReaderInputStream(Reader reader,
                         Charset charset)
Construct a ReaderInputStream for the specified Reader, with the specified encoding.

Parameters:
reader - non-null Reader.
encoding - non-null Charset
Method Detail

read

public int read()
         throws IOException
Reads from the Reader, returning the same value.

Specified by:
read in class InputStream
Returns:
the value of the next character in the Reader.
Throws:
IOException - if the original Reader fails to be read

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Reads from the Reader into a byte array

Overrides:
read in class InputStream
Parameters:
b - the byte array to read into
off - the offset in the byte array
len - the length in the byte array to fill
Returns:
the actual number read into the byte array, -1 at the end of the stream
Throws:
IOException - if an error occurs

mark

public void mark(int limit)
Marks the read limit of the StringReader.

Overrides:
mark in class InputStream
Parameters:
limit - the maximum limit of bytes that can be read before the mark position becomes invalid

available

public int available()
              throws IOException
Overrides:
available in class InputStream
Returns:
the current number of bytes ready for reading
Throws:
IOException - if an error occurs

markSupported

public boolean markSupported()
Overrides:
markSupported in class InputStream
Returns:
false - mark is not supported

reset

public void reset()
           throws IOException
Resets the StringReader.

Overrides:
reset in class InputStream
Throws:
IOException - if the StringReader fails to be reset

close

public void close()
           throws IOException
Closes the Stringreader.

Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException - if the original StringReader fails to be closed


Copyright © 2007-2012 utgenome.org. All Rights Reserved.