ppkarwasz commented on code in PR #784:
URL: https://github.com/apache/commons-io/pull/784#discussion_r2371385660


##########
src/main/java/org/apache/commons/io/build/AbstractOrigin.java:
##########
@@ -755,6 +1120,28 @@ public Writer getWriter(final Charset charset, final 
OpenOption... options) thro
         return Files.newBufferedWriter(getPath(), Charsets.toCharset(charset), 
options);
     }
 
+    /**
+     * Gets this origin as a Channel, if possible.
+     *
+     * @param channelType The type of channel to return.
+     * @param options Options specifying how a file-based origin is opened, 
ignored otherwise.
+     * @return A new Channel on the origin of the given type.
+     * @param <C> The type of channel to return.
+     * @throws IOException                   If an I/O error occurs.
+     * @throws UnsupportedOperationException If this origin cannot be 
converted to a channel of the given type.
+     * @since 2.21.0
+     */
+    public <C extends Channel> C getChannel(Class<C> channelType, 
OpenOption... options) throws IOException {
+        Objects.requireNonNull(channelType, "channelType");
+        final Channel channel = doGetChannel(options);
+        if (channelType.isInstance(channel)) {
+            return channelType.cast(channel);
+        }
+        throw unsupportedChannelType(channelType);
+    }
+
+    abstract Channel doGetChannel(OpenOption... options) throws IOException;

Review Comment:
   I renamed it to `getChannel` and changed the access to `protected` in 
https://github.com/apache/commons-io/pull/784/commits/b820c4497cab67fe757234b550634e89477e1974.
 This will allow users to reuse the `getChannel(Class<?>, OpenOption...)` 
implementation above.
   
   In this case, should we make `getChannel(Class<?>, OpenOption...)` final?



-- 
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]

Reply via email to