Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.mortbay.util
Class LineInput  view LineInput download LineInput.java

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.FilterInputStream
          extended byorg.mortbay.util.LineInput
All Implemented Interfaces:
java.io.Closeable

public class LineInput
extends java.io.FilterInputStream

Fast LineInput InputStream. This buffered InputStream provides methods for reading lines of bytes. The lines can be converted to String or character arrays either using the default encoding or a user supplied encoding. Buffering and data copying are highly optimized, making this an ideal class for protocols that mix character encoding lines with arbitrary byte data (eg HTTP). The buffer size is also the maximum line length in bytes and/or characters. If the byte length of a line is less than the max, but the character length is greater, than then trailing characters are lost. Line termination is forgiving and accepts CR, LF, CRLF or EOF. Line input uses the mark/reset mechanism, so any marks set prior to a readLine call are lost.

Version:
$Id: LineInput.java,v 1.11 2003/09/18 13:29:27 gregwilkins Exp $

Nested Class Summary
private static class LineInput.ByteBuffer
           
static class LineInput.LineBuffer
          Reusable LineBuffer.
 
Field Summary
private  int _avail
           
private  byte[] _buf
           
private  LineInput.ByteBuffer _byteBuffer
           
private  int _byteLimit
           
private  int _contents
           
private  java.lang.String _encoding
           
private  boolean _eof
           
private  boolean _lastCr
           
private  LineInput.LineBuffer _lineBuffer
           
private  int _mark
           
private  boolean _newByteLimit
           
private  int _pos
           
private  java.io.InputStreamReader _reader
           
private  boolean _seenCrLf
           
private static int CR
           
private static int LF
           
private static org.apache.commons.logging.Log log
           
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
LineInput(java.io.InputStream in)
          Constructor.
LineInput(java.io.InputStream in, int bufferSize)
          Constructor.
LineInput(java.io.InputStream in, int bufferSize, java.lang.String encoding)
          Constructor.
 
Method Summary
 int available()
          Calls the in.available() method.
 void destroy()
           
private  void fill()
           
private  int fillLine(int maxLen)
           
 int getByteLimit()
          Get the byte limit.
 java.io.InputStream getInputStream()
           
 void mark(int limit)
          Calls the in.mark(int) method.
 boolean markSupported()
          Calls the in.markSupported() method.
 int read()
          Calls the in.read() method
 int read(byte[] b, int off, int len)
          Calls the in.read(byte[], int, int) method.
 java.lang.String readLine()
          Read a line ended by CR, LF or CRLF.
 int readLine(byte[] b, int off, int len)
          Read a line ended by CR, LF or CRLF.
 int readLine(char[] c, int off, int len)
          Read a line ended by CR, LF or CRLF.
 LineInput.LineBuffer readLineBuffer()
          Read a Line ended by CR, LF or CRLF.
 LineInput.LineBuffer readLineBuffer(int len)
          Read a Line ended by CR, LF or CRLF.
 void reset()
          Calls the in.reset() method.
 void setByteLimit(int bytes)
          Set the byte limit.
 long skip(long n)
          Calls the in.skip(long) method
 
Methods inherited from class java.io.FilterInputStream
close, read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log

_buf

private byte[] _buf

_byteBuffer

private LineInput.ByteBuffer _byteBuffer

_reader

private java.io.InputStreamReader _reader

_mark

private int _mark

_pos

private int _pos

_avail

private int _avail

_contents

private int _contents

_byteLimit

private int _byteLimit

_newByteLimit

private boolean _newByteLimit

_lineBuffer

private LineInput.LineBuffer _lineBuffer

_encoding

private java.lang.String _encoding

_eof

private boolean _eof

_lastCr

private boolean _lastCr

_seenCrLf

private boolean _seenCrLf

LF

private static final int LF
See Also:
Constant Field Values

CR

private static final int CR
See Also:
Constant Field Values
Constructor Detail

LineInput

public LineInput(java.io.InputStream in)
Constructor. Default buffer and maximum line size is 2048.


LineInput

public LineInput(java.io.InputStream in,
                 int bufferSize)
Constructor.


LineInput

public LineInput(java.io.InputStream in,
                 int bufferSize,
                 java.lang.String encoding)
          throws java.io.UnsupportedEncodingException
Constructor.

Method Detail

getInputStream

public java.io.InputStream getInputStream()

setByteLimit

public void setByteLimit(int bytes)
Set the byte limit. If set, only this number of bytes are read before EOF.


getByteLimit

public int getByteLimit()
Get the byte limit.


readLine

public java.lang.String readLine()
                          throws java.io.IOException
Read a line ended by CR, LF or CRLF. The default or supplied encoding is used to convert bytes to characters.


readLine

public int readLine(char[] c,
                    int off,
                    int len)
             throws java.io.IOException
Read a line ended by CR, LF or CRLF. The default or supplied encoding is used to convert bytes to characters.


readLine

public int readLine(byte[] b,
                    int off,
                    int len)
             throws java.io.IOException
Read a line ended by CR, LF or CRLF.


readLineBuffer

public LineInput.LineBuffer readLineBuffer()
                                    throws java.io.IOException
Read a Line ended by CR, LF or CRLF. Read a line into a shared LineBuffer instance. The LineBuffer is resused between calls and should not be held by the caller. The default or supplied encoding is used to convert bytes to characters.


readLineBuffer

public LineInput.LineBuffer readLineBuffer(int len)
                                    throws java.io.IOException
Read a Line ended by CR, LF or CRLF. Read a line into a shared LineBuffer instance. The LineBuffer is resused between calls and should not be held by the caller. The default or supplied encoding is used to convert bytes to characters.


read

public int read()
         throws java.io.IOException
Description copied from class: java.io.FilterInputStream
Calls the in.read() method


read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Description copied from class: java.io.FilterInputStream
Calls the in.read(byte[], int, int) method.


skip

public long skip(long n)
          throws java.io.IOException
Description copied from class: java.io.FilterInputStream
Calls the in.skip(long) method


available

public int available()
              throws java.io.IOException
Description copied from class: java.io.FilterInputStream
Calls the in.available() method.


mark

public void mark(int limit)
          throws java.lang.IllegalArgumentException
Description copied from class: java.io.FilterInputStream
Calls the in.mark(int) method.


reset

public void reset()
           throws java.io.IOException
Description copied from class: java.io.FilterInputStream
Calls the in.reset() method.


markSupported

public boolean markSupported()
Description copied from class: java.io.FilterInputStream
Calls the in.markSupported() method.


fill

private void fill()
           throws java.io.IOException

fillLine

private int fillLine(int maxLen)
              throws java.io.IOException

destroy

public void destroy()