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 StringasString(InputStream is)Returns the string content of a stream, new line chars will be removed.static StringasString(InputStream is, boolean preserveNL)Returns the string content of a stream.static voidcloseGracefully(Closeable closable)Closes the closable interface and reports error if any.static InputStreamdocumentToInputStream(Document doc)Converts aDocumentto anInputStreamstatic DocumentinputStreamToDocument(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
nulllines. - Throws:
IOException- if an error occurs while consuming theisstream.
-
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 theisstream.
-
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 theisstream.
-
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 aDocumentto anInputStream- Parameters:
doc- theDocumentto convert- Returns:
- an
InputStreamrepresenting 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
-
-