net.jbeans.io
Class JBeansReader

java.lang.Object
  extended byjava.io.Reader
      extended bynet.jbeans.io.JBeansReader

public final class JBeansReader
extends java.io.Reader

JBeansReader reads strings and numbers from a reader or an input stream.

Version:
$Revision: 1.1.1.1 $
Author:
Masahiro Takatsuka (masa@jbeans.net)
See Also:
Reader

Field Summary
protected static java.lang.String STREAM_CLOSED
           
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
JBeansReader(java.io.InputStream in)
          Construct a newly created JBeansReader
JBeansReader(java.io.InputStream in, java.lang.String delim)
          Construct a newly created JBeansReader
JBeansReader(java.io.InputStream in, java.lang.String delim, boolean returnTokens)
          Construct a newly created JBeansReader
JBeansReader(java.io.Reader in)
          Construct a newly created JBeansReader
JBeansReader(java.io.Reader in, java.lang.String delim)
          Construct a newly created JBeansReader
JBeansReader(java.io.Reader in, java.lang.String delim, boolean returnTokens)
          Construct a newly created JBeansReader
 
Method Summary
 void close()
          Close the stream.
static void main(java.lang.String[] args)
          Test routine.
 int read(char[] cbuf, int off, int len)
          Read characters into a portion of an array.
 java.lang.String read(int len)
          Reads the specified numbers of characters and returns as a String.
static java.lang.String read(java.io.Reader reader, int len)
          Reads the specified numbers of characters from the specified Reader and returns as a String.
 boolean readBoolean()
          Reads a boolean from this data input stream.
 byte readByte()
          Reads a signed 8-bit value from this data input stream.
 char readChar()
          Reads a Unicode character from this data input stream.
static int readChars(char[] chars, java.io.Reader reader, int len)
          Reads the specified numbers of characters from the specified Reader and returns as a String.
static char[] readChars(java.io.Reader reader, int len)
          Reads the specified numbers of characters from the specified Reader and returns as a String.
 double readDouble()
          Reads a double from this data input stream.
 float readFloat()
          Reads a float from this data input stream.
 int readInt()
          Reads a signed 32-bit integer from this data input stream.
 java.lang.String readLine()
          Read a line of text.
 java.lang.String readLine(char commentchar)
          Read a line of text.
 java.lang.String readLine(java.lang.String commentchars)
          Read a line of text.
 long readLong()
          Reads a signed 64-bit integer from this data input stream.
 short readShort()
          Reads a signed 16-bit number from this data input stream.
 java.lang.String readToken()
          Read one token as a string.
 boolean ready()
          Tell whether this stream is ready to be read.
 
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
 

Field Detail

STREAM_CLOSED

protected static final java.lang.String STREAM_CLOSED
See Also:
Constant Field Values
Constructor Detail

JBeansReader

public JBeansReader(java.io.InputStream in,
                    java.lang.String delim,
                    boolean returnTokens)
Construct a newly created JBeansReader

Parameters:
in - An InputStream.
delim - the delimiters.
returnTokens - flag indicating whether to return the delimiters as tokens.

JBeansReader

public JBeansReader(java.io.InputStream in,
                    java.lang.String delim)
Construct a newly created JBeansReader

Parameters:
in - An InputStream.
delim - the delimiters.

JBeansReader

public JBeansReader(java.io.InputStream in)
Construct a newly created JBeansReader

Parameters:
in - An InputStream.

JBeansReader

public JBeansReader(java.io.Reader in,
                    java.lang.String delim,
                    boolean returnTokens)
Construct a newly created JBeansReader

Parameters:
in - A Reader.
delim - the delimiters.
returnTokens - flag indicating whether to return the delimiters as tokens.

JBeansReader

public JBeansReader(java.io.Reader in,
                    java.lang.String delim)
Construct a newly created JBeansReader

Parameters:
in - A Reader.
delim - the delimiters.

JBeansReader

public JBeansReader(java.io.Reader in)
Construct a newly created JBeansReader

Parameters:
in - A Reader.
Method Detail

read

public final int read(char[] cbuf,
                      int off,
                      int len)
               throws java.io.IOException
Read characters into a portion of an array.

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:
java.io.IOException - If an I/O error occurs

read

public final java.lang.String read(int len)
                            throws java.io.IOException
Reads the specified numbers of characters and returns as a String.

Throws:
java.io.IOException

readChars

public static final char[] readChars(java.io.Reader reader,
                                     int len)
                              throws java.io.IOException
Reads the specified numbers of characters from the specified Reader and returns as a String.

Throws:
java.io.IOException

readChars

public static final int readChars(char[] chars,
                                  java.io.Reader reader,
                                  int len)
                           throws java.io.IOException
Reads the specified numbers of characters from the specified Reader and returns as a String.

Throws:
java.io.IOException

read

public static final java.lang.String read(java.io.Reader reader,
                                          int len)
                                   throws java.io.IOException
Reads the specified numbers of characters from the specified Reader and returns as a String.

Throws:
java.io.IOException

ready

public final boolean ready()
                    throws java.io.IOException
Tell whether this stream is ready to be read. An InputReader is ready if its input buffer is not empty, or if bytes are available to be read from the underlying byte stream.

Throws:
java.io.IOException - If an I/O error occurs

close

public final void close()
                 throws java.io.IOException
Close the stream.

Throws:
java.io.IOException - If an I/O error occurs

readLine

public final java.lang.String readLine()
                                throws java.io.IOException
Read a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.

Returns:
A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached
Throws:
java.io.IOException - If an I/O error occurs

readLine

public final java.lang.String readLine(java.lang.String commentchars)
                                throws java.io.IOException
Read a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.

Returns:
A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached
Throws:
java.io.IOException - If an I/O error occurs

readLine

public final java.lang.String readLine(char commentchar)
                                throws java.io.IOException
Read a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.

Returns:
A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached
Throws:
java.io.IOException - If an I/O error occurs

readToken

public final java.lang.String readToken()
                                 throws java.io.IOException
Read one token as a string.

Returns:
A String containing the string, or null if the end of the stream has been reached.
Throws:
java.io.IOException - If an I/O error occurs

readBoolean

public final boolean readBoolean()
                          throws java.io.IOException
Reads a boolean from this data input stream. This method reads a single byte from the underlying input stream. A value of 0 represents false. Any other value represents true. This method blocks until either the byte is read, the end of the stream is detected, or an exception is thrown.

Returns:
the boolean value read.
Throws:
java.io.EOFException - if this input stream has reached the end.
java.io.IOException - if an I/O error occurs.

readByte

public final byte readByte()
                    throws java.io.IOException
Reads a signed 8-bit value from this data input stream. This method reads a byte from the underlying input stream. If the byte read is b, where 0 <= b <= 255, then the result is:

This method blocks until either the byte is read, the end of the stream is detected, or an exception is thrown.

Returns:
the next byte of this input stream as a signed 8-bit byte.
Throws:
java.io.EOFException - if this input stream has reached the end.
java.io.IOException - if an I/O error occurs.

readShort

public final short readShort()
                      throws java.io.IOException
Reads a signed 16-bit number from this data input stream. The method reads two bytes from the underlying input stream. If the two bytes read, in order, are b1 and b2, where each of the two values is between 0 and 255, inclusive, then the result is equal to:

This method blocks until the two bytes are read, the end of the stream is detected, or an exception is thrown.

Returns:
the next two bytes of this input stream, interpreted as a signed 16-bit number.
Throws:
java.io.EOFException - if this input stream reaches the end before reading two bytes.
java.io.IOException - if an I/O error occurs.

readChar

public final char readChar()
                    throws java.io.IOException
Reads a Unicode character from this data input stream. This method reads two bytes from the underlying input stream. If the bytes read, in order, are b1 and b2, where 0 <= b1, b1 <= 255, then the result is equal to:

This method blocks until either the two bytes are read, the end of the stream is detected, or an exception is thrown.

Returns:
the next two bytes of this input stream as a Unicode character.
Throws:
java.io.EOFException - if this input stream reaches the end before reading two bytes.
java.io.IOException - if an I/O error occurs.

readInt

public final int readInt()
                  throws java.io.IOException
Reads a signed 32-bit integer from this data input stream. This method reads four bytes from the underlying input stream. If the bytes read, in order, are b1, b2, b3, and b4, where 0 <= b1, b2, b3, b4 <= 255, then the result is equal to:

This method blocks until the four bytes are read, the end of the stream is detected, or an exception is thrown.

Returns:
the next four bytes of this input stream, interpreted as an int.
Throws:
java.io.EOFException - if this input stream reaches the end before reading four bytes.
java.io.IOException - if an I/O error occurs.

readLong

public final long readLong()
                    throws java.io.IOException
Reads a signed 64-bit integer from this data input stream. This method reads eight bytes from the underlying input stream. If the bytes read, in order, are b1, b2, b3, b4, b5, b6, b7, and b8, where

then the result is equal to:

     ((long)b1 << 56) + ((long)b2 << 48) +
        ((long)b3 << 40) + ((long)b4 << 32) +
        ((long)b5 << 24) + (b6 << 16) +
        (b7 << 8) + b8
 

This method blocks until the eight bytes are read, the end of the stream is detected, or an exception is thrown.

Returns:
the next eight bytes of this input stream, interpreted as a long.
Throws:
java.io.EOFException - if this input stream reaches the end before reading eight bytes.
java.io.IOException - if an I/O error occurs.

readFloat

public final float readFloat()
                      throws java.io.IOException
Reads a float from this data input stream. This method reads an int value as if by the readInt method and then converts that int to a float using the intBitsToFloat method in class Float. This method blocks until the four bytes are read, the end of the stream is detected, or an exception is thrown.

Returns:
the next four bytes of this input stream, interpreted as a float.
Throws:
java.io.EOFException - if this input stream reaches the end before reading four bytes.
java.io.IOException - if an I/O error occurs.

readDouble

public final double readDouble()
                        throws java.io.IOException
Reads a double from this data input stream. This method reads a long value as if by the readLong method and then converts that long to a double using the longBitsToDouble method in class Double.

This method blocks until the eight bytes are read, the end of the stream is detected, or an exception is thrown.

Returns:
the next eight bytes of this input stream, interpreted as a double.
Throws:
java.io.EOFException - if this input stream reaches the end before reading eight bytes.
java.io.IOException - if an I/O error occurs.

main

public static final void main(java.lang.String[] args)
Test routine.

Parameters:
args - the command line arguments.


Copyright © 2003 JBean project. All Rights Reserved.