Added overload; added max size check
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package org.mustangproject.validator;
|
package org.mustangproject.validator;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
@@ -103,6 +104,10 @@ public class ZUGFeRDValidator {
|
|||||||
// Except it is "<?xml version='1.0'?><xml/>" LOL
|
// Except it is "<?xml version='1.0'?><xml/>" LOL
|
||||||
context.addResultItem(
|
context.addResultItem(
|
||||||
new ValidationResultItem(ESeverity.fatal, "File too small").setSection(5).setPart(EPart.pdf));
|
new ValidationResultItem(ESeverity.fatal, "File too small").setSection(5).setPart(EPart.pdf));
|
||||||
|
} else if (inputLength >= Integer.MAX_VALUE) {
|
||||||
|
// Byte arrays are limited to 2GB in Java
|
||||||
|
context.addResultItem(
|
||||||
|
new ValidationResultItem(ESeverity.fatal, "File too big").setSection(5).setPart(EPart.pdf));
|
||||||
} else {
|
} else {
|
||||||
content = IOUtils.toByteArray(inputStream);
|
content = IOUtils.toByteArray(inputStream);
|
||||||
XMLValidator xv = new XMLValidator(context);
|
XMLValidator xv = new XMLValidator(context);
|
||||||
@@ -252,6 +257,15 @@ public class ZUGFeRDValidator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String validate(byte[] bytes, String fileNameOfInputStream) {
|
||||||
|
try(ByteArrayInputStream bais = new ByteArrayInputStream (bytes)) {
|
||||||
|
return internalValidate (fileNameOfInputStream, bais, bytes.length);
|
||||||
|
}
|
||||||
|
catch (IOException ex) {
|
||||||
|
throw new UncheckedIOException (ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void getPdfValidationResults(StringBuilder finalStringResult, PDFValidator pdfv, XMLValidator xv) throws IrrecoverableValidationError {
|
private void getPdfValidationResults(StringBuilder finalStringResult, PDFValidator pdfv, XMLValidator xv) throws IrrecoverableValidationError {
|
||||||
finalStringResult.append(pdfv.getXMLResult());
|
finalStringResult.append(pdfv.getXMLResult());
|
||||||
pdfValidity = context.isValid();
|
pdfValidity = context.isValid();
|
||||||
|
|||||||
Reference in New Issue
Block a user