net.sf.okapi.common

## Class StreamUtil

- java.lang.Object
- - net.sf.okapi.common.StreamUtil

-     public class StreamUtil
      extends java.lang.Object

  Various manipulations of streams, files, etc. Most methods rewrap IOException as OkapiIOException.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `StreamUtil()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static long` | `calcCRC(java.io.InputStream in)`
    `static void` | `copy(java.io.File in, java.io.File out)` Copies one file to another.
    `static void` | `copy(java.io.File in, java.io.OutputStream out)`
    `static void` | `copy(java.io.InputStream in, java.io.File outputFile)` Copies an `InputStream` to a File.
    `static void` | `copy(java.io.InputStream is, java.io.OutputStream outputStream)` Copies an `InputStream` to an `OutputStream`.
    `static void` | `copy(java.io.InputStream is, java.lang.String outputPath)` Copies an `InputStream` to a File.
    `static void` | `copy(java.nio.channels.ReadableByteChannel inChannel, java.nio.channels.WritableByteChannel outChannel)` Copies a `ReadableByteChannel` to a `WritableByteChannel`.
    `static void` | `copy(java.nio.channels.ReadableByteChannel inChannel, java.nio.channels.WritableByteChannel outChannel, boolean closeChannels)` Copies a `ReadableByteChannel` to a `WritableByteChannel`.
    `static void` | `copy(java.lang.String fromPath, java.lang.String toPath, boolean move)` Copies a file from one location to another.
    `static FileCachedInputStream` | `createResettableStream(java.io.InputStream is, int bufferSize)`
    `static byte[]` | `inputStreamToBytes(java.io.InputStream in)` Reads an InputStream into an array of bytes.
    `boolean` | `isCompressed(byte[] bytes)`
    `static java.lang.String` | `streamAsString(java.io.InputStream in, java.lang.String encoding)`
    `static java.lang.String` | `streamUtf8AsString(java.io.InputStream in)`
    `static java.io.InputStream` | `stringAsStream(java.lang.String str, java.lang.String encoding)`

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

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

- - ### Constructor Detail

    - #### StreamUtil

          public StreamUtil()

  - ### Method Detail

    - #### inputStreamToBytes

          public static byte[] inputStreamToBytes(java.io.InputStream in)
                                           throws java.io.IOException

      Reads an InputStream into an array of bytes.
      Parameters:
        `in` - the input stream to read.
      Returns:
        the array of bytes read.
      Throws:
        `java.io.IOException` - if an error occurs.

    - #### copy

          public static void copy(java.io.File in,
                                  java.io.OutputStream out)

    - #### streamAsString

          public static java.lang.String streamAsString(java.io.InputStream in,
                                                        java.lang.String encoding)

    - #### streamUtf8AsString

          public static java.lang.String streamUtf8AsString(java.io.InputStream in)

    - #### stringAsStream

          public static java.io.InputStream stringAsStream(java.lang.String str,
                                                           java.lang.String encoding)

    - #### calcCRC

          public static long calcCRC(java.io.InputStream in)

    - #### copy

          public static void copy(java.nio.channels.ReadableByteChannel inChannel,
                                  java.nio.channels.WritableByteChannel outChannel)

      Copies a `ReadableByteChannel` to a `WritableByteChannel`.
      Parameters:
        `inChannel` - the input Channel.
        `outChannel` - the output Channel.
      Throws:
        `OkapiIOException` - if an error occurs.

    - #### copy

          public static void copy(java.nio.channels.ReadableByteChannel inChannel,
                                  java.nio.channels.WritableByteChannel outChannel,
                                  boolean closeChannels)

      Copies a `ReadableByteChannel` to a `WritableByteChannel`.
      Parameters:
        `inChannel` - the input Channel.
        `outChannel` - the output Channel.
        `closeChannels` - close in and out channels?
      Throws:
        `OkapiIOException` - if an error occurs.

    - #### copy

          public static void copy(java.io.InputStream in,
                                  java.io.File outputFile)

      Copies an `InputStream` to a File.
      Parameters:
        `in` - the input stream.
        `outputFile` - the output `File`.
      Throws:
        `OkapiIOException` - if an error occurs.

    - #### copy

          public static void copy(java.io.InputStream is,
                                  java.lang.String outputPath)

      Copies an `InputStream` to a File.
      Parameters:
        `is` - the input stream.
        `outputPath` - the output path.
      Throws:
        `OkapiIOException` - if an error occurs.

    - #### copy

          public static void copy(java.io.InputStream is,
                                  java.io.OutputStream outputStream)

      Copies an `InputStream` to an `OutputStream`.
      Parameters:
        `is` - the input stream.
        `outputStream` - the output stream.
      Throws:
        `OkapiIOException` - if an error occurs.

    - #### copy

          public static void copy(java.io.File in,
                                  java.io.File out)

      Copies one file to another.
      Parameters:
        `in` - the input file.
        `out` - the output file.
      Throws:
        `OkapiIOException` - if an error occurs.

    - #### copy

          public static void copy(java.lang.String fromPath,
                                  java.lang.String toPath,
                                  boolean move)

      Copies a file from one location to another.
      Parameters:
        `fromPath` - the path of the file to copy.
        `toPath` - the path of the copy to make.
        `move` - true to move the file, false to copy it.
      Throws:
        `OkapiIOException` - if an error occurs.

    - #### createResettableStream

          public static FileCachedInputStream createResettableStream(java.io.InputStream is,
                                                                     int bufferSize)
                                                              throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### isCompressed

          public boolean isCompressed(byte[] bytes)
                               throws java.io.IOException

      Throws:
        `java.io.IOException`