Class SeekableInMemoryByteChannel

java.lang.Object
org.apache.commons.compress.utils.SeekableInMemoryByteChannel
All Implemented Interfaces:
Closeable, AutoCloseable, ByteChannel, Channel, ReadableByteChannel, SeekableByteChannel, WritableByteChannel

public class SeekableInMemoryByteChannel extends Object implements SeekableByteChannel
A SeekableByteChannel implementation that wraps a byte[].

When this channel is used for writing an internal buffer grows to accommodate incoming data. The natural size limit is the value of Integer.MAX_VALUE and it is not possible to set the position or truncate to a value bigger than that. Internal buffer can be accessed via array().

Since:
1.13
  • Field Details

    • NAIVE_RESIZE_LIMIT

      private static final int NAIVE_RESIZE_LIMIT
      See Also:
    • data

      private byte[] data
    • closed

      private final AtomicBoolean closed
    • position

      private int position
    • size

      private int size
  • Constructor Details

    • SeekableInMemoryByteChannel

      public SeekableInMemoryByteChannel(byte[] data)
      Constructor taking a byte array.

      This constructor is intended to be used with pre-allocated buffer or when reading from a given byte array.

      Parameters:
      data - input data or pre-allocated array.
    • SeekableInMemoryByteChannel

      public SeekableInMemoryByteChannel()
      Parameterless constructor - allocates internal buffer by itself.
    • SeekableInMemoryByteChannel

      public SeekableInMemoryByteChannel(int size)
      Constructor taking a size of storage to be allocated.

      Creates a channel and allocates internal storage of a given size.

      Parameters:
      size - size of internal buffer to allocate, in bytes.
  • Method Details