com.topcoder.file.split
Class Metadata

java.lang.Object
  extended by com.topcoder.file.split.Metadata

public final class Metadata
extends java.lang.Object

This is a final class for encapsulating metadata information used by the file splitter and joiner components. It consists of data members for the information stored in the header, and has methods for writing itself to an output stream and initializing itself by reading metadata from an input stream.

The following is an excerpt of the metadata header format:

The first split file also contains a header with metadata:

Version:
1.0
Author:
npe
See Also:
FileSplitter, FileJoiner

Constructor Summary
Metadata()
           
 
Method Summary
 short getMajorVersion()
           
 short getMinorVersion()
           
 int getNumSplitFiles()
           
 java.lang.String getOriginalFileName()
           
 long getSize()
           
 java.lang.String getSplitFileFormatString()
           
 void read(java.io.InputStream is)
          Initializes this metadata object by reading a series of bytes from an input stream.
 void setMajorVersion(short majorVersion)
           
 void setMinorVersion(short minorVersion)
           
 void setNumSplitFiles(int numSplitFiles)
           
 void setOriginalFileName(java.lang.String originalFileName)
           
 void setSplitFileFormatString(java.lang.String splitFileFormatString)
           
 void write(java.io.OutputStream os)
          Writes this metadata object as a formatted series of bytes to an output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Metadata

public Metadata()
Method Detail

getMajorVersion

public short getMajorVersion()
Returns:
The metadata format major version number.

setMajorVersion

public void setMajorVersion(short majorVersion)
Parameters:
majorVersion - Sets the metadata format major version number.

getMinorVersion

public short getMinorVersion()
Returns:
The metadata format minor version number.

setMinorVersion

public void setMinorVersion(short minorVersion)
Parameters:
minorVersion - Sets the metadata format minor version number.

getOriginalFileName

public java.lang.String getOriginalFileName()
Returns:
The name of the original file.

setOriginalFileName

public void setOriginalFileName(java.lang.String originalFileName)
Parameters:
originalFileName - The name of the original file.

getSplitFileFormatString

public java.lang.String getSplitFileFormatString()
Returns:
The split file format string, which is the pattern used in a MessageFormat object. This string must contain {0} and {1} placeholders for formatting, although that is not validated here.

setSplitFileFormatString

public void setSplitFileFormatString(java.lang.String splitFileFormatString)
Parameters:
splitFileFormatString - The split file format string, which is the pattern used in a MessageFormat object. This string must contain {0} and {1} placeholders for formatting, although that is not validated here.

getNumSplitFiles

public int getNumSplitFiles()
Returns:
The number of split files.

setNumSplitFiles

public void setNumSplitFiles(int numSplitFiles)
Parameters:
numSplitFiles - The number of split files.

getSize

public long getSize()
             throws java.io.IOException
Returns:
The size of this metadata object in number of bytes. This value is the length of the signature and format version, plus the length of the remaining variable length data header.
Throws:
java.io.IOException

write

public void write(java.io.OutputStream os)
           throws java.io.IOException
Writes this metadata object as a formatted series of bytes to an output stream. The format is described in the JavaDocs for this class. This is used to write a header to the first split file.

Parameters:
os - The output stream to write the metadata header to.
Throws:
java.io.IOException - If an error occurs while writing the metadata header.
See Also:
FileSplitter

read

public void read(java.io.InputStream is)
          throws java.io.IOException,
                 InvalidSplitFileHeaderException
Initializes this metadata object by reading a series of bytes from an input stream. As the bytes are read they are validated to ensure that they conform to the metadata format, which is described in the JavaDocs for this class. This method is used to read metadata information from the first split file in order to join the split files together.

Parameters:
is - The input stream containing the metadata header.
Throws:
java.io.IOException - If an error occurs while reading the metadata.
InvalidSplitFileHeaderException - If the metadata read doesn't conform to the split file format.
See Also:
FileJoiner


Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.