Class CancellableDigestOutputStream

java.lang.Object
java.io.OutputStream
org.eclipse.jgit.internal.storage.io.CancellableDigestOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
Direct Known Subclasses:
PackOutputStream

public class CancellableDigestOutputStream extends OutputStream
An OutputStream that keeps a digest and checks every N bytes for cancellation.
  • Field Details

    • BYTES_TO_WRITE_BEFORE_CANCEL_CHECK

      public static final int BYTES_TO_WRITE_BEFORE_CANCEL_CHECK
      The OutputStream checks every this value for cancellation
      See Also:
    • writeMonitor

      private final ProgressMonitor writeMonitor
    • out

      private final OutputStream out
    • md

      private final MessageDigest md
    • count

      private long count
    • checkCancelAt

      private long checkCancelAt
  • Constructor Details

    • CancellableDigestOutputStream

      public CancellableDigestOutputStream(ProgressMonitor writeMonitor, OutputStream out)
      Initialize a CancellableDigestOutputStream.
      Parameters:
      writeMonitor - monitor to update on output progress and check cancel.
      out - target stream to receive all contents.
  • Method Details

    • getWriteMonitor

      public final ProgressMonitor getWriteMonitor()
      Get the monitor which is used to update on output progress and check cancel.
      Returns:
      the monitor
    • getDigest

      public final byte[] getDigest()
      Obtain the current SHA-1 digest.
      Returns:
      SHA-1 digest
    • length

      public final long length()
      Get total number of bytes written since stream start.
      Returns:
      total number of bytes written since stream start.
    • write

      public final void write(int b) throws IOException
      Specified by:
      write in class OutputStream
      Throws:
      IOException
    • write

      public final void write(byte[] b, int off, int len) throws IOException
      Overrides:
      write in class OutputStream
      Throws:
      IOException
    • flush

      public void flush() throws IOException
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class OutputStream
      Throws:
      IOException