Class HttpParser
java.lang.Object
com.github.bottomlessarchive.warc.service.http.HttpParser
public class HttpParser
extends java.lang.Object
-
Method Summary
Modifier and Type Method Description static java.lang.StringgetString(byte[] data, int offset, int length, java.nio.charset.Charset charset)Converts the byte array of HTTP content characters to a string.static org.apache.http.Header[]parseHeaders(java.io.InputStream is, java.nio.charset.Charset charset)Parses headers from the given stream.static java.lang.StringreadLine(java.io.InputStream inputStream, java.nio.charset.Charset charset)Read up to "\n" from an (unchunked) input stream.static byte[]readRawLine(java.io.InputStream inputStream)Return byte array from an (unchunked) input stream.
-
Method Details
-
readLine
public static java.lang.String readLine(java.io.InputStream inputStream, java.nio.charset.Charset charset) throws java.io.IOExceptionRead 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,nullis returned.- Parameters:
inputStream- the stream to read fromcharset- charset of HTTP protocol elements- Returns:
- a line from the stream
- Throws:
java.io.IOException- if an I/O problem occurs
-
readRawLine
public static byte[] readRawLine(java.io.InputStream inputStream) throws java.io.IOExceptionReturn 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,nullis returned.- Parameters:
inputStream- the stream to read from- Returns:
- a byte array from the stream
- Throws:
java.io.IOException- if an I/O problem occurs
-
parseHeaders
public static org.apache.http.Header[] parseHeaders(java.io.InputStream is, java.nio.charset.Charset charset) throws java.io.IOException, org.apache.http.HttpExceptionParses headers from the given stream. Headers with the same name are not combined.- Parameters:
is- the stream to read headers fromcharset- the charset to use for reading the data- Returns:
- an array of headers in the order in which they were parsed
- Throws:
java.io.IOException- if an IO error occurs while reading from the streamorg.apache.http.HttpException- if there is an error parsing a header value
-
getString
public static java.lang.String getString(byte[] data, int offset, int length, java.nio.charset.Charset charset)Converts the byte array of HTTP content characters to a string. If the specified charset is not supported, default system encoding is used.- Parameters:
data- the byte array to be encodedoffset- the index of the first byte to encodelength- the number of bytes to encodecharset- the desired character encoding- Returns:
- The result of the conversion.
- Since:
- 3.0
-