Package com.twelvemonkeys.io.ole2
Class CompoundDocument
java.lang.Object
com.twelvemonkeys.io.ole2.CompoundDocument
- All Implemented Interfaces:
AutoCloseable
Represents 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 ClassesModifier and TypeClassDescription(package private) static class
(package private) static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
private SIdChain
private static final int
static final long
The epoch offset of CompoundDocument time stampsprivate static final int
static final int
private final DataInput
(package private) static final byte[]
private int[]
private int
private static final int
private Entry
private int[]
private static final int
private int
private int[]
private int
private int
private int
private SIdChain
private UUID
-
Constructor Summary
ConstructorsConstructorDescriptionCompoundDocument
(SeekableInputStream stream) CompoundDocument
(File file) Creates a (for now) read onlyCompoundDocument
.CompoundDocument
(InputStream pInput) Creates a read onlyCompoundDocument
.CompoundDocument
(ImageInputStream input) Creates a read onlyCompoundDocument
. -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
private static boolean
void
close()
This method will close the underlyingRandomAccessFile
if any, but will leave any stream created outside the document open.private InputStream
getDirectoryStreamForDId
(int pDirectoryId) getEntries
(int pDirectoryId, Entry pParent) getEntriesRecursive
(int pDirectoryId, Entry pParent, SortedSet<Entry> pEntries) (package private) Entry
(package private) Entry
(package private) SeekableInputStream
getInputStreamForSId
(int pStreamId, int pStreamSize) private SIdChain
getSIdChain
(int pSId, long pStreamSize) Gets the SIdChain for the given stream Idprivate boolean
isShortStream
(long pStreamSize) private void
private void
readSAT()
private void
seekToDId
(int pDId) private void
seekToSId
(int pSId, long pStreamSize) Seeks to the start pos for the given stream Idprivate int
skipBytesFully
(int n) static long
toJavaTimeInMillis
(long pMSTime) Converts the given time stamp to standard Java time representation, milliseconds since January 1, 1970.toString()
-
Field Details
-
MAGIC
static final byte[] MAGIC -
FREE_SID
private static final int FREE_SID- See Also:
-
END_OF_CHAIN_SID
private static final int END_OF_CHAIN_SID- See Also:
-
SAT_SECTOR_SID
private static final int SAT_SECTOR_SID- See Also:
-
MSAT_SECTOR_SID
private static final int MSAT_SECTOR_SID- See Also:
-
HEADER_SIZE
public static final int HEADER_SIZE- See Also:
-
EPOCH_OFFSET
public static final long EPOCH_OFFSETThe epoch offset of CompoundDocument time stamps- See Also:
-
input
-
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
-
shortStreamSIdChain
-
directorySIdChain
-
-
Constructor Details
-
CompoundDocument
Creates 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:
IOException
- if an I/O exception occurs while reading the header
-
CompoundDocument
Creates a read onlyCompoundDocument
.- Parameters:
pInput
- the input to read from.- Throws:
IOException
- if an I/O exception occurs while reading the header
-
CompoundDocument
CompoundDocument(SeekableInputStream stream) throws IOException - Throws:
IOException
-
CompoundDocument
Creates a read onlyCompoundDocument
.- Parameters:
input
- the input to read from- Throws:
IOException
- if an I/O exception occurs while reading the header
-
-
Method Details
-
close
This method will close the underlyingRandomAccessFile
if any, but will leave any stream created outside the document open.- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
- if an I/O error occurs.- See Also:
-
canRead
-
canRead
-
readHeader
- Throws:
IOException
-
skipBytesFully
- Throws:
IOException
-
readSAT
- Throws:
IOException
-
getSIdChain
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:
IOException
- if an I/O exception occurs
-
isShortStream
private boolean isShortStream(long pStreamSize) -
seekToSId
Seeks 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:
IOException
- if an I/O exception occurs
-
seekToDId
- Throws:
IOException
-
getInputStreamForSId
- Throws:
IOException
-
getDirectoryStreamForDId
- Throws:
IOException
-
getEntry
- Throws:
IOException
-
getEntries
- Throws:
IOException
-
getEntriesRecursive
private SortedSet<Entry> getEntriesRecursive(int pDirectoryId, Entry pParent, SortedSet<Entry> pEntries) throws IOException - Throws:
IOException
-
getEntry
- Throws:
IOException
-
getRootEntry
- Throws:
IOException
-
toString
-
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
0L
ifpMSTime == 0L
-