Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| HTML Parser Home Page
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.htmlparser.lexer
Class Source

    java.lang.Object
      java.io.Reader
          org.htmlparser.lexer.Source

All Implemented Interfaces:
  Serializable

public class Source
extends Reader
implements Serializable

A buffered source of characters. A Source is very similar to a the following construct:

     new InputStreamReader (new BufferedInputStream (connection.getInputStream ()), charset)

It differs from the above, in two ways:
- the fetching of bytes from the connection's input stream may be asynchronous
- the character set may be changed, which resets the input stream

See Also:
  Serialized Form

Field Summary
`static int` | `BUFFER_SIZE` An initial buffer size.
`static int` | `EOF` Return value when no more characters are left.
`char[]` | `mBuffer` The characters read so far.
`protected String` | `mEncoding` The character set in use.
`int` | `mLevel` The number of valid bytes in the buffer.
`protected int` | `mMark` The bookmark.
`int` | `mOffset` The offset of the next byte returned by read().
`protected InputStreamReader` | `mReader` The converter from bytes to characters.
`protected InputStream` | `mStream` The stream of bytes.

Fields inherited from class java.io.Reader
`lock`

Constructor Summary
`Source(InputStream stream)` Create a source of characters using the default character set.
`Source(InputStream stream, String charset)` Create a source of characters.
`Source(InputStream stream, String charset, int buffer_size)` Create a source of characters.

Method Summary
`int` | `available()` Get the number of available characters.
`void` | `close()` Does nothing.
`void` | `destroy()` Close the stream.
`protected void` | `fill(int min)` Fetch more characters from the underlying reader.
`String` | `getEncoding()` Get the encoding being used to convert characters.
`InputStream` | `getStream()` Get the input stream being used.
`void` | `mark(int readAheadLimit)` Mark the present position in the stream.
`boolean` | `markSupported()` Tell whether this stream supports the mark() operation.
`int` | `offset()` Get the position (in characters).
`int` | `read()` Read a single character.
`int` | `read(char[] cbuf)` Read characters into an array.
`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` | `reset()` Reset the source.
`long` | `skip(long n)` Skip characters.
`void` | `unread()` Undo the read of a single character.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### BUFFER_SIZE

    public static int BUFFER_SIZE

  An initial buffer size.

### EOF

    public static final int EOF

  Return value when no more characters are left.

  See Also:
    Constant Field Values

### mStream

    protected transient InputStream mStream

  The stream of bytes.

### mEncoding

    protected String mEncoding

  The character set in use.

### mReader

    protected transient InputStreamReader mReader

  The converter from bytes to characters.

### mBuffer

    public char[] mBuffer

  The characters read so far.

### mLevel

    public int mLevel

  The number of valid bytes in the buffer.

### mOffset

    public int mOffset

  The offset of the next byte returned by read().

### mMark

    protected int mMark

  The bookmark.

Constructor Detail

### Source

    public Source(InputStream stream)
           throws UnsupportedEncodingException

  Create a source of characters using the default character set.

Parameters:
  `stream` - The stream of bytes to use.

### Source

    public Source(InputStream stream,
                  String charset)
           throws UnsupportedEncodingException

  Create a source of characters.

Parameters:
  `stream` - The stream of bytes to use.
  `charset` - The character set used in encoding the stream.

### Source

    public Source(InputStream stream,
                  String charset,
                  int buffer_size)
           throws UnsupportedEncodingException

  Create a source of characters.

Parameters:
  `stream` - The stream of bytes to use.
  `charset` - The character set used in encoding the stream.

Method Detail

### getStream

    public InputStream getStream()

  Get the input stream being used.

  Returns:
    The current input stream.

### getEncoding

    public String getEncoding()

  Get the encoding being used to convert characters.

  Returns:
    The current encoding.

### fill

    protected void fill(int min)
                 throws IOException

  Fetch more characters from the underlying reader. Has no effect if the underlying reader has been drained.

  Parameters:
    `min` - The minimum to read.
  Throws:
    `IOException` - If the underlying reader read() throws one.

### close

    public void close()
               throws IOException

  Does nothing. It's supposed to close the stream, but use destroy() instead.

  Throws:
    `IOException`
  See Also:
    `destroy()`

### 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.

  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.

### 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.

  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(char[] cbuf)
             throws IOException

  Read characters into an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

  Parameters:
    `cbuf` - Destination buffer.
  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.

### reset

    public void reset()

  Reset the source. Repositions the read point to begin at zero.

  Throws:
    `IllegalStateException` - If the source has been closed.

### markSupported

    public boolean markSupported()

  Tell whether this stream supports the mark() operation.

  Returns:
    `true` if and only if this stream supports the mark operation.

### mark

    public void mark(int readAheadLimit)
              throws IOException

  Mark the present position in the stream. Subsequent calls to reset() will attempt to reposition the stream to this point. Not all character-input streams support the mark() operation.

  Parameters:
    `readAheadLimit` - Not used.
  Throws:
    `IOException` - Never thrown.

### ready

    public boolean ready()
                  throws IOException

  Tell whether this stream is ready to be read.

  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` - Never thrown.

### skip

    public long skip(long n)
              throws IOException

  Skip characters. This method will block until some characters are available, an I/O error occurs, or the end of the stream is reached. Note: n is treated as an int

  Parameters:
    `n` - The number of characters to skip.
  Returns:
    The number of characters actually skipped
  Throws:
    `IllegalArgumentException` - If `n` is negative.
    `IOException` - If an I/O error occurs.

### unread

    public void unread()
                throws IOException

  Undo the read of a single character.

  Throws:
    `IOException` - If no characters have been read.

### destroy

    public void destroy()
                 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.

  Throws:
    `IOException` - If an I/O error occurs

### offset

    public int offset()

  Get the position (in characters).

  Returns:
    The number of characters that have been read.

### available

    public int available()

  Get the number of available characters.

  Returns:
    The number of characters that can be read without blocking.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| © 2004 Somik Raha Mar 14, 2004
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

HTML Parser is an open source library released under LGPL.