List of usage examples for org.apache.poi.poifs.filesystem DirectoryEntry createDocument
public DocumentEntry createDocument(final String name, final InputStream stream) throws IOException;
From source file:net.sf.mpxj.utility.MppClean.java
License:Open Source License
/** * Extracts a block of data from the MPP file, and iterates through the map * of find/replace pairs to make the data anonymous. * //from ww w . j a v a 2 s .c om * @param parentDirectory parent directory object * @param fileName target file name * @param replacements find/replace data * @param unicode true for double byte text * @throws IOException */ private void processReplacements(DirectoryEntry parentDirectory, String fileName, Map<String, String> replacements, boolean unicode) throws IOException { // // Populate a list of keys and sort into descending order of length // List<String> keys = new ArrayList<String>(replacements.keySet()); Collections.sort(keys, new Comparator<String>() { @Override public int compare(String o1, String o2) { return (o2.length() - o1.length()); } }); // // Extract the raw file data // DocumentEntry targetFile = (DocumentEntry) parentDirectory.getEntry(fileName); DocumentInputStream dis = new DocumentInputStream(targetFile); int dataSize = dis.available(); byte[] data = new byte[dataSize]; dis.read(data); // // Replace the text // for (String findText : keys) { String replaceText = replacements.get(findText); replaceData(data, findText, replaceText, unicode); } // // Remove the document entry // targetFile.delete(); // // Replace it with a new one // parentDirectory.createDocument(fileName, new ByteArrayInputStream(data)); }
From source file:net.sf.mpxj.utility.MppCleanUtility.java
License:Open Source License
/** * Extracts a block of data from the MPP file, and iterates through the map * of find/replace pairs to make the data anonymous. * /* www. ja v a2 s . co m*/ * @param parentDirectory parent directory object * @param fileName target file name * @param replacements find/replace data * @param unicode true for double byte text * @throws IOException */ private void processReplacements(DirectoryEntry parentDirectory, String fileName, Map<String, String> replacements, boolean unicode) throws IOException { // // Populate a list of keys and sort into descending order of length // List<String> keys = new ArrayList<String>(replacements.keySet()); Collections.sort(keys, new Comparator<String>() { @Override public int compare(String o1, String o2) { return (o2.length() - o1.length()); } }); // // Extract the raw file data // DocumentEntry targetFile = (DocumentEntry) parentDirectory.getEntry(fileName); DocumentInputStream dis = new DocumentInputStream(targetFile); int dataSize = dis.available(); byte[] data = new byte[dataSize]; dis.read(data); dis.close(); // // Replace the text // for (String findText : keys) { String replaceText = replacements.get(findText); replaceData(data, findText, replaceText, unicode); } // // Remove the document entry // targetFile.delete(); // // Replace it with a new one // parentDirectory.createDocument(fileName, new ByteArrayInputStream(data)); }
From source file:org.elasticwarehouse.core.parsers.FileEmbeddedDocumentExtractor.java
License:Apache License
protected void copy(DirectoryEntry sourceDir, DirectoryEntry destDir) throws IOException { for (org.apache.poi.poifs.filesystem.Entry entry : sourceDir) { if (entry instanceof DirectoryEntry) { // Need to recurse DirectoryEntry newDir = destDir.createDirectory(entry.getName()); copy((DirectoryEntry) entry, newDir); } else {/*from ww w .j a v a2 s . c o m*/ // Copy entry InputStream contents = new DocumentInputStream((DocumentEntry) entry); try { destDir.createDocument(entry.getName(), contents); } finally { contents.close(); } } } }