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 a `Document` to an `InputStream`
    `static Document` | `inputStreamToDocument​(InputStream is)` |

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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 the `is` 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 the `is` 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 the `is` 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 a `Document` to an `InputStream`
      Parameters:
        `doc` - the `Document` to convert
      Returns:
        an `InputStream` representing the contents of the input `Document`
      Throws:
        `TransformerFactoryConfigurationError` - thrown when there is a problem with configuration with the Transformer Factories
        `TransformerConfigurationException` - 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`