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

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

Introduction

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

Prototype

public int getBigBlockSize() 

Source Link

Usage

From source file:tv.amwa.maj.io.aaf.AAFBuilder.java

License:Apache License

/**
 * @param args/*from  ww  w .j  ava 2  s  . c  o  m*/
 */
public static void main(String[] args) throws IOException {

    if (args.length != 2)
        System.exit(1);

    final String inputFilename = args[0];
    final String outputFilename = args[1];

    POIFSReader r = new AAFReader();

    LocalAAFEventReader eventReader = new LocalAAFEventReader();
    r.registerListener(eventReader);

    AvidFactory.registerAvidExtensions();

    FileInputStream fis = null;

    long startTime = System.nanoTime();
    try {
        fis = new FileInputStream(inputFilename);
        r.read(new FileInputStream(inputFilename));
        eventReader.resolveEntries();
    } finally {
        if (fis != null)
            try {
                fis.close();
            } catch (Exception e) {
            }
    }
    long endTime = System.nanoTime();

    System.out.println("AAF file read in " + (endTime - startTime) + "ns.");

    ((PrefaceImpl) eventReader.getPreface()).setByteOrder(tv.amwa.maj.enumeration.ByteOrder.Big);
    System.out.println(eventReader.getPreface().getByteOrder());

    POIFSFileSystem outputFileSystem = new POIFSFileSystem();

    DirectoryEntry rootDir = outputFileSystem.getRoot();

    AAFWriterListener aafWriter = makeAAFWriterListener();
    DirectoryEntry metaDictionaryDir = rootDir.createDirectory(META_DICTIONARY_DIRNAME);
    DirectoryEntry prefaceDir = rootDir.createDirectory(PREFACE_DIRNAME);

    generateAAFStructure(prefaceDir, aafWriter, eventReader.getPreface());
    generateMetaDictionary(metaDictionaryDir, aafWriter, eventReader.getPreface());
    rootDir.createDocument(PROPERTIES_STREAMNAME, 70, aafWriter);
    rootDir.createDocument(REFERENCED_PROPERTIES_STREAMNAME, aafWriter.getReferencedPropertiesSize(),
            aafWriter);

    //       rootDir.setStorageClsid(
    //             (outputFileSystem.getBigBlockSize() == 4096) ?
    //                   new AAFClassID(AAFSignatureSSBin4K) :
    //                      new AAFClassID(AAFSignatureSSBinary));

    rootDir.setStorageClsid(new ClassID(rootEntryClassID, 0));

    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(outputFilename);
        outputFileSystem.writeFilesystem(fos);
    } finally {
        if (fos != null)
            try {
                fos.close();
            } catch (Exception e) {
            }
    }

    // AAF puts a signature in bytes 8-23 of the file
    // POIFS cannot write this

    RandomAccessFile fixFile = null;
    FileChannel fixChannel = null;
    try {
        fixFile = new RandomAccessFile(outputFilename, "rw");
        fixChannel = fixFile.getChannel();

        fixChannel.position(8);
        if (outputFileSystem.getBigBlockSize() == 4096)
            fixChannel.write(ByteBuffer.wrap(AAFSignatureSSBin4KBytes));
        else
            fixChannel.write(ByteBuffer.wrap(AAFSignatureSSBinaryBytes));
    } finally {
        if (fixChannel != null)
            fixChannel.close();
    }
}

From source file:tv.amwa.maj.io.aaf.AAFFactory.java

License:Apache License

/**
 * <p>Write an AAF file with the given filename that is constructed from the given {@linkplain Preface preface}.<p>
 * /*from  ww w .  j ava2s .c  om*/
 * <p>Note that this version of MAJ only supports writing metadata-only files.</p>
 * 
 * @param preface Preface to use to construct an AAF file from.
 * @param outputFilename File path specification for the file to write the preface to.
 * 
 * @throws IOException An error occurred when writing the AAF file.
 * 
 * @see #readPreface(String)
 */
public final static void writePreface(Preface preface, String outputFilename) throws IOException {

    POIFSFileSystem outputFileSystem = new POIFSFileSystem();

    DirectoryEntry rootDir = outputFileSystem.getRoot();

    preface.updateDictionaries();
    //       System.out.println(preface);

    AAFWriterListener aafWriter = AAFBuilder.makeAAFWriterListener();
    DirectoryEntry metaDictionaryDir = rootDir.createDirectory(META_DICTIONARY_DIRNAME);
    DirectoryEntry prefaceDir = rootDir.createDirectory(PREFACE_DIRNAME);

    AAFBuilder.generateAAFStructure(prefaceDir, aafWriter, preface);
    AAFBuilder.generateMetaDictionary(metaDictionaryDir, aafWriter, preface);
    rootDir.createDocument(PROPERTIES_STREAMNAME, 70, aafWriter);
    rootDir.createDocument(REFERENCED_PROPERTIES_STREAMNAME, aafWriter.getReferencedPropertiesSize(),
            aafWriter);

    //       rootDir.setStorageClsid(
    //             (outputFileSystem.getBigBlockSize() == 4096) ?
    //                   new AAFClassID(AAFSignatureSSBin4K) :
    //                      new AAFClassID(AAFSignatureSSBinary));

    rootDir.setStorageClsid(new ClassID(rootEntryClassID, 0));

    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(outputFilename);
        outputFileSystem.writeFilesystem(fos);
    } finally {
        if (fos != null)
            try {
                fos.close();
            } catch (Exception e) {
            }
    }

    // AAF puts a signature in bytes 8-23 of the file
    // POIFS cannot write this

    RandomAccessFile fixFile = null;
    FileChannel fixChannel = null;
    try {
        fixFile = new RandomAccessFile(outputFilename, "rw");
        fixChannel = fixFile.getChannel();

        fixChannel.position(8);
        if (outputFileSystem.getBigBlockSize() == 4096)
            fixChannel.write(ByteBuffer.wrap(AAFSignatureSSBin4KBytes));
        else
            fixChannel.write(ByteBuffer.wrap(AAFSignatureSSBinaryBytes));
    } finally {
        if (fixChannel != null)
            fixChannel.close();
    }
}