Example usage for org.apache.poi.poifs.filesystem POIFSFileSystem POIFSFileSystem

List of usage examples for org.apache.poi.poifs.filesystem POIFSFileSystem POIFSFileSystem

Introduction

In this page you can find the example usage for org.apache.poi.poifs.filesystem POIFSFileSystem POIFSFileSystem.

Prototype

public POIFSFileSystem(FileChannel channel, boolean readOnly) throws IOException 

Source Link

Document

Creates a POIFSFileSystem from an open FileChannel.

Usage

From source file:com.healthmarketscience.jackcess.util.OleBlobTest.java

License:Apache License

private static void checkCompoundStorage(OleBlob.CompoundContent cc, Attachment attach) throws Exception {
    File tmpData = File.createTempFile("attach_", ".dat");

    try {/* w  w w .  ja va2 s .c o m*/
        FileOutputStream fout = new FileOutputStream(tmpData);
        fout.write(attach.getFileData());
        fout.close();

        POIFSFileSystem attachFs = new POIFSFileSystem(tmpData, true);

        for (OleBlob.CompoundContent.Entry e : cc) {
            DocumentEntry attachE = null;
            try {
                attachE = CompoundOleUtil.getDocumentEntry(e.getName(), attachFs.getRoot());
            } catch (FileNotFoundException fnfe) {
                // ignored, the ole data has extra entries
                continue;
            }

            byte[] attachEBytes = toByteArray(new DocumentInputStream(attachE), attachE.getSize());
            byte[] entryBytes = toByteArray(e.getStream(), e.length());

            assertTrue(Arrays.equals(attachEBytes, entryBytes));
        }

        ByteUtil.closeQuietly(attachFs);

    } finally {
        tmpData.delete();
    }
}