From: Brett S. <ida...@gm...> - 2010-04-29 06:49:06
|
I got the newest build and get the same thing. I will open a bug report in the morning. Thank you for the response. Brett On Wed, Apr 28, 2010 at 9:05 PM, Ahmed Ashour <asa...@ya...> wrote: > Hi Brett, > > Please test with latest snapshot from > http://build.canoo.com/htmlunit/artifacts, and open a bug report if you > still face the issue. > > Yours, > Ahmed > ---- > Blog: http://asashour.blogspot.com > ------------------------------ > *From:* Brett Shouse <ida...@gm...> > *To:* htm...@li... > *Sent:* Thu, April 29, 2010 3:44:24 AM > *Subject:* [Htmlunit-user] BigContentPage.getContentAsStream() fails > > I am having trouble saving a BigContentPage to a file. I have attached a > test case below with a dummy page (sorry, the real one is not > internet accessible). The result of the click() action is a page with > "Content-Disposition: inline". When I attempt to get the InputStream (using > getContentAsStream), I get a error that the stream is already closed. When I > try to use getContentAsString(), It tells me I should us getInputStream() > (which I assume has been replace with getContentAsStream). > > Any suggestions on how I can address this issue? > > Thank you. > > > > Brett > > > ---Test Case--- > //Start my WebClient > WebClient wc = new WebClient(BrowserVersion.INTERNET_EXPLORER_6); > > //Create attachment list for CollectingAttachmentHandler > List<Attachment> files = new ArrayList<Attachment>(); > > //set an AttachmentHander on the WebClient > wc.setAttachmentHandler(new CollectingAttachmentHandler(files)); > > //Load my page and click the export link > BigContentPage dl = wc.getPage(" > http://www.mypage.com/").getAnchorByText("Export").click<http://www.mypage.com/%22%29.getAnchorByText%28%22Export%22%29.click> > (); > > //It seems I need to call this because the Content-Disposition is "inline" > and not "attachment" > wc.getAttachmentHandler().handleAttachment(dl); > > //Prepare to save the attachment > byte buf[] = new byte[1024]; > int len; > File of = new File("output.csv"); > OutputStream os = new FileOutputStream(of); > > //Get the input stream > InputStream is = > files.get(0).getPage().getWebResponse().getContentAsStream(); > > //Try to read data in and write it to a file > while( (len = is.read(buf)) > 0) { //Exception thrown on this line > os.write(buf,0,len); > } > os.flush(); > os.close(); > is.close(); > ---End Test Case--- > > > ---Start Exception--- > java.io <http://java.io.IO>.IOException: Attempted read on closed stream. > at org.apache.commons.httpclient.AutoCloseInputStream.i > sReadAllowed(AutoCloseInputStream.java:183) > at org.apache.commons.httpclient.AutoCloseInputStream.read( > AutoCloseInputStream.java:107) > at java.io <http://java.io.FilterInputStream.re>.FilterInputStream.read(Unknown > Source) > at com.gargoylesoftware.htmlunit.MemoryInputStream.read( > MemoryInputStream.java:123) > at java.io.FilterInputStream.read(Unknown Source) > ---End Exception--- > > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Htmlunit-user mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/htmlunit-user > > |