List of usage examples for org.apache.poi.poifs.filesystem DirectoryEntry setStorageClsid
public void setStorageClsid(ClassID clsidStorage);
From source file:tv.amwa.maj.io.aaf.AAFBuilder.java
License:Apache License
public final static void generateAAFStructure(DirectoryEntry classDir, AAFWriterListener aafWriter, MetadataObject rootObject) throws IOException { ClassDefinition rootClass = MediaEngine.getClassDefinition(rootObject); // if (rootClass instanceof PropertyDefinition) // aafWriter.registerLocalID((PropertyDefinition) rootClass); String path = makePathForDirectory(classDir); classDir.setStorageClsid(new AAFClassID(rootClass.getAUID())); // System.out.println(path + " " + classDir.getStorageClsid()); // System.out.println(path + File.separator + "properties"); Set<PropertyDefinition> properties = rootClass.getAllPropertyDefinitions(); if (rootObject instanceof MetaDefinition) ((MetaDefinition) rootObject).setAAFNamesInUse(true); SortedMap<? extends PropertyDefinition, ? extends PropertyValue> valueMap = rootClass .getProperties(rootObject);/*w w w . j a v a2s.c o m*/ if (rootObject instanceof MetaDefinition) ((MetaDefinition) rootObject).setAAFNamesInUse(false); int propertyCount = 0; int propertiesSize = 0; for (PropertyDefinition property : properties) { // No need to process optional not present values if (property.getIsOptional()) { if (!valueMap.containsKey(property)) continue; } // No need to write object class property if (property.getAUID().equals(ObjectClassID)) continue; // Not interested in member of properties in AAF serialization if (property.getAUID().equals(MemberOfID)) continue; // Check to see if we don't have a value for everything else if (!valueMap.containsKey(property)) { System.err.println("Found a required property not in the value map for " + rootClass.getName() + "." + property.getName() + "."); System.err.println(rootObject.toString()); continue; } TypeDefinition propertyType = property.getTypeDefinition(); PropertyValue value = valueMap.get(property); if (propertyType.equals(TypeDefinitions.ApplicationPluginObjectStrongReferenceSet)) { Set<PropertyValue> setElements = ((TypeDefinitionSet) propertyType).getElements(value); if (setElements.size() == 1) { // Possibly an extension class PropertyValue theElement = null; for (PropertyValue item : setElements) theElement = item; ApplicationPluginObject plugin = (ApplicationPluginObject) theElement.getValue(); if (!(plugin.getObjectClass().getAUID().equals(AAFConstants.ApplicationPluginObjectID))) { classDir.setStorageClsid(new AAFClassID(plugin.getObjectClass().getAUID())); } } for (PropertyValue item : setElements) { // TODO unnecessarily defensive? if (!(item.getValue() instanceof ApplicationPluginObject)) continue; ApplicationPluginObject plugin = (ApplicationPluginObject) item.getValue(); if (plugin == null) continue; Set<AUID> extensionPropertyIDs = plugin.getExtensionPropertyIDs(); for (AUID extensionPropertyID : extensionPropertyIDs) { PropertyDefinition extensionPropertyDefinition = Warehouse .lookForProperty(extensionPropertyID); PropertyValue extensionPropertyValue = plugin.getExtensionProperty(extensionPropertyID); if ((extensionPropertyDefinition != null) && (extensionPropertyValue != null)) { propertyCount++; aafWriter.registerLocalID(extensionPropertyDefinition); aafWriter.addProperty(path, extensionPropertyDefinition, extensionPropertyValue); propertiesSize += processPropertyValue(extensionPropertyDefinition, extensionPropertyValue, classDir, aafWriter, path); } } } continue; } aafWriter.registerLocalID(property); aafWriter.addProperty(path, property, value); propertyCount++; propertiesSize += processPropertyValue(property, value, classDir, aafWriter, path); } propertiesSize += 4 + 6 * propertyCount; classDir.createDocument(PROPERTIES_STREAMNAME, propertiesSize, aafWriter); }
From source file:tv.amwa.maj.io.aaf.AAFBuilder.java
License:Apache License
/** * @param args/* ww w . j a va2s.c om*/ */ 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 . ja v a2 s . 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(); } }