Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Premature end of file Error Using same inputstream from two functions

843834Aug 19 2008 — edited Aug 21 2008
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.
...
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 18 2008
Added on Aug 19 2008
12 comments
1,914 views