Package edu.harvard.hul.ois.jhove
Class ModuleBase
java.lang.Object
edu.harvard.hul.ois.jhove.ModuleBase
- All Implemented Interfaces:
Module
- Direct Known Subclasses:
BytestreamModule
This class is an abstract implementation of the Module interface.
It contains all the methods required for a Module, but doesn't
do anything by itself. A subclass should provide a functional
implementation of
parse(InputStream, RepInfo, int)
if it is not random access, or parse(RandomAccessFile, RepInfo)
if it is random access.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AppThe application objectprotected booleanThe dominant "endianness" of the Module.protected booleanFlag indicating valid checksum information setprotected Checksummerprotected booleanFlag to indicate read routines should count the streamprotected StringCoverage informationprotected CRC32CRC32 calculated on content objectprotected ChecksumInputStreamprotected DateModule last modification dateList of default parameters.protected DataInputStreamThe list of supported features.protected String[]Formats recognized by this Moduleprotected StringInitialization value.protected booleanRandom access flagprotected JhoveBaseJHOVE engine.protected LoggerLogger for a module class.protected MessageDigestMD5 digest calculated on content objectprotected String[]MIME types supported by this Moduleprotected StringModule nameprotected longByte count of content objectprotected StringModule noteprotected StringModule-specific parameter.protected StringModule release descriptionprotected StringRepInfo noteprotected StringCopyright noticeprotected MessageDigestSHA-1 digest calculated on content objectprotected MessageDigestSHA-256 digest calculated on content objectModule Signature listModule specification document listprotected StringValidity criteriaprotected AgentModule vendorprotected intIndicator of how much data to reportprotected StringWell-formedness criteriaFields inherited from interface edu.harvard.hul.ois.jhove.Module
MAXIMUM_VERBOSITY, MINIMUM_VERBOSITY -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedModuleBase(String name, String release, int[] date, String[] format, String coverage, String[] mimeType, String wellFormedNote, String validityNote, String repInfoNote, String note, String rights, boolean isRandomAccess) Constructors of all subclasses of ModuleBase should call this as asuperconstructor. -
Method Summary
Modifier and TypeMethodDescriptionaddIntegerProperty(String name, int value, String[] labels) Returns a Property representing an integer value.addIntegerProperty(String name, int value, String[] labels, int[] index) Returns a Property representing an integer value.voidApplies the default parameters.protected voidcalcRAChecksum(Checksummer ckSummer, RandomAccessFile raf) Calculates the checksums for a module that uses a random access file.voidcheckSignatures(File file, InputStream stream, RepInfo info) Check if the digital object conforms to this Module's internal signature information.voidcheckSignatures(File file, RandomAccessFile raf, RepInfo info) Check if the digital object conforms to this Module's internal signature information.protected voidchecksumIfRafNotCopied(RepInfo info, RandomAccessFile raf) getApp()Returns the App object.getBase()Returns the JHOVE engine object.static DataInputStreamgetBufferedDataStream(InputStream stream, int size) A convenience method for getting a buffered DataInputStream from a module's InputStream.final StringReturn details as to the specific format versions or variants that are supported by this moduleprotected StringgetCRC32()Returns the hex string representation of the CRC32 result.final DategetDate()Return the last modification date of this Module, as a Java Date objectReturns the list of default parameters.Returns the full list of features.final String[]Return the array of format names supported by this Modulefinal String[]Return the array of MIME type strings for formats supported by this Modulefinal StringgetName()Return the module namelonggetNByte()Returns the value of _nByte.final StringgetNote()Return the module notefinal StringReturn the release identifierfinal StringReturn the RepInfo notefinal StringReturn the copyright information stringReturn the List of Signatures recognized by this ModuleReturns a list ofDocumentobjects (one for each specification document of the format).final StringReturn the string describing validity criteriafinal AgentReturn the vendor informationfinal StringReturn the string describing well-formedness criteriabooleanhasFeature(String feature) Returnstrueif the module supports a given named feature, andfalseif the feature is unsupported or unknown.voidPer-instantiation initialization.voidInitializes the feature list.protected voidprotected voidInitializes the state of the module for parsing.booleanReturnstrueif the dominant "endianness" of the module, or the current file being processed, is big-endian, otherwise false.protected booleanisParamInDefaults(String paramVal) final booleanReturn the random access flag (true if the module operates on random access files, false if it operates on streams)voidPer-action initialization.intparse(InputStream stream, RepInfo info, int parseIndex) Parse the content of a stream digital object and store the results in RepInfo.voidparse(RandomAccessFile file, RepInfo info) Parse the content of a random access digital object and store the results in RepInfo.static intreadByteBuf(DataInputStream stream, byte[] buf, ModuleBase counted) Reads into a byte buffer from a DataInputStream.static doublereadDouble(DataInputStream stream, boolean endian) static doublereadDouble(DataInputStream stream, boolean endian, ModuleBase counted) static doublereadDouble(RandomAccessFile file, boolean endian) static floatreadFloat(DataInputStream stream, boolean endian, ModuleBase counted) static floatreadFloat(RandomAccessFile file, boolean endian) static intreadSignedByte(DataInputStream stream) static intreadSignedByte(DataInputStream stream, ModuleBase counted) static intstatic intreadSignedInt(DataInputStream stream, boolean endian) static intreadSignedInt(DataInputStream stream, boolean endian, ModuleBase counted) static intreadSignedInt(RandomAccessFile file, boolean endian) static longreadSignedLong(DataInputStream stream, boolean bigEndian, ModuleBase counted) Reads eight bytes as a signed 64-bit value from a DataInputStream.static RationalreadSignedRational(DataInputStream stream, boolean endian, ModuleBase counted) static RationalreadSignedRational(RandomAccessFile file, boolean endian) static intreadSignedShort(DataInputStream stream, boolean endian) static intreadSignedShort(DataInputStream stream, boolean endian, ModuleBase counted) static intreadSignedShort(RandomAccessFile file, boolean endian) static intreadUnsignedByte(DataInputStream stream) Reads an unsigned byte from a DataInputStream.static intreadUnsignedByte(DataInputStream stream, ModuleBase counted) Reads an unsigned byte from a DataInputStream.static intReads an unsigned byte from a RandomAccessFile.static longreadUnsignedInt(DataInputStream stream, boolean bigEndian) Reads four bytes as an unsigned 32-bit value from a DataInputStream.static longreadUnsignedInt(DataInputStream stream, boolean bigEndian, ModuleBase counted) Reads four bytes as an unsigned 32-bit value from a DataInputStream.static longreadUnsignedInt(RandomAccessFile file, boolean bigEndian) Reads four bytes as an unsigned 32-bit value from a RandomAccessFile.static RationalreadUnsignedRational(DataInputStream stream, boolean endian) static RationalreadUnsignedRational(DataInputStream stream, boolean endian, ModuleBase counted) static RationalreadUnsignedRational(RandomAccessFile file, boolean endian) static intreadUnsignedShort(DataInputStream stream, boolean bigEndian) Reads two bytes as an unsigned short value from a DataInputStream.static intreadUnsignedShort(DataInputStream stream, boolean bigEndian, ModuleBase counted) Reads two bytes as an unsigned short value from a DataInputStream.static intreadUnsignedShort(RandomAccessFile file, boolean bigEndian) Reads two bytes as an unsigned short value from a RandomAccessFile.voidReset parameter settings.final voidPass the associated App object to this Module.final voidPass the JHOVE engine object to this Module.protected static voidsetChecksums(Checksummer ckSummer, RepInfo info) Set the checksum values.final voidSet the value of the CRC32 calculated for the content object.voidsetDefaultParams(List<String> params) Set a a List of default parameters for the module.final voidsetMD5(MessageDigest md5) Sets the MD5 calculated digest for the content object, and sets the checksumFinished flag.final voidsetNByte(long nByte) Sets the byte count for the content object, and sets the checksumFinished flag.final voidsetSHA1(MessageDigest sha1) Sets the SHA-1 calculated digest for the content object, and sets the checksumFinished flag.final voidsetSHA256(MessageDigest sha256) Sets the SHA-256 calculated digest for the content object, and sets the checksumFinished flag.protected voidsetupDataStream(InputStream stream, RepInfo info) final voidsetValidityNote(String validityNote) Set the value of the validityNote property, which briefly explains the validity criteria of this Module.voidsetVerbosity(int verbosity) Set the degree of verbosity desired from the module.voidshow(OutputHandler handler) Generates information about this Module.longskipBytes(DataInputStream stream, long bytesToSkip) Skip over some bytes.longskipBytes(DataInputStream stream, long bytesToSkip, ModuleBase counted) Skip over some bytes.protected voidskipDstreamToEnd(RepInfo info) protected Property[]vectorToPropArray(Vector vec) A utility for converting a Vector of Properties to an Array.
-
Field Details
-
_app
The application object -
_coverage
Coverage information -
_date
Module last modification date -
_format
Formats recognized by this Module -
_init
Initialization value. -
_defaultParams
List of default parameters. -
_je
JHOVE engine. -
_mimeType
MIME types supported by this Module -
_name
Module name -
_note
Module note -
_param
Module-specific parameter. -
_release
Module release description -
_repInfoNote
RepInfo note -
_rights
Copyright notice -
_signature
Module Signature list -
_specification
Module specification document list -
_vendor
Module vendor -
_wellFormedNote
Well-formedness criteria -
_validityNote
Validity criteria -
_isRandomAccess
protected boolean _isRandomAccessRandom access flag -
_nByte
protected long _nByteByte count of content object -
_crc32
CRC32 calculated on content object -
_md5
MD5 digest calculated on content object -
_sha1
SHA-1 digest calculated on content object -
_sha256
SHA-256 digest calculated on content object -
_checksumFinished
protected boolean _checksumFinishedFlag indicating valid checksum information set -
_verbosity
protected int _verbosityIndicator of how much data to report -
_countStream
protected boolean _countStreamFlag to indicate read routines should count the stream -
_bigEndian
protected boolean _bigEndianThe dominant "endianness" of the Module. -
_features
The list of supported features. -
_logger
Logger for a module class. -
_ckSummer
-
_cstream
-
_dstream
-
-
Constructor Details
-
ModuleBase
protected ModuleBase(String name, String release, int[] date, String[] format, String coverage, String[] mimeType, String wellFormedNote, String validityNote, String repInfoNote, String note, String rights, boolean isRandomAccess) Constructors of all subclasses of ModuleBase should call this as asuperconstructor.- Parameters:
name- Name of the modulerelease- Release identifierdate- Last modification date of the module code, in the form of an array of three numbers.date[0]is the year,date[1]the month, anddate[2]the day.format- Array of format names supported by the modulecoverage- Details as to the specific format versions or variants that are supported by the modulemimeType- Array of MIME type strings for formats supported by the modulewellFormedNote- Brief explanation of what constitutes well-formed contentvalidityNote- Brief explanation of what constitutes valid contentrepInfoNote- Note pertaining to RepInfo (may be null)note- Additional information about the module (may be null)rights- Copyright notice for the moduleisRandomAccess-trueif the module treats content as random-access data,falseif it treats content as stream data
-
-
Method Details
-
initFeatures
public void initFeatures()Initializes the feature list. This method puts the following features in the list:- edu.harvard.hul.ois.canValidate
- edu.harvard.hul.ois.canIdentify
-
init
Per-instantiation initialization. The default method does nothing but save its parameter. -
setDefaultParams
Set a a List of default parameters for the module.- Specified by:
setDefaultParamsin interfaceModule- Parameters:
params- A List whose elements are Strings. May be empty.
-
applyDefaultParams
Applies the default parameters. Calling this clears any prior parameters.- Specified by:
applyDefaultParamsin interfaceModule- Throws:
Exception
-
resetParams
public void resetParams()Reset parameter settings. Returns to a default state without any parameters. The default method clears the saved parameter.- Specified by:
resetParamsin interfaceModule
-
param
Per-action initialization. May be called multiple times. The default method does nothing but save its parameter. -
getApp
Returns the App object. -
getBase
Returns the JHOVE engine object. -
getNByte
public long getNByte()Returns the value of _nByte. Meaningful only for modules that use a counted InputStream. -
isBigEndian
public boolean isBigEndian()Returnstrueif the dominant "endianness" of the module, or the current file being processed, is big-endian, otherwise false. This does not guarantee that all numbers in the module follow the dominant endianness, particularly as formats sometimes incorporate data stored in a previously defined format. For some formats, e.g., TIFF, the endianness depends on the file being processed. Every module must initialize the value of _bigEndian for this function, or else assign its value when parsing a file, to return a meaningful result. For some modules (e.g., ASCII, endianness has no meaning. -
getCoverage
Return details as to the specific format versions or variants that are supported by this module- Specified by:
getCoveragein interfaceModule
-
getDate
Return the last modification date of this Module, as a Java Date object -
getFormat
Return the array of format names supported by this Module -
getMimeType
Return the array of MIME type strings for formats supported by this Module- Specified by:
getMimeTypein interfaceModule
-
getName
Return the module name -
getNote
Return the module note -
getRelease
Return the release identifier- Specified by:
getReleasein interfaceModule
-
getRepInfoNote
Return the RepInfo note- Specified by:
getRepInfoNotein interfaceModule
-
getRights
Return the copyright information string -
getSignature
Return the List of Signatures recognized by this Module- Specified by:
getSignaturein interfaceModule
-
getSpecification
Returns a list ofDocumentobjects (one for each specification document of the format). The specification list is generated by the Module, and specifications cannot be added by callers.- Specified by:
getSpecificationin interfaceModule- See Also:
-
getVendor
Return the vendor information -
getWellFormedNote
Return the string describing well-formedness criteria- Specified by:
getWellFormedNotein interfaceModule
-
getValidityNote
Return the string describing validity criteria- Specified by:
getValidityNotein interfaceModule
-
isRandomAccess
public final boolean isRandomAccess()Return the random access flag (true if the module operates on random access files, false if it operates on streams)- Specified by:
isRandomAccessin interfaceModule
-
hasFeature
Returnstrueif the module supports a given named feature, andfalseif the feature is unsupported or unknown. Feature names are case sensitive. It is recommended that features be named using package nomenclature. The following features are, by default, supported by the modules developed by OIS:- edu.harvard.hul.ois.canValidate
- edu.harvard.hul.ois.canIdentify
- Specified by:
hasFeaturein interfaceModule
-
getFeatures
Returns the full list of features.- Specified by:
getFeaturesin interfaceModule
-
getDefaultParams
Returns the list of default parameters.- Specified by:
getDefaultParamsin interfaceModule
-
setApp
Pass the associated App object to this Module. The App makes various services available. -
setBase
Pass the JHOVE engine object to this Module. -
setValidityNote
Set the value of the validityNote property, which briefly explains the validity criteria of this Module. -
setCRC32
Set the value of the CRC32 calculated for the content object. The checksum-like functions can be set by the caller. Setting any of these creates the assumption that the calculation is already done, and sets the checksumFinished flag to inhibit recalculation. -
setVerbosity
public void setVerbosity(int verbosity) Set the degree of verbosity desired from the module. The setting ofparamcan override the verbosity setting. It does not affect whether raw data are reported or not, only which data are reported.- Specified by:
setVerbosityin interfaceModule- Parameters:
verbosity- The requested verbosity value. Recognized values are Module.MINIMUM_VERBOSITY and Module.MAXIMUM_VERBOSITY. The interpretation of the value depends on the module, and the module may choose not to use this setting. However, modules should treat MAXIMUM_VERBOSITY as a request for all the data available from the module.
-
setNByte
public final void setNByte(long nByte) Sets the byte count for the content object, and sets the checksumFinished flag. -
setMD5
Sets the MD5 calculated digest for the content object, and sets the checksumFinished flag. -
setSHA1
Sets the SHA-1 calculated digest for the content object, and sets the checksumFinished flag. -
setSHA256
Sets the SHA-256 calculated digest for the content object, and sets the checksumFinished flag. -
parse
Parse the content of a stream digital object and store the results in RepInfo. A given Module will normally override only one of the two parse methods; the default method does nothing.- Specified by:
parsein interfaceModule- Parameters:
stream- An InputStream, positioned at its beginning, which is generated from the object to be parsed. If multiple calls toparseare made on the basis of a nonzero value being returned, a new InputStream must be provided each time.info- A fresh (on the first call) RepInfo object which will be modified to reflect the results of the parsing If multiple calls toparseare made on the basis of a nonzero value being returned, the same RepInfo object should be passed with each call.parseIndex- Must be 0 in first call toparse. Ifparsereturns a nonzero value, it must be called again withparseIndexequal to that return value.- Throws:
IOException
-
parse
Parse the content of a random access digital object and store the results in RepInfo. A given Module will normally override only one of the two parse methods; the default method does nothing.- Specified by:
parsein interfaceModule- Parameters:
file- A RandomAccessFile, positioned at its beginning, which is generated from the object to be parsedinfo- A fresh RepInfo object which will be modified to reflect the results of the parsing- Throws:
IOException
-
checkSignatures
Check if the digital object conforms to this Module's internal signature information. This function checks the file against the list of predefined signatures for the module. If there are no predefined signatures, it calls parse with the arguments passed to it. Override this for modules that check digital signatures in some other way. Any module for which the signature may be located other than at the beginning of the file must override.- Specified by:
checkSignaturesin interfaceModule- Parameters:
file- A File object for the object being parsedstream- An InputStream, positioned at its beginning, which is generated from the object to be parsedinfo- A fresh RepInfo object which will be modified to reflect the results of the test- Throws:
IOException
-
checkSignatures
Check if the digital object conforms to this Module's internal signature information.- Specified by:
checkSignaturesin interfaceModule- Parameters:
file- A File object representing the object to be parsedraf- A RandomAccessFile, positioned at its beginning, which is generated from the object to be parsedinfo- A fresh RepInfo object which will be modified to reflect the results of the test- Throws:
IOException
-
initParse
protected void initParse()Initializes the state of the module for parsing. This should be called early in each module's parse() method. If a module overrides it to provide additional functionality, the module's initParse() should call super.initParse(). -
initInfo
-
calcRAChecksum
Calculates the checksums for a module that uses a random access file.- Throws:
IOException
-
setChecksums
Set the checksum values.- Parameters:
ckSummer- Checksummer objectinfo- RepInfo object
-
show
Generates information about this Module. The format of the output depends on the OutputHandler. -
getCRC32
Returns the hex string representation of the CRC32 result. -
addIntegerProperty
Returns a Property representing an integer value. If raw output is specified for the module, returns an INTEGER property, andlabelsandindexare unused. Otherwise, returns a STRING property, with the string being the element oflabelswhose index is the index ofvalueinindex. -
addIntegerProperty
Returns a Property representing an integer value. If raw output is specified for the module, returns an INTEGER property, andlabelsandindexare unused. Otherwise, returns a STRING property, with the string being the element oflabelswhose index isvalue. -
readUnsignedByte
Reads an unsigned byte from a DataInputStream.- Parameters:
stream- Stream to read- Throws:
IOException
-
readUnsignedByte
Reads an unsigned byte from a DataInputStream.- Parameters:
stream- Stream to readcounted- If non-null, module for which value of _nByte shall be incremented appropriately- Throws:
IOException
-
readUnsignedByte
Reads an unsigned byte from a RandomAccessFile.- Throws:
IOException
-
readByteBuf
public static int readByteBuf(DataInputStream stream, byte[] buf, ModuleBase counted) throws IOException Reads into a byte buffer from a DataInputStream.- Parameters:
stream- Stream to read frombuf- Byte buffer to fill upcounted- If non-null, module for which value of _nByte shall be incremented appropriately- Throws:
IOException
-
readUnsignedShort
Reads two bytes as an unsigned short value from a DataInputStream.- Parameters:
stream- The stream to read from.bigEndian- If true, interpret the first byte as the high byte, otherwise interpret the first byte as the low byte.- Throws:
IOException
-
readUnsignedShort
public static int readUnsignedShort(DataInputStream stream, boolean bigEndian, ModuleBase counted) throws IOException Reads two bytes as an unsigned short value from a DataInputStream.- Parameters:
stream- The stream to read from.bigEndian- If true, interpret the first byte as the high byte, otherwise interpret the first byte as the low byte.- Throws:
IOException
-
readUnsignedShort
Reads two bytes as an unsigned short value from a RandomAccessFile.- Parameters:
file- The file to read from.bigEndian- If true, interpret the first byte as the high byte, otherwise interpret the first byte as the low byte.- Throws:
IOException
-
readUnsignedInt
Reads four bytes as an unsigned 32-bit value from a DataInputStream.- Parameters:
stream- The stream to read from.bigEndian- If true, interpret the first byte as the high byte, otherwise interpret the first byte as the low byte.- Throws:
IOException
-
readUnsignedInt
public static long readUnsignedInt(DataInputStream stream, boolean bigEndian, ModuleBase counted) throws IOException Reads four bytes as an unsigned 32-bit value from a DataInputStream.- Parameters:
stream- The stream to read from.bigEndian- If true, interpret the first byte as the high byte, otherwise interpret the first byte as the low byte.- Throws:
IOException
-
readUnsignedInt
Reads four bytes as an unsigned 32-bit value from a RandomAccessFile.- Parameters:
file- The file to read from.bigEndian- If true, interpret the first byte as the high byte, otherwise interpret the first byte as the low byte.- Throws:
IOException
-
readSignedLong
public static long readSignedLong(DataInputStream stream, boolean bigEndian, ModuleBase counted) throws IOException Reads eight bytes as a signed 64-bit value from a DataInputStream.- Parameters:
stream- The stream to read from.bigEndian- If true, interpret the first byte as the high byte, otherwise interpret the first byte as the low byte.- Throws:
IOException
-
readUnsignedRational
public static Rational readUnsignedRational(DataInputStream stream, boolean endian) throws IOException - Throws:
IOException
-
readUnsignedRational
public static Rational readUnsignedRational(DataInputStream stream, boolean endian, ModuleBase counted) throws IOException - Throws:
IOException
-
readUnsignedRational
public static Rational readUnsignedRational(RandomAccessFile file, boolean endian) throws IOException - Throws:
IOException
-
readSignedRational
public static Rational readSignedRational(DataInputStream stream, boolean endian, ModuleBase counted) throws IOException - Throws:
IOException
-
readSignedRational
- Throws:
IOException
-
readSignedByte
- Throws:
IOException
-
readSignedShort
- Throws:
IOException
-
readSignedInt
- Throws:
IOException
-
readSignedByte
- Throws:
IOException
-
readSignedByte
- Throws:
IOException
-
readSignedShort
- Throws:
IOException
-
readSignedShort
public static int readSignedShort(DataInputStream stream, boolean endian, ModuleBase counted) throws IOException - Throws:
IOException
-
readSignedInt
- Throws:
IOException
-
readSignedInt
public static int readSignedInt(DataInputStream stream, boolean endian, ModuleBase counted) throws IOException - Throws:
IOException
-
readFloat
- Throws:
IOException
-
readFloat
public static float readFloat(DataInputStream stream, boolean endian, ModuleBase counted) throws IOException - Throws:
IOException
-
readDouble
- Throws:
IOException
-
readDouble
- Throws:
IOException
-
readDouble
public static double readDouble(DataInputStream stream, boolean endian, ModuleBase counted) throws IOException - Throws:
IOException
-
skipBytes
Skip over some bytes. Return number of bytes skipped.- Throws:
IOException
-
skipBytes
public long skipBytes(DataInputStream stream, long bytesToSkip, ModuleBase counted) throws IOException Skip over some bytes. Return number of bytes skipped.- Throws:
IOException
-
getBufferedDataStream
A convenience method for getting a buffered DataInputStream from a module's InputStream. If the size specified is 0 or less, the default buffer size is used. -
vectorToPropArray
A utility for converting a Vector of Properties to an Array. It can be simpler to build a Vector and then call VectorToPropArray than to allocate an array and drop all the Properites into the correct indices. All the members of the Vector must be of type Property, or a ClassCastException will be thrown. -
setupDataStream
-
checksumIfRafNotCopied
- Throws:
IOException
-
isParamInDefaults
-
skipDstreamToEnd
-