Skip to content

io7m-com/streamtime

Repository files navigation

streamtime

Maven Central Maven Central (snapshot) Codecov Java Version

com.io7m.streamtime

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)

streamtime

The streamtime package provides a simple extension to Java I/O streams that can track transfer rates and provide statistics.

Features

  • Input and output stream implementations that track and regularly broadcast transfer statistics.
  • High coverage test suite.
  • OSGi-ready.
  • JPMS-ready.
  • ISC license.

Usage

Create a STTimedInputStream from an existing InputStream, and provide it with a Consumer<STTransferStatistics> function that receives transfer updates:

InputStream is;
Consumer<STTransferStatistics> f;

try (var input = new STTimedInputStream(f, is)) {
  input.transferTo(...);
}

The f function will be called at a rate of roughly once per second, with a new value of type STTransferStatistics describing the expected number of octets, the current number of octets, and the current number of octets received per second.

The STTimedOutputStream class works similarly, but for OutputStream values.