Class TimestampedObserver

java.lang.Object
org.apache.commons.io.input.ObservableInputStream.Observer
org.apache.commons.io.input.TimestampedObserver

public class TimestampedObserver extends ObservableInputStream.Observer
An observer with timestamps.

For example:

 final TimestampedObserver timetampedObserver = new TimestampedObserver();
 try (final ObservableInputStream inputStream = new ObservableInputStream(...),
     timetampedObserver)) {
     ...
 }
 System.out.printf("IO duration: %s%n", timetampedObserver.getOpenToCloseDuration());
 
Since:
2.9.0
  • Field Details

    • closeInstant

      private volatile Instant closeInstant
    • openInstant

      private final Instant openInstant
  • Constructor Details

    • TimestampedObserver

      public TimestampedObserver()
  • Method Details

    • closed

      public void closed() throws IOException
      Description copied from class: ObservableInputStream.Observer
      Called to indicate that the ObservableInputStream has been closed.
      Overrides:
      closed in class ObservableInputStream.Observer
      Throws:
      IOException - if an I/O error occurs.
    • getCloseInstant

      public Instant getCloseInstant()
      Gets the instant for when this instance was closed.
      Returns:
      the instant for when closed was called.
    • getOpenToCloseDuration

      public Duration getOpenToCloseDuration()
      Gets the Duration between creation and close.
      Returns:
      the Duration between creation and close.
    • getOpenToNowDuration

      public Duration getOpenToNowDuration()
      Gets the Duration between creation and now.
      Returns:
      the Duration between creation and now.
    • getOpenInstant

      public Instant getOpenInstant()
      Gets the instant for when this instance was created.
      Returns:
      the instant for when this instance was created.
    • toString

      public String toString()
      Overrides:
      toString in class Object