org.apache.commons.httpclient

Class HttpParser


public class HttpParser
extends Object

A utility class for parsing http header values according to RFC-2616 Section 4 and 19.3.
Since:
2.0beta1

Method Summary

static Header[]
parseHeaders(InputStream is)
Deprecated. use #parseHeaders(InputStream, String)
static Header[]
parseHeaders(InputStream is, String charset)
Parses headers from the given stream.
static String
readLine(InputStream inputStream)
Deprecated. use #readLine(InputStream, String)
static String
readLine(InputStream inputStream, String charset)
Read up to "\n" from an (unchunked) input stream.
static byte[]
readRawLine(InputStream inputStream)
Return byte array from an (unchunked) input stream.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Details

parseHeaders

public static Header[] parseHeaders(InputStream is)
            throws IOException,
                   HttpException

Deprecated. use #parseHeaders(InputStream, String)

Parses headers from the given stream. Headers with the same name are not combined.
Parameters:
is - the stream to read headers from
Returns:
an array of headers in the order in which they were parsed
Throws:
IOException - if an IO error occurs while reading from the stream
HttpException - if there is an error parsing a header value

parseHeaders

public static Header[] parseHeaders(InputStream is,
                                    String charset)
            throws IOException,
                   HttpException
Parses headers from the given stream. Headers with the same name are not combined.
Parameters:
is - the stream to read headers from
charset - the charset to use for reading the data
Returns:
an array of headers in the order in which they were parsed
Throws:
IOException - if an IO error occurs while reading from the stream
HttpException - if there is an error parsing a header value
Since:
3.0
Usages and Demos :

View More Examples of parseHeaders(InputStream is,String charset)
   1: import org.apache.commons.httpclient.Header;
   2: import org.apache.commons.httpclient.HttpParser;
   3: import org.apache.commons.httpclient.StatusLine;
   4:         ...
   5:             do {
   6:                 line = HttpParser.readLine(in, HTTP_ELEMENT_CHARSET);
   7:             } while (line != null && line.length() == 0);
   8:         ...
   9:                     RequestLine.parseLine(line),
  10:                     HttpParser.parseHeaders(this.in, HTTP_ELEMENT_CHARSET),
  11:                     this.in);
  12:         ...
  13:             do {
  14:                 line = HttpParser.readLine(in, HTTP_ELEMENT_CHARSET);

View Full Code Here

readLine

public static String readLine(InputStream inputStream)
            throws IOException

Deprecated. use #readLine(InputStream, String)

Read up to "\n" from an (unchunked) input stream. If the stream ends before the line terminator is found, the last part of the string will still be returned. If no input data available, null is returned
Parameters:
inputStream - the stream to read from
Returns:
a line from the stream
Throws:
IOException - if an I/O problem occurs

readLine

public static String readLine(InputStream inputStream,
                              String charset)
            throws IOException
Read up to "\n" from an (unchunked) input stream. If the stream ends before the line terminator is found, the last part of the string will still be returned. If no input data available, null is returned.
Parameters:
inputStream - the stream to read from
charset - charset of HTTP protocol elements
Returns:
a line from the stream
Throws:
IOException - if an I/O problem occurs
Since:
3.0

readRawLine

public static byte[] readRawLine(InputStream inputStream)
            throws IOException
Return byte array from an (unchunked) input stream. Stop reading when "\n" terminator encountered If the stream ends before the line terminator is found, the last part of the string will still be returned. If no input data available, null is returned.
Parameters:
inputStream - the stream to read from
Returns:
a byte array from the stream
Throws:
IOException - if an I/O problem occurs