Package org.apache.any23.util
Class StreamUtils
- java.lang.Object
-
- org.apache.any23.util.StreamUtils
-
public class StreamUtils extends Object
Contains general utility functions for handling streams.- Author:
- Michele Mostarda (mostarda@fbk.eu)
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String[]
asLines(InputStream is)
Returns all the lines read from an input stream.static String
asString(InputStream is)
Returns the string content of a stream, new line chars will be removed.static String
asString(InputStream is, boolean preserveNL)
Returns the string content of a stream.static void
closeGracefully(Closeable closable)
Closes the closable interface and reports error if any.static InputStream
documentToInputStream(Document doc)
Converts aDocument
to anInputStream
static Document
inputStreamToDocument(InputStream is)
-
-
-
Method Detail
-
asLines
public static String[] asLines(InputStream is) throws IOException
Returns all the lines read from an input stream.- Parameters:
is
- input stream.- Returns:
- list of not
null
lines. - Throws:
IOException
- if an error occurs while consuming theis
stream.
-
asString
public static String asString(InputStream is, boolean preserveNL) throws IOException
Returns the string content of a stream.- Parameters:
is
- input stream.preserveNL
- preserves new line chars.- Returns:
- the string content.
- Throws:
IOException
- if an error occurs while consuming theis
stream.
-
asString
public static String asString(InputStream is) throws IOException
Returns the string content of a stream, new line chars will be removed.- Parameters:
is
- input stream.- Returns:
- the string content.
- Throws:
IOException
- if an error occurs while consuming theis
stream.
-
closeGracefully
public static void closeGracefully(Closeable closable)
Closes the closable interface and reports error if any.- Parameters:
closable
- the closable object to be closed.
-
documentToInputStream
public static InputStream documentToInputStream(Document doc) throws TransformerConfigurationException, TransformerFactoryConfigurationError
Converts aDocument
to anInputStream
- Parameters:
doc
- theDocument
to convert- Returns:
- an
InputStream
representing the contents of the inputDocument
- Throws:
TransformerFactoryConfigurationError
- thrown when there is a problem with configuration with the Transformer FactoriesTransformerConfigurationException
- thrown when a serious configuration error exists
-
inputStreamToDocument
public static Document inputStreamToDocument(InputStream is) throws org.apache.xerces.impl.io.MalformedByteSequenceException
- Throws:
org.apache.xerces.impl.io.MalformedByteSequenceException
-
-