Package org.apache.commons.io.channels

# Class CloseShieldChannel

java.lang.Object
org.apache.commons.io.channels.CloseShieldChannel

public final class CloseShieldChannel extends Object
Creates a close-shielding proxy for a `Channel`.

The returned proxy implements all `Channel` sub-interfaces that are both supported by this implementation and actually implemented by the given delegate.

The following interfaces are supported:

- `AsynchronousChannel`
- `ByteChannel`
- `Channel`
- `GatheringByteChannel`
- `InterruptibleChannel`
- `NetworkChannel`
- `ReadableByteChannel`
- `ScatteringByteChannel`
- `SeekableByteChannel`
- `WritableByteChannel`

Since:
  2.21.0
See Also:
  - `Channel`
  - `Closeable`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static <T extends Channel>
  T`
  `wrap(T channel)`
  Wraps a channel to shield it from being closed.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### wrap

    public static <T extends Channel> T wrap(T channel)
    Wraps a channel to shield it from being closed.
    Type Parameters:
      `T` - A supported channel type.
    Parameters:
      `channel` - The underlying channel to shield, not `null`.
    Returns:
      A proxy that shields `close()` and enforces closed semantics on other calls.
    Throws:
      `ClassCastException` - if `T` is not a supported channel type.
      `NullPointerException` - if `channel` is `null`.