I have two functions:
Boolean isValid(InputStream in) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
factory.setAttribute(JAXP_SCHEMA_SOURCE, schemas);
DocumentBuilder parser = factory.newDocumentBuilder();
parser.parse(in);
...
}
void transform(InputStream in) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
StreamSource ss = new StreamSource(File("transformer.xslt"));
Transformer trans = TransformerFactory.newInstance().newTransformer(ss);
StreamSource sin = new StreamSource(in);
// The next statement throws an exception
trans.transform(sin, new StreamResult(out));
...
}
Which are called from a third:
void doSomething(InputStream in) {
if (isValid(in)) {
transform(in);
}
}
But when this pass trough the first something happens with the InputStream that the second functions throws an Exception in the transform phase. The strange thing is that this doesnt happens if both of them open their own FileInputStream. Any clues thanks.
SystemId Unknown; Line #-1; Column #-1; Premature end of file.
[Fatal Error] :-1:-1: Premature end of file.
...