Skip to content

Commit 8080c7c

Browse files
authored
Add NIO channel support to AbstractStreamBuilder (#784)
* feat: add NIO channel support to `AbstractStreamBuilder` Some builders derived from `AbstractStreamBuilder` (for example, `SevenZFile.Builder` in Commons Compress) need to produce a `SeekableByteChannel` as their data source. Until now this required ad-hoc `instanceof` switches across different origin types. This change integrates channel support directly into the origin/builder abstraction, leading to a cleaner and more object-oriented design. ### Key changes * Add `getReadableByteChannel()` and `getWritableByteChannel()` to `AbstractOrigin` and propagate to `AbstractStreamBuilder`. * Introduce `ChannelOrigin`, an `AbstractOrigin` implementation backed by an existing `ReadableByteChannel`/`WritableByteChannel`. * Add `ByteArrayChannel`, a simple in-memory `SeekableByteChannel` implementation. * Extend unit tests to cover the new methods and types. * fix: cleanup on Windows * fix: checkstyle violation * fix: merge `ByteArrayChannel` and `ByteArraySeekableByteChannel` * fix: failing test * fix: remove irrelevant changes * fix: changelog * fix: make `data` private * fix: refine `ByteArraySeekableByteChannel` Javadoc Clarifies the Javadoc to better reflect the intended usage patterns: * `wrap(byte[])` is modeled after `ByteArrayInputStream` and is primarily for read-oriented use. * The public constructors `ByteArraySeekableByteChannel()` and `ByteArraySeekableByteChannel(int)` follow the pattern of `ByteArrayOutputStream` and are mainly suited for write-oriented use. * fix: add missing `@Override` annotation * fix: typo in default size value * feat: add generic `getChannel(Class<C>)` accessor Adds a type-safe `getChannel(Class<C>)` method that lets callers request any supported `Channel` subtype (e.g. `ReadableByteChannel`, `WritableByteChannel`, `SeekableByteChannel`) through a single entry point. * fix: rename `doGetChannel` to `getChannel` * fix: Javadoc * fix: default capacity of `ByteArraySeekableByteChannel` * fix: rename `getTestData` to `cloneTestData` * docs: minimum channel type by origin * fix: make `getChannel` final * fix: don't clone `testData` Cloning the test data is unnecessary as all but one test are not supposed to modify them. * fix: test order
1 parent 2b755f3 commit 8080c7c

22 files changed

+1085
-77
lines changed

src/changes/changes.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ The <action> type attribute can be add,update,fix,remove.
6363
<action dev="ggregory" type="add" due-to="Gary Gregory">Add org.apache.commons.io.output.ProxyOutputStream.writeRepeat(int, long).</action>
6464
<action dev="pkarwasz" type="add" due-to="Piotr P. Karwasz">Add length unit support in FileSystem limits.</action>
6565
<action dev="pkarwasz" type="add" due-to="Piotr P. Karwasz">Add IOUtils.toByteArray(InputStream, int, int) for safer chunked reading with size validation.</action>
66-
<action dev="pkarwasz" type="add" due-to="Piotr P. Karwasz">Add org.apache.commons.io.file.PathUtils.getPath(String, String).</action>
66+
<action dev="ggregory" type="add" due-to="Gary Gregory">Add org.apache.commons.io.file.PathUtils.getPath(String, String).</action>
6767
<action dev="ggregory" type="add" due-to="Gary Gregory">Add org.apache.commons.io.channels.ByteArraySeekableByteChannel.</action>
6868
<action dev="ggregory" type="add" due-to="Gary Gregory">Add IOIterable.asIterable().</action>
69+
<action dev="pkarwasz" type="add" due-to="Piotr P. Karwasz">Add NIO channel support to `AbstractStreamBuilder`.</action>
6970
<action dev="pkarwasz" type="add" due-to="Piotr P. Karwasz">Add CloseShieldChannel to close-shielded NIO Channels #786.</action>
7071
<!-- UPDATE -->
7172
<action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump org.apache.commons:commons-parent from 85 to 88 #774, #783.</action>

0 commit comments

Comments
 (0)