Skip to content

io7m-com/wendover

Repository files navigation

wendover

Maven Central Maven Central (snapshot) Codecov Java Version

com.io7m.wendover

JVM Platform Status
OpenJDK (Temurin) Current Linux Build (OpenJDK (Temurin) Current, Linux)
OpenJDK (Temurin) LTS Linux Build (OpenJDK (Temurin) LTS, Linux)
OpenJDK (Temurin) Current Windows Build (OpenJDK (Temurin) Current, Windows)
OpenJDK (Temurin) LTS Windows Build (OpenJDK (Temurin) LTS, Windows)

wendover

The wendover package provides extra classes for working with Java NIO channels.

Features

  • Numerous Channel classes and adapters with various properties.
  • High coverage test suite.
  • OSGi-ready.
  • JPMS-ready.
  • ISC license.

Usage

CloseShieldSeekableByteChannel

Use CloseShieldSeekableByteChannel in order to prevent external code from closing an arbitrary SeekableByteChannel instance:

SeekableByteChannel c;

someUntrustedObject.run(new CloseShieldSeekableByteChannel(c));

The CloseShieldSeekableByteChannel instance can be closed, but will not result in the underlying channel really being closed.

ReadOnlySeekableByteChannel

Use ReadOnlySeekableByteChannel to protect an arbitrary SeekableByteChannel instance against writes:

SeekableByteChannel c;

someUntrustedObject.run(new ReadOnlySeekableByteChannel(c));

Attempts to write to the ReadOnlySeekableByteChannel will result in NonWritableChannelException being thrown.

SubrangeSeekableByteChannel

Use SubrangeSeekableByteChannel to restrict reads and writes to an arbitrary SeekableByteChannel instance to a particular range:

SeekableByteChannel c;

someObject.run(new SubrangeSeekableByteChannel(c, 100L, 1000L));

Reads of the SubrangeSeekableByteChannel instance will be limited to only reading data that falls within offsets [100, 100 + 1000 - 1]. Reading at position 0 of the SubrangeSeekableByteChannel instance will actually read from position 100 of c. Writes are similarly translated and limited.

UpperRangeTrackingSeekableByteChannel

Use UpperRangeTrackingSeekableByteChannel to track the uppermost point written by an arbitrary SeekableByteChannel instance:

SeekableByteChannel c;

var d = new UpperRangeTrackingSeekableByteChannel(c);

someObject.run(d);

System.out.println(d.uppermostWritten());

ByteBufferChannels

Use the ByteBufferChannels class to adapt a ByteBuffer into a SeekableByteChannel:

ByteBuffer data;

SeekableByteChannel c = ByteBufferChannels.ofByteBuffer(data);

DelegatingSeekableByteChannel

Use the DelegatingSeekableByteChannel class to delegate operations to an existing channel. This class is used to implement most of the wendover package.