use of com.tom_roush.pdfbox.cos.COSNull in project PdfBox-Android by TomRoush.
the class PDStream method getMetadata.
/**
* Get the metadata that is part of the document catalog. This will return
* null if there is no meta data for this object.
*
* @return The metadata for this object.
* @throws IllegalStateException if the value of the metadata entry is different from a stream
* or null
*/
public PDMetadata getMetadata() {
PDMetadata retval = null;
COSBase mdStream = stream.getDictionaryObject(COSName.METADATA);
if (mdStream != null) {
if (mdStream instanceof COSStream) {
retval = new PDMetadata((COSStream) mdStream);
} else if (mdStream instanceof COSNull) {
// null is authorized
} else {
throw new IllegalStateException("Expected a COSStream but was a " + mdStream.getClass().getSimpleName());
}
}
return retval;
}
use of com.tom_roush.pdfbox.cos.COSNull in project PdfBox-Android by TomRoush.
the class COSParser method prepareDecryption.
/**
* Prepare for decryption.
*
* @throws InvalidPasswordException If the password is incorrect.
* @throws IOException if something went wrong
*/
private void prepareDecryption() throws IOException {
if (encryption != null) {
return;
}
COSBase trailerEncryptItem = document.getTrailer().getItem(COSName.ENCRYPT);
if (trailerEncryptItem == null || trailerEncryptItem instanceof COSNull) {
return;
}
if (trailerEncryptItem instanceof COSObject) {
COSObject trailerEncryptObj = (COSObject) trailerEncryptItem;
parseDictionaryRecursive(trailerEncryptObj);
}
try {
encryption = new PDEncryption(document.getEncryptionDictionary());
DecryptionMaterial decryptionMaterial;
if (keyStoreInputStream != null) {
KeyStore ks = KeyStore.getInstance("PKCS12");
ks.load(keyStoreInputStream, password.toCharArray());
decryptionMaterial = new PublicKeyDecryptionMaterial(ks, keyAlias, password);
} else {
decryptionMaterial = new StandardDecryptionMaterial(password);
}
securityHandler = encryption.getSecurityHandler();
securityHandler.prepareForDecryption(encryption, document.getDocumentID(), decryptionMaterial);
accessPermission = securityHandler.getCurrentAccessPermission();
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw new IOException("Error (" + e.getClass().getSimpleName() + ") while creating security handler for decryption", e);
} finally {
if (keyStoreInputStream != null) {
IOUtils.closeQuietly(keyStoreInputStream);
}
}
}
Aggregations