* @param streamBuf the data in the stream, as a byte buffer
*/
public static ByteBuffer decodeStream(PDFObject dict, ByteBuffer streamBuf, Set<String> filterLimits)
throws IOException {
PDFObject filter = dict.getDictRef("Filter");
if (filter == null) {
// just apply default decryption
return dict.getDecrypter().decryptBuffer(null, dict, streamBuf);
} else {
// apply filters
FilterSpec spec = new FilterSpec(dict, filter);
// determine whether default encryption applies or if there's a
// specific Crypt filter; it must be the first filter according to
// the errata for PDF1.7
boolean specificCryptFilter =
spec.ary.length != 0 && spec.ary[0].getStringValue().equals("Crypt");
if (!specificCryptFilter) {
// No Crypt filter, so should apply default decryption (if
// present!)
streamBuf = dict.getDecrypter().decryptBuffer(
null, dict, streamBuf);
}
for (int i = 0; i < spec.ary.length; i++) {
String enctype = spec.ary[i].getStringValue();
if (filterLimits.contains(enctype)) {
break;
}
if (enctype == null) {
} else if (enctype.equals("FlateDecode") || enctype.equals("Fl")) {
streamBuf = FlateDecode.decode(dict, streamBuf, spec.params[i]);
} else if (enctype.equals("LZWDecode") || enctype.equals("LZW")) {
streamBuf = LZWDecode.decode(streamBuf, spec.params[i]);
} else if (enctype.equals("ASCII85Decode") || enctype.equals("A85")) {
streamBuf = ASCII85Decode.decode(streamBuf, spec.params[i]);
} else if (enctype.equals("ASCIIHexDecode") || enctype.equals("AHx")) {
streamBuf = ASCIIHexDecode.decode(streamBuf, spec.params[i]);
} else if (enctype.equals("RunLengthDecode") || enctype.equals("RL")) {
streamBuf = RunLengthDecode.decode(streamBuf, spec.params[i]);
} else if (enctype.equals("DCTDecode") || enctype.equals("DCT")) {
streamBuf = DCTDecode.decode(dict, streamBuf, spec.params[i]);
} else if (enctype.equals("JPXDecode")) {
streamBuf = JPXDecode.decode(dict, streamBuf, spec.params[i]);
} else if (enctype.equals("CCITTFaxDecode") || enctype.equals("CCF")) {
streamBuf = CCITTFaxDecode.decode(dict, streamBuf, spec.params[i]);
} else if (enctype.equals("Crypt")) {
String cfName = PDFDecrypterFactory.CF_IDENTITY;
if (spec.params[i] != null) {
final PDFObject nameObj = spec.params[i].getDictRef("Name");
if (nameObj != null && nameObj.getType() == PDFObject.NAME) {
cfName = nameObj.getStringValue();
}
}
streamBuf = dict.getDecrypter().decryptBuffer(cfName, null, streamBuf);
} else if (enctype.equals("JBIG2Decode")) {
streamBuf = JBig2Decode.decode(dict, streamBuf, spec.params[i]);