This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git
The following commit(s) were added to refs/heads/master by this push: new 084d453fd Javadoc 084d453fd is described below commit 084d453fdc4841002bcd6b57bb87bc8f3b7c1f90 Author: Gary D. Gregory <garydgreg...@gmail.com> AuthorDate: Sun Sep 21 10:17:19 2025 -0400 Javadoc --- .../utils/SeekableInMemoryByteChannel.java | 43 ++++------------------ 1 file changed, 8 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannel.java b/src/main/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannel.java index 9119d1850..7055f6bbf 100644 --- a/src/main/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannel.java +++ b/src/main/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannel.java @@ -29,11 +29,14 @@ import org.apache.commons.lang3.ArrayUtils; /** - * A {@link SeekableByteChannel} implementation that wraps a byte[]. + * A {@link SeekableByteChannel} implementation that wraps a byte array. * <p> - * When this channel is used for writing an internal buffer grows to accommodate incoming data. The natural size limit is the value of {@link Integer#MAX_VALUE} - * and it is not possible to {@link #position(long) set the position} or {@link #truncate truncate} to a value bigger than that. Internal buffer can be accessed - * via {@link SeekableInMemoryByteChannel#array()}. + * When this channel is used for writing, an internal buffer grows to accommodate incoming data. The natural size limit is the value of + * {@link Integer#MAX_VALUE} and it is not possible to {@link #position(long) set the position} or {@link #truncate truncate} to a value bigger than that. The + * raw internal buffer is accessed via {@link SeekableInMemoryByteChannel#array()}. + * </p> + * <p> + * This class never throws {@link ClosedChannelException} because a byte array is not a resource you open or close. * </p> * * @since 1.13 @@ -42,7 +45,6 @@ public class SeekableInMemoryByteChannel implements SeekableByteChannel { private static final int NAIVE_RESIZE_LIMIT = Integer.MAX_VALUE >> 1; - private byte[] data; private final AtomicBoolean closed = new AtomicBoolean(); private int position; @@ -57,9 +59,6 @@ public SeekableInMemoryByteChannel() { /** * Constructs a new instance from a byte array. - * <p> - * This constructor is intended to be used with pre-allocated buffer or when reading from a given byte array. - * </p> * * @param data input data or pre-allocated array. */ @@ -70,9 +69,6 @@ public SeekableInMemoryByteChannel(final byte[] data) { /** * Constructs a new instance from a size of storage to be allocated. - * <p> - * Creates a channel and allocates internal storage of a given size. - * </p> * * @param size size of internal buffer to allocate, in bytes. */ @@ -81,7 +77,7 @@ public SeekableInMemoryByteChannel(final int size) { } /** - * Obtains the array backing this channel. + * Gets the raw byte array backing this channel, <em>this is not a copy</em>. * <p> * NOTE: The returned buffer is not aligned with containing data, use {@link #size()} to obtain the size of data stored in the buffer. * </p> @@ -108,13 +104,6 @@ public boolean isOpen() { return !closed.get(); } - /** - * Returns this channel's position. - * <p> - * This method violates the contract of {@link SeekableByteChannel#position()} as it will not throw any exception when invoked on a closed channel. - * Instead, it will return the position the channel had when close has been called. - * </p> - */ @Override public long position() { return position; @@ -161,26 +150,11 @@ private void resize(final int newLength) { data = Arrays.copyOf(data, len); } - /** - * Returns the current size of entity to which this channel is connected. - * <p> - * This method violates the contract of {@link SeekableByteChannel#size} as it will not throw any exception when invoked on a closed channel. - * Instead, it will return the size the channel had when close has been called. - * </p> - */ @Override public long size() { return size; } - /** - * Truncates the entity, to which this channel is connected, to the given size. - * <p> - * This method violates the contract of {@link SeekableByteChannel#truncate} as it will not throw any exception when invoked on a closed channel. - * </p> - * - * @throws IllegalArgumentException if size is negative or bigger than the maximum of a Java integer - */ @Override public SeekableByteChannel truncate(final long newSize) { if (newSize < 0L || newSize > Integer.MAX_VALUE) { @@ -216,5 +190,4 @@ public int write(final ByteBuffer b) throws IOException { } return wanted; } - }