kwin commented on code in PR #1748:
URL: https://github.com/apache/maven-resolver/pull/1748#discussion_r2687764933
##########
maven-resolver-transport-jetty/src/main/java/org/eclipse/aether/transport/jetty/PutTaskRequestContent.java:
##########
@@ -18,118 +18,260 @@
*/
package org.eclipse.aether.transport.jetty;
-import java.io.EOFException;
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.nio.channels.ByteChannel;
import java.nio.channels.Channels;
+import java.nio.channels.ClosedChannelException;
import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.SeekableByteChannel;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
+import java.util.Objects;
import org.eclipse.aether.spi.connector.transport.PutTask;
-import org.eclipse.jetty.client.util.AbstractRequestContent;
+import org.eclipse.jetty.client.ByteBufferRequestContent;
+import org.eclipse.jetty.client.Request;
import org.eclipse.jetty.io.ByteBufferPool;
+import org.eclipse.jetty.io.Content;
+import org.eclipse.jetty.io.RetainableByteBuffer;
+import org.eclipse.jetty.io.internal.ByteChannelContentSource;
import org.eclipse.jetty.util.BufferUtil;
-import org.eclipse.jetty.util.Callback;
+import org.eclipse.jetty.util.ExceptionUtil;
import org.eclipse.jetty.util.IO;
+import org.eclipse.jetty.util.TypeUtil;
+import org.eclipse.jetty.util.thread.AutoLock;
+import org.eclipse.jetty.util.thread.SerializedInvoker;
-class PutTaskRequestContent extends AbstractRequestContent {
- private final PutTask putTask;
- private final int bufferSize;
- private ByteBufferPool bufferPool;
- private boolean useDirectByteBuffers = true;
+/**
+ * Heavily inspired by Jetty's
org.eclipse.jetty.io.internal.ByteChannelContentSource but adjusted to deal with
+ * ReadableByteChannels.
+ * Also Jetty's ByteChannelContentSource is an internal package so should not
be used directly.
+ */
+public class PutTaskRequestContent extends ByteBufferRequestContent implements
Request.Content {
- PutTaskRequestContent(PutTask putTask) {
- this(putTask, 4096);
+ public static Request.Content from(PutTask putTask) throws IOException {
+ ReadableByteChannel channel;
+ if (putTask.getDataPath() != null) {
+ channel = Files.newByteChannel(putTask.getDataPath(),
StandardOpenOption.READ);
+ } else {
+ // TODO: support rewind for retries when using InputStream
Review Comment:
Came up with a simpler solution based on `Supplier<ReadableByteChannel>` in
https://github.com/apache/maven-resolver/pull/1748/commits/82f6bda5b7f7a3e94cfbb924b8d681b201899699.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]