Class MCRContentInputStream

java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.mycore.datamodel.ifs.MCRContentInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class MCRContentInputStream extends FilterInputStream
This input stream is used by the MyCoRe filesystem classes to read the content of a file and import it into the System. MCRContentInputStream provides the header of the file that is read (the first 64k) for content type detection purposes, counts the number of bytes read and builds an MD5 checksum String while content goes through this input stream.
Version:
$Revision$ $Date$
Author:
Frank Lützenkirchen
  • Field Details

    • HEADER_SIZE

      protected static final int HEADER_SIZE
      The number of bytes that will be read for content type detection
      See Also:
    • md5

      protected byte[] md5
      The MD5 checksum of all bytes read through this stream
    • digest

      protected MessageDigest digest
      The message digest to build the MD5 checksum
    • length

      protected long length
      The total number of bytes read so far
  • Constructor Details

  • Method Details

    • consume

      public int consume() throws IOException
      Throws:
      IOException
    • read

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

      public int read(byte[] buf, int off, int len) throws IOException
      Overrides:
      read in class FilterInputStream
      Throws:
      IOException
    • getHeader

      public byte[] getHeader()
      Returns the first 64 k of the underlying input stream. This is used for content type detection during file import into MyCoRe.
      Returns:
      the first 64 k of the input stream
    • getLength

      public long getLength()
      Returns the number of bytes read so far
      Returns:
      the number of bytes read
    • getMD5

      public byte[] getMD5()
      Returns the MD5 message digest that has been built during reading of the underlying input stream.
      Returns:
      the MD5 message digest checksum of all bytes that have been read
    • getMD5String

      public String getMD5String()
      Returns the MD5 checksum as a String
      Returns:
      the MD5 checksum as a String of hex digits
    • getMD5String

      public static String getMD5String(byte[] digest)
      Given an MD5 message digest, returns the MD5 checksum as a String
      Returns:
      the MD5 checksum as a String of hex digits