src/test/java/uk/gov/hmcts/reform/sendletter/PdfHelper.java
public static void validateZippedPdf(byte[] data) throws IOException {
        try (ZipInputStream zip = new ZipInputStream(new ByteArrayInputStream(data))) {

            zip.getNextEntry(); //positions the stream at the beginning of the entry data

            PreflightParser pdfParser = new PreflightParser(new ByteArrayDataSource(zip));
            pdfParser.parse();
            PreflightDocument document = pdfParser.getPreflightDocument();
            // This will throw an exception if the file format is invalid,
            // but ignores more minor errors such as missing metadata.
            document.validate();
        }
    }
/**
     * Validate that data is a zipped pdf or throw an exception.
     */
Validate that data is a zipped pdf or throw an exception.
Validate that data is a zipped pdf or throw an exception .
public static void validateZippedPdf(byte[] data) throws IOException {
        try (ZipInputStream zip = new ZipInputStream(new ByteArrayInputStream(data))) {
            zip.getNextEntry(); 
            PreflightParser pdfParser = new PreflightParser(new ByteArrayDataSource(zip));
            pdfParser.parse();
            PreflightDocument document = pdfParser.getPreflightDocument();
            document.validate();
        }
    }
public static void validateZippedPdf ( byte [ ] data ) throws IOException { try ( ZipInputStream zip = new ZipInputStream ( new ByteArrayInputStream ( data ) ) ) { zip . getNextEntry ( ) ; PreflightParser pdfParser = new PreflightParser ( new ByteArrayDataSource ( zip ) ) ; pdfParser . parse ( ) ; PreflightDocument document = pdfParser . getPreflightDocument ( ) ; document . validate ( ) ; } }
Validate that data is a zipped pdf or throw an exception.
Validate that data is a zipped pdf or throw an exception .
//positions the stream at the beginning of the entry data // This will throw an exception if the file format is invalid, // but ignores more minor errors such as missing metadata.