Package com.twelvemonkeys.io.ole2
Class CompoundDocument
- java.lang.Object
-
- com.twelvemonkeys.io.ole2.CompoundDocument
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public final class CompoundDocument extends java.lang.Object implements java.lang.AutoCloseableRepresents a read-only OLE2 compound document.NOTE: This class is not synchronized. Accessing the document or its entries from different threads, will need synchronization on the document instance.
- Version:
- $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/ole2/CompoundDocument.java#4 $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classCompoundDocument.SeekableLittleEndianDataInputStream(package private) static classCompoundDocument.Stream
-
Field Summary
Fields Modifier and Type Field Description private intdirectorySIdprivate SIdChaindirectorySIdChainprivate static intEND_OF_CHAIN_SIDstatic longEPOCH_OFFSETThe epoch offset of CompoundDocument time stampsprivate static intFREE_SIDstatic intHEADER_SIZEprivate java.io.DataInputinput(package private) static byte[]MAGICprivate int[]masterSATprivate intminStreamSizeprivate static intMSAT_SECTOR_SIDprivate EntryrootEntryprivate int[]SATprivate static intSAT_SECTOR_SIDprivate intsectorSizeprivate int[]shortSATprivate intshortSATSIdprivate intshortSATSizeprivate intshortSectorSizeprivate SIdChainshortStreamSIdChainprivate java.util.UUIDuUID
-
Constructor Summary
Constructors Constructor Description CompoundDocument(SeekableInputStream stream)CompoundDocument(java.io.File file)Creates a (for now) read onlyCompoundDocument.CompoundDocument(java.io.InputStream pInput)Creates a read onlyCompoundDocument.CompoundDocument(javax.imageio.stream.ImageInputStream input)Creates a read onlyCompoundDocument.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static booleancanRead(java.io.DataInput pInput)private static booleancanRead(java.io.DataInput pInput, boolean pReset)voidclose()This method will close the underlyingRandomAccessFileif any, but will leave any stream created outside the document open.private java.io.InputStreamgetDirectoryStreamForDId(int pDirectoryId)(package private) java.util.SortedSet<Entry>getEntries(int pDirectoryId, Entry pParent)private java.util.SortedSet<Entry>getEntriesRecursive(int pDirectoryId, Entry pParent, java.util.SortedSet<Entry> pEntries)(package private) EntrygetEntry(int pDirectoryId, Entry pParent)(package private) EntrygetEntry(java.lang.String pPath)(package private) SeekableInputStreamgetInputStreamForSId(int pStreamId, int pStreamSize)EntrygetRootEntry()private SIdChaingetSIdChain(int pSId, long pStreamSize)Gets the SIdChain for the given stream Idprivate booleanisShortStream(long pStreamSize)private voidreadHeader()private voidreadSAT()private voidseekToDId(int pDId)private voidseekToSId(int pSId, long pStreamSize)Seeks to the start pos for the given stream Idprivate intskipBytesFully(int n)static longtoJavaTimeInMillis(long pMSTime)Converts the given time stamp to standard Java time representation, milliseconds since January 1, 1970.java.lang.StringtoString()
-
-
-
Field Detail
-
MAGIC
static final byte[] MAGIC
-
FREE_SID
private static final int FREE_SID
- See Also:
- Constant Field Values
-
END_OF_CHAIN_SID
private static final int END_OF_CHAIN_SID
- See Also:
- Constant Field Values
-
SAT_SECTOR_SID
private static final int SAT_SECTOR_SID
- See Also:
- Constant Field Values
-
MSAT_SECTOR_SID
private static final int MSAT_SECTOR_SID
- See Also:
- Constant Field Values
-
HEADER_SIZE
public static final int HEADER_SIZE
- See Also:
- Constant Field Values
-
EPOCH_OFFSET
public static final long EPOCH_OFFSET
The epoch offset of CompoundDocument time stamps- See Also:
- Constant Field Values
-
input
private final java.io.DataInput input
-
uUID
private java.util.UUID uUID
-
sectorSize
private int sectorSize
-
shortSectorSize
private int shortSectorSize
-
directorySId
private int directorySId
-
minStreamSize
private int minStreamSize
-
shortSATSId
private int shortSATSId
-
shortSATSize
private int shortSATSize
-
masterSAT
private int[] masterSAT
-
SAT
private int[] SAT
-
shortSAT
private int[] shortSAT
-
rootEntry
private Entry rootEntry
-
shortStreamSIdChain
private SIdChain shortStreamSIdChain
-
directorySIdChain
private SIdChain directorySIdChain
-
-
Constructor Detail
-
CompoundDocument
public CompoundDocument(java.io.File file) throws java.io.IOExceptionCreates a (for now) read onlyCompoundDocument.Warning! You must invoke
close()on the compound document created from this constructor when done, to avoid leaking file descriptors.- Parameters:
file- the file to read from- Throws:
java.io.IOException- if an I/O exception occurs while reading the header
-
CompoundDocument
public CompoundDocument(java.io.InputStream pInput) throws java.io.IOExceptionCreates a read onlyCompoundDocument.- Parameters:
pInput- the input to read from.- Throws:
java.io.IOException- if an I/O exception occurs while reading the header
-
CompoundDocument
CompoundDocument(SeekableInputStream stream) throws java.io.IOException
- Throws:
java.io.IOException
-
CompoundDocument
public CompoundDocument(javax.imageio.stream.ImageInputStream input) throws java.io.IOExceptionCreates a read onlyCompoundDocument.- Parameters:
input- the input to read from- Throws:
java.io.IOException- if an I/O exception occurs while reading the header
-
-
Method Detail
-
close
public void close() throws java.io.IOExceptionThis method will close the underlyingRandomAccessFileif any, but will leave any stream created outside the document open.- Specified by:
closein interfacejava.lang.AutoCloseable- Throws:
java.io.IOException- if an I/O error occurs.- See Also:
CompoundDocument(File),RandomAccessFile.close()
-
canRead
public static boolean canRead(java.io.DataInput pInput)
-
canRead
private static boolean canRead(java.io.DataInput pInput, boolean pReset)
-
readHeader
private void readHeader() throws java.io.IOException- Throws:
java.io.IOException
-
skipBytesFully
private int skipBytesFully(int n) throws java.io.IOException- Throws:
java.io.IOException
-
readSAT
private void readSAT() throws java.io.IOException- Throws:
java.io.IOException
-
getSIdChain
private SIdChain getSIdChain(int pSId, long pStreamSize) throws java.io.IOException
Gets the SIdChain for the given stream Id- Parameters:
pSId- the stream IdpStreamSize- the size of the stream, or -1 for system control streams- Returns:
- the SIdChain for the given stream Id
- Throws:
java.io.IOException- if an I/O exception occurs
-
isShortStream
private boolean isShortStream(long pStreamSize)
-
seekToSId
private void seekToSId(int pSId, long pStreamSize) throws java.io.IOExceptionSeeks to the start pos for the given stream Id- Parameters:
pSId- the stream IdpStreamSize- the size of the stream, or -1 for system control streams- Throws:
java.io.IOException- if an I/O exception occurs
-
seekToDId
private void seekToDId(int pDId) throws java.io.IOException- Throws:
java.io.IOException
-
getInputStreamForSId
SeekableInputStream getInputStreamForSId(int pStreamId, int pStreamSize) throws java.io.IOException
- Throws:
java.io.IOException
-
getDirectoryStreamForDId
private java.io.InputStream getDirectoryStreamForDId(int pDirectoryId) throws java.io.IOException- Throws:
java.io.IOException
-
getEntry
Entry getEntry(int pDirectoryId, Entry pParent) throws java.io.IOException
- Throws:
java.io.IOException
-
getEntries
java.util.SortedSet<Entry> getEntries(int pDirectoryId, Entry pParent) throws java.io.IOException
- Throws:
java.io.IOException
-
getEntriesRecursive
private java.util.SortedSet<Entry> getEntriesRecursive(int pDirectoryId, Entry pParent, java.util.SortedSet<Entry> pEntries) throws java.io.IOException
- Throws:
java.io.IOException
-
getEntry
Entry getEntry(java.lang.String pPath) throws java.io.IOException
- Throws:
java.io.IOException
-
getRootEntry
public Entry getRootEntry() throws java.io.IOException
- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toJavaTimeInMillis
public static long toJavaTimeInMillis(long pMSTime)
Converts the given time stamp to standard Java time representation, milliseconds since January 1, 1970. The time stamp parameter is assumed to be in units of 100 nano seconds since January 1, 1601.If the timestamp is
0L(meaning not specified), no conversion is done, to behave likejava.io.File.- Parameters:
pMSTime- an unsigned long value representing the time stamp (in units of 100 nano seconds since January 1, 1601).- Returns:
- the time stamp converted to Java time stamp in milliseconds,
or
0LifpMSTime == 0L
-
-