UnpackParsedCommand inputCommand = (UnpackParsedCommand) parsedCommand;
try{
PdfFile[] fileList = arraysConcat(inputCommand.getInputFileList(), getPdfFiles(inputCommand.getInputDirectory()));
//check if empty
if (fileList== null || !(fileList.length >0)){
throw new UnpackException(UnpackException.CMD_NO_INPUT_FILE);
}
for(int i = 0; i<fileList.length; i++){
int unpackedFiles = 0;
try{
pdfReader = new PdfReader(new RandomAccessFileOrArray(fileList[i].getFile().getAbsolutePath()),fileList[i].getPasswordBytes());
pdfReader.removeUnusedObjects();
pdfReader.consolidateNamedDestinations();
PdfDictionary catalog = pdfReader.getCatalog();
PdfDictionary names = (PdfDictionary) PdfReader.getPdfObject(catalog.get(PdfName.NAMES));
if (names != null) {
PdfDictionary embFiles = (PdfDictionary) PdfReader.getPdfObject(names.get(new PdfName("EmbeddedFiles")));
if (embFiles != null) {
HashMap embMap = PdfNameTree.readTree(embFiles);
for (Iterator iter = embMap.values().iterator(); iter.hasNext();) {
PdfDictionary filespec = (PdfDictionary) PdfReader.getPdfObject((PdfObject) iter.next());
unpackedFiles += unpackFile(filespec, inputCommand.getOutputFile(), inputCommand.isOverwrite());
}
}
}
for (int k = 1; k <= pdfReader.getNumberOfPages(); ++k) {
PdfArray annots = (PdfArray) PdfReader.getPdfObject(pdfReader.getPageN(k).get(PdfName.ANNOTS));
if (annots != null){
for (Iterator iter = annots.listIterator(); iter.hasNext();) {
PdfDictionary annot = (PdfDictionary) PdfReader.getPdfObject((PdfObject) iter.next());
PdfName subType = (PdfName) PdfReader.getPdfObject(annot.get(PdfName.SUBTYPE));
if (PdfName.FILEATTACHMENT.equals(subType)){
PdfDictionary filespec = (PdfDictionary) PdfReader.getPdfObject(annot.get(PdfName.FS));
unpackedFiles += unpackFile(filespec, inputCommand.getOutputFile(), inputCommand.isOverwrite());
}
}
}
}
pdfReader.close();
if(unpackedFiles >0){
LOG.info("File "+fileList[i].getFile().getName()+" unpacked, found "+unpackedFiles+" attachments.");
}else{
LOG.info("No attachments in "+fileList[i].getFile().getName()+".");
}
setPercentageOfWorkDone(((i+1)*WorkDoneDataModel.MAX_PERGENTAGE)/fileList.length);
}catch(Exception e){
LOG.error("Error unpacking file "+fileList[i].getFile().getName(), e);
}
}
}catch(Exception e){
throw new UnpackException(e);
}finally{
setWorkCompleted();
}
}
else{