org.mycore.datamodel.ifs
Class MCRContentInputStream

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

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: 13085 $ $Date: 2008-02-06 18:27:24 +0100 (Mi, 06 Feb 2008) $
Author:
Frank Lützenkirchen

Field Summary
protected  MessageDigest digest
          The MD5 checksum of all bytes read through this stream
protected  byte[] header
          The header of the file read
protected static int headerSize
          The number of bytes that will be read for content type detection
protected  long length
          The total number of bytes read so far
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
MCRContentInputStream(InputStream in)
          Constructs a new MCRContentInputStream
 
Method Summary
static MessageDigest buildMD5Digest()
          Builds a MessageDigest instance for MD5 checksum computation.
 byte[] getHeader()
          Returns the first 64 k of the underlying input stream.
 long getLength()
          Returns the number of bytes read so far
 byte[] getMD5()
          Returns the MD5 message digest that has been built during reading of the underlying input stream.
 String getMD5String()
          Returns the MD5 checksum as a String
static String getMD5String(MessageDigest digest)
          Given an MD5 message digest, returns the MD5 checksum as a String
 int read()
           
 int read(byte[] buf, int off, int len)
           
 
Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

headerSize

protected static final int headerSize
The number of bytes that will be read for content type detection

See Also:
Constant Field Values

digest

protected MessageDigest digest
The MD5 checksum of all bytes read through this stream


length

protected long length
The total number of bytes read so far


header

protected byte[] header
The header of the file read

Constructor Detail

MCRContentInputStream

public MCRContentInputStream(InputStream in)
                      throws MCRException
Constructs a new MCRContentInputStream

Parameters:
in - the InputStream to read from
Throws:
MCRConfigurationException - if java classes supporting MD5 checksums are not found
MCRException
Method Detail

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(MessageDigest digest)
Given an MD5 message digest, returns the MD5 checksum as a String

Returns:
the MD5 checksum as a String of hex digits

buildMD5Digest

public static MessageDigest buildMD5Digest()
Builds a MessageDigest instance for MD5 checksum computation.

Throws:
MCRConfigurationException - if no java classes that support MD5 algorithm could be found