Class MD5InputStream

All Implemented Interfaces:
Closeable, AutoCloseable

public class MD5InputStream extends DigestInputStream
MD5InputStream, a subclass of FilterInputStream implementing MD5 functionality on a stream.
Author:
Tony Chemit - chemit@codelutin.com
  • Field Details

    • streamLength

      protected long streamLength
      length of readed stream
  • Constructor Details

    • MD5InputStream

      public MD5InputStream(InputStream in)
      Creates a MD5InputStream
      Parameters:
      in - The input stream
  • Method Details

    • getMD5Digest

      protected static MessageDigest getMD5Digest() throws IllegalStateException
      Throws:
      IllegalStateException
    • hash

      public static byte[] hash(InputStream input) throws IOException
      Compute the MD5 for the given input. Note: The the stream will be closed after calling the method even if something was wrong.
      Parameters:
      input - the stream to parse
      Returns:
      the MD5 hash for the given input stream
      Throws:
      IOException - if any pb while reading in stream or digest
    • hash

      public static byte[] hash(File input) throws IOException
      Compute the MD5 for the given input file.
      Parameters:
      input - the File stream to parse
      Returns:
      the MD5 hash for the given input File
      Throws:
      IOException - if any pb while reading in stream or digest
    • hash

      public static byte[] hash(String input) throws IOException
      Compute the MD5 for the given input sring.
      Parameters:
      input - the stream to parse
      Returns:
      the MD5 hash for the given input String
      Throws:
      IOException - if any pb while reading in stream or digest
    • read

      public int read() throws IOException
      Overrides:
      read in class DigestInputStream
      Throws:
      IOException
    • read

      public int read(byte[] bytes, int offset, int length) throws IOException
      Overrides:
      read in class DigestInputStream
      Throws:
      IOException
    • hash

      public byte[] hash()
      Returns array of bytes representing hash of the stream as finalized for the current state.
      Returns:
      hash
      See Also:
    • getStreamLength

      public long getStreamLength()