"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ExtractEmbeddedFiles.java" between
pdfbox-2.0.23-src.zip and pdfbox-2.0.24-src.zip

About: Apache PDFBox is a Java PDF library tool that allows creation of new PDF documents, manipulation of existing documents and the ability to extract content from documents.

ExtractEmbeddedFiles.java  (pdfbox-2.0.23-src):ExtractEmbeddedFiles.java  (pdfbox-2.0.24-src)
skipping to change at line 108 skipping to change at line 108
PDComplexFileSpecification fileSpec = (PDComplexFileSpecificatio n) annotationFileAttachment.getFile(); PDComplexFileSpecification fileSpec = (PDComplexFileSpecificatio n) annotationFileAttachment.getFile();
PDEmbeddedFile embeddedFile = getEmbeddedFile(fileSpec); PDEmbeddedFile embeddedFile = getEmbeddedFile(fileSpec);
if (embeddedFile != null) if (embeddedFile != null)
{ {
extractFile(filePath, fileSpec.getFilename(), embeddedFile); extractFile(filePath, fileSpec.getFilename(), embeddedFile);
} }
} }
} }
} }
private static void extractFilesFromEFTree(PDEmbeddedFilesNameTreeNode efTre e, String filePath) throws IOException private static void extractFilesFromEFTree(PDNameTreeNode<PDComplexFileSpeci fication> efTree, String filePath) throws IOException
{ {
Map<String, PDComplexFileSpecification> names = efTree.getNames(); Map<String, PDComplexFileSpecification> names = efTree.getNames();
if (names != null) if (names != null)
{ {
extractFiles(names, filePath); extractFiles(names, filePath);
} }
else else
{ {
List<PDNameTreeNode<PDComplexFileSpecification>> kids = efTree.getKi ds(); List<PDNameTreeNode<PDComplexFileSpecification>> kids = efTree.getKi ds();
if (kids == null)
{
return;
}
for (PDNameTreeNode<PDComplexFileSpecification> node : kids) for (PDNameTreeNode<PDComplexFileSpecification> node : kids)
{ {
names = node.getNames(); extractFilesFromEFTree(node, filePath);
extractFiles(names, filePath);
} }
} }
} }
private static void extractFiles(Map<String, PDComplexFileSpecification> nam es, String filePath) private static void extractFiles(Map<String, PDComplexFileSpecification> nam es, String filePath)
throws IOException throws IOException
{ {
for (Entry<String, PDComplexFileSpecification> entry : names.entrySet()) for (Entry<String, PDComplexFileSpecification> entry : names.entrySet())
{ {
PDComplexFileSpecification fileSpec = entry.getValue(); PDComplexFileSpecification fileSpec = entry.getValue();
skipping to change at line 144 skipping to change at line 147
{ {
extractFile(filePath, fileSpec.getFilename(), embeddedFile); extractFile(filePath, fileSpec.getFilename(), embeddedFile);
} }
} }
} }
private static void extractFile(String filePath, String filename, PDEmbedded File embeddedFile) private static void extractFile(String filePath, String filename, PDEmbedded File embeddedFile)
throws IOException throws IOException
{ {
String embeddedFilename = filePath + filename; String embeddedFilename = filePath + filename;
File file = new File(filePath + filename); File file = new File(embeddedFilename);
File parentDir = file.getParentFile();
if (!parentDir.exists())
{
// sometimes paths contain a directory
System.out.println("Creating " + parentDir);
parentDir.mkdirs();
}
System.out.println("Writing " + embeddedFilename); System.out.println("Writing " + embeddedFilename);
FileOutputStream fos = null; FileOutputStream fos = null;
try try
{ {
fos = new FileOutputStream(file); fos = new FileOutputStream(file);
fos.write(embeddedFile.toByteArray()); fos.write(embeddedFile.toByteArray());
} }
finally finally
{ {
IOUtils.closeQuietly(fos); IOUtils.closeQuietly(fos);
 End of changes. 4 change blocks. 
4 lines changed or deleted 14 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)