Package dk.netarkivet.common.utils
Class InputStreamUtils
- java.lang.Object
-
- dk.netarkivet.common.utils.InputStreamUtils
-
public class InputStreamUtils extends java.lang.Object
This class provides various utilities for inputstreams.
-
-
Constructor Summary
Constructors Constructor Description InputStreamUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
readLine(java.io.InputStream inputStream)
Read a line of bytes from an InputStream.static byte[]
readRawLine(java.io.InputStream inputStream)
Reads a raw line from an InputStream, up till \n.
-
-
-
Constructor Detail
-
InputStreamUtils
public InputStreamUtils()
-
-
Method Detail
-
readLine
public static java.lang.String readLine(java.io.InputStream inputStream) throws java.io.IOException
Read a line of bytes from an InputStream. Useful when an InputStream may contain both text and binary data.- Parameters:
inputStream
- A source of data- Returns:
- A line of text read from inputStream, with terminating \r\n or \n removed, or null if no data is available.
- Throws:
java.io.IOException
- on trouble reading from input stream
-
readRawLine
public static byte[] readRawLine(java.io.InputStream inputStream) throws java.io.IOException
Reads a raw line from an InputStream, up till \n. Since HTTP allows \r\n and \n as terminators, this gets the whole line. This code is adapted from org.apache.commons.httpclient.HttpParser- Parameters:
inputStream
- A stream to read from.- Returns:
- Array of bytes read or null if none are available.
- Throws:
java.io.IOException
- if the underlying reads fail
-
-