Package org.mycore.datamodel.ifs
Class MCRContentInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.mycore.datamodel.ifs.MCRContentInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
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 Summary
Modifier and TypeFieldDescriptionprotected MessageDigest
The message digest to build the MD5 checksumprotected byte[]
The header of the file readprotected static final int
The number of bytes that will be read for content type detectionprotected long
The total number of bytes read so farprotected byte[]
The MD5 checksum of all bytes read through this streamFields inherited from class java.io.FilterInputStream
in
-
Constructor Summary
ConstructorDescriptionConstructs a new MCRContentInputStream -
Method Summary
Modifier and TypeMethodDescriptionint
consume()
byte[]
Returns the first 64 k of the underlying input stream.long
Returns the number of bytes read so farbyte[]
getMD5()
Returns the MD5 message digest that has been built during reading of the underlying input stream.Returns the MD5 checksum as a Stringstatic String
getMD5String
(byte[] digest) Given an MD5 message digest, returns the MD5 checksum as a Stringint
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.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
HEADER_SIZE
protected static final int HEADER_SIZEThe number of bytes that will be read for content type detection- See Also:
-
md5
protected byte[] md5The MD5 checksum of all bytes read through this stream -
digest
The message digest to build the MD5 checksum -
length
protected long lengthThe total number of bytes read so far -
header
protected byte[] headerThe header of the file read
-
-
Constructor Details
-
MCRContentInputStream
Constructs a new MCRContentInputStream- Parameters:
in
- the InputStream to read from- Throws:
MCRConfigurationException
- if java classes supporting MD5 checksums are not foundMCRException
-
-
Method Details
-
consume
- Throws:
IOException
-
read
- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classFilterInputStream
- 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
Returns the MD5 checksum as a String- Returns:
- the MD5 checksum as a String of hex digits
-
getMD5String
Given an MD5 message digest, returns the MD5 checksum as a String- Returns:
- the MD5 checksum as a String of hex digits
-