oracle.dbtools.plugin.api.io

## Interface IOStreams

-     public interface IOStreams

  Methods for working with `InputStream`, `OutputStream`, `Readable`, and `Appendable` streams.
  Author:
    cdivilly

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `byte[]` | `asByteArray(CharSequence text)` Convert the specified text into a UTF-8 encoded `byte[]` array.
    `byte[]` | `asByteArray(InputStream is)` buffer the contents of the specified byte stream into a `byte[]` array.
    `byte[]` | `asByteArray(Readable r)` Buffer the contents of the specified `Readable` into a `byte[]` array
    `byte[]` | `asByteArray(ReadableByteChannel r)` Buffer the contents of the specified `ReadableByteChannel` into a `byte[]` array
    `SeekableByteChannel` | `asByteChannel(byte[] bytes)` Adapt the specified byte array to a read only instance of `SeekableByteChannel`.
    `InputStream` | `asInputStream(byte[] bytes)` Adapt the specified byte array to an instance of `InputStream`.
    `InputStream` | `asInputStream(CharSequence text)` Convert a `CharSequence` into an `InputStream` instance
    `String` | `asString(InputStream is)` Buffer the contents of the specified byte stream into a `String`.
    `String` | `asString(Readable r)` Buffer the contents of the specified character stream into a `String` .
    `long` | `copy(InputStream is, OutputStream os)` Copy the contents of a `InputStream` to an `OutputStream`
    `long` | `copy(Readable source, Appendable destination)` Copy the contents of a `Readable` (input character stream) to an `Appendable` (output character stream)
    `long` | `copy(ReadableByteChannel source, WritableByteChannel destination)` Copy the contents of a `ReadableByteChannel` (input byte stream) to a `WritableByteChannel` (output byte stream)
    `InputStream` | `emptyStream()` Return an InputStream containing zero bytes
    `boolean` | `isEmptyStream(InputStream stream)` Checks if the specified `InputStream` is the empty stream instance provided by `emptyStream()`.
    `OutputStream` | `nullStream()` Return an `OutputStream` that swallows all output silently
    `InputStream` | `uncloseable(InputStream in)` Wrapper an InputStream so it cannot be closed.

- - ### Method Detail

    - #### copy

          long copy(InputStream is,
                    OutputStream os)
             throws IOException

      Copy the contents of a `InputStream` to an `OutputStream`
      Parameters:
        `is` - The stream containing the content
        `os` - The stream to write the content to
      Returns:
        The number of bytes copied
      Throws:
        `IOException` - if an error occurs while reading/writing either stream

    - #### copy

          long copy(Readable source,
                    Appendable destination)
             throws IOException

      Copy the contents of a `Readable` (input character stream) to an `Appendable` (output character stream)
      Parameters:
        `source` - The stream containing the content
        `destination` - The stream to write the content to
      Returns:
        The number of characters copied
      Throws:
        `IOException` - if an error occurs while reading/writing either stream

    - #### copy

          long copy(ReadableByteChannel source,
                    WritableByteChannel destination)
             throws IOException

      Copy the contents of a `ReadableByteChannel` (input byte stream) to a `WritableByteChannel` (output byte stream)
      Parameters:
        `source` - The stream containing the content
        `destination` - The stream to write the content to
      Returns:
        The number of bytes copied
      Throws:
        `IOException` - if an error occurs while reading/writing either stream

    - #### emptyStream

          InputStream emptyStream()

      Return an InputStream containing zero bytes
      Returns:
        an empty stream

    - #### nullStream

          OutputStream nullStream()

      Return an `OutputStream` that swallows all output silently
      Returns:
        A null output stream

    - #### uncloseable

          InputStream uncloseable(InputStream in)

      Wrapper an InputStream so it cannot be closed.
      Parameters:
        `in` - InputStream instance
      Returns:
        InputStream instance that cannot be closed.

    - #### isEmptyStream

          boolean isEmptyStream(InputStream stream)

      Checks if the specified `InputStream` is the empty stream instance provided by `emptyStream()`.
      Parameters:
        `stream` - The stream to be tested
      Returns:
        true if the specified `InputStream` is the same instance, false otherwise.

    - #### asString

          String asString(InputStream is)
                   throws IOException

      Buffer the contents of the specified byte stream into a `String`. The contents of the byte stream must be encoded in `UTF-8`.
      Parameters:
        `is` - The byte stream
      Returns:
        The buffered stream as a `String`
      Throws:
        `IOException` - if an error occurs while reading the stream

    - #### asString

          String asString(Readable r)
                   throws IOException

      Buffer the contents of the specified character stream into a `String` .
      Parameters:
        `r` - The character stream
      Returns:
        The buffered stream as a `String`
      Throws:
        `IOException` - if an error occurs while reading the stream

    - #### asInputStream

          InputStream asInputStream(CharSequence text)
                             throws IOException

      Convert a `CharSequence` into an `InputStream` instance
      Parameters:
        `text` - The text to be transformed into an `InputStream`
      Returns:
        `InputStream` instance
      Throws:
        `IOException` - if an error occurs while reading the stream

    - #### asInputStream

          InputStream asInputStream(byte[] bytes)

      Adapt the specified byte array to an instance of `InputStream`.
      Parameters:
        `bytes` - The bytes to be exposed as a stream
      Returns:
        The `InputStream` instance.

    - #### asByteChannel

          SeekableByteChannel asByteChannel(byte[] bytes)

      Adapt the specified byte array to a read only instance of `SeekableByteChannel`. Note that the `SeekableByteChannel.write(java.nio.ByteBuffer)` and `SeekableByteChannel.truncate(long)` methods of the returned instance will always throw `NonWritableChannelException`. The returned instance is not thread safe, the `SeekableByteChannel.position()` state is not multi-thread safe.
      Parameters:
        `bytes` - The bytes to be exposed as a byte channel
      Returns:
        read only `SeekableByteChannel` instance

    - #### asByteArray

          byte[] asByteArray(InputStream is)
                      throws IOException

      buffer the contents of the specified byte stream into a `byte[]` array.
      Parameters:
        `is` - The byte stream
      Returns:
        byte[] buffer containing the entire contents of the stream
      Throws:
        `IOException` - if an error occurs while reading the stream

    - #### asByteArray

          byte[] asByteArray(Readable r)
                      throws IOException

      Buffer the contents of the specified `Readable` into a `byte[]` array
      Parameters:
        `r` - The character stream
      Returns:
        byte[] buffer containing the entire contents of the stream
      Throws:
        `IOException` - if an error occurs while reading the stream

    - #### asByteArray

          byte[] asByteArray(CharSequence text)
                      throws IOException

      Convert the specified text into a UTF-8 encoded `byte[]` array.
      Parameters:
        `text` - The text to be converted
      Returns:
        byte[] buffer containing the UTF-8 representation of the text
      Throws:
        `IOException` - if an error occurs while reading the stream

    - #### asByteArray

          byte[] asByteArray(ReadableByteChannel r)
                      throws IOException

      Buffer the contents of the specified `ReadableByteChannel` into a `byte[]` array
      Parameters:
        `r` - The byte channel
      Returns:
        byte[] buffer containing the entire contents of the stream
      Throws:
        `IOException` - if an error occurs while reading the stream

Copyright © 2010, 2022, Oracle and/or its affiliates.