SharedByteArrayInputStream (JavaMail API documentation)
Date: 2018-05-06

javax.mail.util

## Class SharedByteArrayInputStream

- java.lang.Object
- - java.io.InputStream
  - - java.io.ByteArrayInputStream
    - - javax.mail.util.SharedByteArrayInputStream

- All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, SharedInputStream

      public class SharedByteArrayInputStream
      extends java.io.ByteArrayInputStream
      implements SharedInputStream

  A ByteArrayInputStream that implements the SharedInputStream interface, allowing the underlying byte array to be shared between multiple readers.
  Since:
    JavaMail 1.4

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected int` | `start` Position within shared buffer that this stream starts at.

    - ### Fields inherited from class java.io.ByteArrayInputStream

      `buf, count, mark, pos`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SharedByteArrayInputStream(byte[] buf)` Create a SharedByteArrayInputStream representing the entire byte array.
    `SharedByteArrayInputStream(byte[] buf, int offset, int length)` Create a SharedByteArrayInputStream representing the part of the byte array from `offset` for `length` bytes.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `long` | `getPosition()` Return the current position in the InputStream, as an offset from the beginning of the InputStream.
    `java.io.InputStream` | `newStream(long start, long end)` Return a new InputStream representing a subset of the data from this InputStream, starting at `start` (inclusive) up to `end` (exclusive).

    - ### Methods inherited from class java.io.ByteArrayInputStream

      `available, close, mark, markSupported, read, read, reset, skip`

    - ### Methods inherited from class java.io.InputStream

      `read`

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

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

- - ### Field Detail

    - #### start

          protected int start

      Position within shared buffer that this stream starts at.

  - ### Constructor Detail

    - #### SharedByteArrayInputStream

          public SharedByteArrayInputStream(byte[] buf)

      Create a SharedByteArrayInputStream representing the entire byte array.
      Parameters:
        `buf` - the byte array

    - #### SharedByteArrayInputStream

          public SharedByteArrayInputStream(byte[] buf,
                                    int offset,
                                    int length)

      Create a SharedByteArrayInputStream representing the part of the byte array from `offset` for `length` bytes.
      Parameters:
        `buf` - the byte array
        `offset` - offset in byte array to first byte to include
        `length` - number of bytes to include

  - ### Method Detail

    - #### getPosition

          public long getPosition()

      Return the current position in the InputStream, as an offset from the beginning of the InputStream.
      Specified by:
        `getPosition` in interface `SharedInputStream`
      Returns:
        the current position

    - #### newStream

          public java.io.InputStream newStream(long start,
                                      long end)

      Return a new InputStream representing a subset of the data from this InputStream, starting at `start` (inclusive) up to `end` (exclusive). `start` must be non-negative. If `end` is -1, the new stream ends at the same place as this stream. The returned InputStream will also implement the SharedInputStream interface.
      Specified by:
        `newStream` in interface `SharedInputStream`
      Parameters:
        `start` - the starting position
        `end` - the ending position + 1
      Returns:
        the new stream

Copyright © 1996-2013, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms< /a>.