fengbaicanhe / flying-saucer

Automatically exported from code.google.com/p/flying-saucer
0 stars 0 forks source link

Stream closed exception #173

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Try to get image from Java2DRenderer
2.
3.

What is the expected output? What do you see instead?
SEVERE: java.io.IOException: Stream closed
    at java.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:134)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:256)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
    at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
    at java.io.InputStreamReader.read(InputStreamReader.java:167)
    at org.xhtmlrenderer.css.parser.Lexer.zzRefill(Lexer.java:1634)
    at org.xhtmlrenderer.css.parser.Lexer.yylex(Lexer.java:1865)
    at org.xhtmlrenderer.css.parser.CSSParser.next(CSSParser.java:1798)
    at org.xhtmlrenderer.css.parser.CSSParser.la(CSSParser.java:1810)
    at org.xhtmlrenderer.css.parser.CSSParser.stylesheet(CSSParser.java:159)
    at org.xhtmlrenderer.css.parser.CSSParser.parseStylesheet(CSSParser.java:89)
    at org.xhtmlrenderer.context.StylesheetFactoryImpl.parse(StylesheetFactoryImpl.java:78)
    at org.xhtmlrenderer.context.StylesheetFactoryImpl.parse(StylesheetFactoryImpl.java:95)
    at org.xhtmlrenderer.context.StylesheetFactoryImpl.getStylesheet(StylesheetFactoryImpl.java:174)
    at org.xhtmlrenderer.context.StyleReference.readAndParseAll(StyleReference.java:123)
    at org.xhtmlrenderer.context.StyleReference.setDocumentContext(StyleReference.java:107)
    at org.xhtmlrenderer.swing.Java2DRenderer.setDocument(Java2DRenderer.java:317)
    at org.xhtmlrenderer.swing.Java2DRenderer.getImage(Java2DRenderer.java:265)
    at printing.HTMLImage.prepareImage(HTMLImage.java:161)

What version of the product are you using? On what operating system?
version R8. System Windows XP

Please provide any additional information below.

here's code context:    

        Tidy tidy = new Tidy();
            StringReader reader = new StringReader(html);
            document = tidy.parseDOM(reader, null);         
//          bufferedImage = generateImageFromHtml(document);
            Java2DRenderer renderer = new Java2DRenderer(document, width, height);
            bufferedImage = renderer.getImage();    

Original issue reported on code.google.com by maciej.w...@gmail.com on 8 Sep 2011 at 11:38

GoogleCodeExporter commented 8 years ago
We are having the same issue in another context

Java Version 1.5.xx (Windows XP)
Version R8 of xhtmlrenderer.

java.io.IOException: Stream closed

      at 
java.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:134)

      at java.io.BufferedInputStream.read1(BufferedInputStream.java:256)

      at java.io.BufferedInputStream.read(BufferedInputStream.java:317)

      at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)

      at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)

      at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)

      at java.io.InputStreamReader.read(InputStreamReader.java:167)

      at org.xhtmlrenderer.css.parser.Lexer.zzRefill(Lexer.java:1634)

      at org.xhtmlrenderer.css.parser.Lexer.yylex(Lexer.java:1865)

      at org.xhtmlrenderer.css.parser.CSSParser.next(CSSParser.java:1798)

      at org.xhtmlrenderer.css.parser.CSSParser.la(CSSParser.java:1810)

      at 
org.xhtmlrenderer.css.parser.CSSParser.stylesheet(CSSParser.java:159)

      at 
org.xhtmlrenderer.css.parser.CSSParser.parseStylesheet(CSSParser.java:89)

      at 
org.xhtmlrenderer.context.StylesheetFactoryImpl.parse(StylesheetFactoryImpl.java
:78)

      at 
org.xhtmlrenderer.context.StylesheetFactoryImpl.parse(StylesheetFactoryImpl.java
:95)

      at 
org.xhtmlrenderer.context.StylesheetFactoryImpl.getStylesheet(StylesheetFactoryI
mpl.java:174)

      at 
org.xhtmlrenderer.context.StyleReference.readAndParseAll(StyleReference.java:123
)

      at 
org.xhtmlrenderer.context.StyleReference.setDocumentContext(StyleReference.java:
107)

      at 
org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:175)

      at 
org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:142)

Original comment by johannes...@gmail.com on 20 Oct 2011 at 11:29

GoogleCodeExporter commented 8 years ago
Also happening here:

What steps will reproduce the problem?
- Trying to parse an HXTML referencing to an external CSS, using the following 
code snippet:

String xhtml = "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><link 
rel=\"stylesheet\" type=\"text/css\" href=\"C:\mystyle.css\" 
media=\"print\"/></head><body><p>SOME TEXT HERE</p></body></html>";
DocumentBuilder builder = 
DocumentBuilderFactory.newInstance().newDocumentBuilder();
builder.setEntityResolver(FSEntityResolver.instance());
Document document = builder.parse(new ByteArrayInputStream(xhtml.getBytes()));
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(document, null);

What is the expected output? What do you see instead?
java.io.IOException: Stream closed
    at java.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:134)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:256)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
    at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
    at java.io.InputStreamReader.read(InputStreamReader.java:167)
    at org.xhtmlrenderer.css.parser.Lexer.zzRefill(Lexer.java:1634)
    at org.xhtmlrenderer.css.parser.Lexer.yylex(Lexer.java:1865)
    at org.xhtmlrenderer.css.parser.CSSParser.next(CSSParser.java:1798)
    at org.xhtmlrenderer.css.parser.CSSParser.la(CSSParser.java:1810)
    at org.xhtmlrenderer.css.parser.CSSParser.stylesheet(CSSParser.java:159)
    at org.xhtmlrenderer.css.parser.CSSParser.parseStylesheet(CSSParser.java:89)
    at org.xhtmlrenderer.context.StylesheetFactoryImpl.parse(StylesheetFactoryImpl.java:78)
    at org.xhtmlrenderer.context.StylesheetFactoryImpl.parse(StylesheetFactoryImpl.java:95)
    at org.xhtmlrenderer.context.StylesheetFactoryImpl.getStylesheet(StylesheetFactoryImpl.java:174)
    at org.xhtmlrenderer.context.StyleReference.readAndParseAll(StyleReference.java:123)
    at org.xhtmlrenderer.context.StyleReference.setDocumentContext(StyleReference.java:107)
    at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:175)
    at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:142)
    at au.gov.djag.lifelink.documentgeneration.flyingsaucer.PdfGenerator.generatePdf(PdfGenerator.java:32)
    at au.gov.djag.lifelink.documentgeneration.tinymce.DocumentGenerationPage$2.onSubmit(DocumentGenerationPage.java:148)
    at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1561)
    at org.apache.wicket.markup.html.form.Form.process(Form.java:958)
    at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:920)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:182)
    at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
    at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
    at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
    at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
    at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1436)
    at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
    at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:484)
    at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:317)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:619)

What version of the product are you using? On what operating system?
Version R8. System Windows 7.

Original comment by duslo...@gmail.com on 8 Nov 2011 at 1:01

GoogleCodeExporter commented 8 years ago
Also happening here:

java.io.IOException: Stream closed
    at java.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:134)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:256)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
    at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
    at java.io.InputStreamReader.read(InputStreamReader.java:167)
    at org.xhtmlrenderer.css.parser.Lexer.zzRefill(Lexer.java:1634)
    at org.xhtmlrenderer.css.parser.Lexer.yylex(Lexer.java:1865)
    at org.xhtmlrenderer.css.parser.CSSParser.next(CSSParser.java:1798)
    at org.xhtmlrenderer.css.parser.CSSParser.la(CSSParser.java:1810)
    at org.xhtmlrenderer.css.parser.CSSParser.stylesheet(CSSParser.java:159)
    at org.xhtmlrenderer.css.parser.CSSParser.parseStylesheet(CSSParser.java:89)
    at org.xhtmlrenderer.context.StylesheetFactoryImpl.parse(StylesheetFactoryImpl.java:78)
    at org.xhtmlrenderer.context.StylesheetFactoryImpl.parse(StylesheetFactoryImpl.java:95)
    at org.xhtmlrenderer.context.StylesheetFactoryImpl.getStylesheet(StylesheetFactoryImpl.java:174)
    at org.xhtmlrenderer.context.StyleReference.readAndParseAll(StyleReference.java:123)
    at org.xhtmlrenderer.context.StyleReference.setDocumentContext(StyleReference.java:107)
    at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:175)
    at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:142
...
java.io.IOException: Stream closed
    at java.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:134)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:256)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
    at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
    at java.io.InputStreamReader.read(InputStreamReader.java:167)
    at org.xhtmlrenderer.css.parser.Lexer.zzRefill(Lexer.java:1634)
    at org.xhtmlrenderer.css.parser.Lexer.yylex(Lexer.java:1865)
    at org.xhtmlrenderer.css.parser.CSSParser.next(CSSParser.java:1798)
    at org.xhtmlrenderer.css.parser.CSSParser.la(CSSParser.java:1810)
    at org.xhtmlrenderer.css.parser.CSSParser.stylesheet(CSSParser.java:159)
    at org.xhtmlrenderer.css.parser.CSSParser.parseStylesheet(CSSParser.java:89)
    at org.xhtmlrenderer.context.StylesheetFactoryImpl.parse(StylesheetFactoryImpl.java:78)
    at org.xhtmlrenderer.context.StylesheetFactoryImpl.parse(StylesheetFactoryImpl.java:95)
    at org.xhtmlrenderer.context.StylesheetFactoryImpl.getStylesheet(StylesheetFactoryImpl.java:174)
    at org.xhtmlrenderer.context.StyleReference.readAndParseAll(StyleReference.java:123)
    at org.xhtmlrenderer.context.StyleReference.setDocumentContext(StyleReference.java:107)
    at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:175)
    at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:142)

Version R8. System solaris 10.

Note that the "org.xhtmlrenderer.context.StylesheetFactoryImpl.parse" has a 
"e.printstacktrace()" that outputs the error to standard system out at line 81.

Original comment by mul...@gmail.com on 13 Jan 2012 at 9:16

GoogleCodeExporter commented 8 years ago
Having the same problem here but I found a workaround.
In my case, the path was correct but I didn't have a scheme at the beginning of 
it.

On a Linux system,I was using: 
href="/tmp/path/to/file/default.css"

Pre-pending the scheme did the trick.
href="file:///tmp/path/to/file/default.css"

Original comment by bsout...@prismhr.com on 29 May 2012 at 12:17