This is an automated email from the ASF dual-hosted git repository. kwin pushed a commit to branch feature/put-task-exposing-byte-channel in repository https://gitbox.apache.org/repos/asf/maven-resolver.git
commit a4d3551de0d384fa998400e263ab78bae1a61997 Author: Konrad Windszus <[email protected]> AuthorDate: Thu Jan 15 14:53:03 2026 +0100 Expose SeekableByteChannel from PutTask This closes #1751 --- maven-resolver-spi/pom.xml | 5 +++++ .../aether/spi/connector/transport/PutTask.java | 25 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/maven-resolver-spi/pom.xml b/maven-resolver-spi/pom.xml index 6509a2d0a..b3cf756c5 100644 --- a/maven-resolver-spi/pom.xml +++ b/maven-resolver-spi/pom.xml @@ -47,6 +47,11 @@ <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.21.0</version> + </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> diff --git a/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/transport/PutTask.java b/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/transport/PutTask.java index 549f5a932..c56d0ad88 100644 --- a/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/transport/PutTask.java +++ b/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/transport/PutTask.java @@ -24,9 +24,13 @@ import java.io.IOException; import java.io.InputStream; import java.io.UncheckedIOException; import java.net.URI; +import java.nio.channels.SeekableByteChannel; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.StandardOpenOption; + +import org.apache.commons.io.channels.ByteArraySeekableByteChannel; /** * A task to upload a resource to the remote repository. @@ -54,7 +58,9 @@ public final class PutTask extends TransportTask { * * @return The input stream for the data, never {@code null}. The stream is unbuffered. * @throws IOException If the stream could not be opened. + * @deprecated Use {@link #newByteChannel()} instead. */ + @Deprecated public InputStream newInputStream() throws IOException { if (dataPath != null) { return Files.newInputStream(dataPath); @@ -62,6 +68,23 @@ public final class PutTask extends TransportTask { return new ByteArrayInputStream(dataBytes); } + /** + * Opens a seekable byte channel for the data to be uploaded. The length of the channel can be queried via + * {@link #getDataLength()}. It's the responsibility of the caller to close the provided channel. + * Write operations on the returned channel will throw {@link java.nio.channels.NonWritableChannelException}. + * + * @return The seekable byte channel for the data, never {@code null}. + * @throws IOException If the channel could not be opened. + * @since 2.1.0 + * @see #getInputStream() + */ + public SeekableByteChannel newByteChannel() throws IOException { + if (dataPath != null) { + return Files.newByteChannel(dataPath, StandardOpenOption.READ); + } + return ByteArraySeekableByteChannel.wrap(dataBytes); + } + /** * Gets the total number of bytes to be uploaded. * @@ -94,7 +117,9 @@ public final class PutTask extends TransportTask { * * @return The data file or {@code null} if the data resides in memory. * @since 2.0.0 + * @deprecated Use {@link #newByteChannel()} instead. */ + @Deprecated public Path getDataPath() { return dataPath; }
