8

I am trying to download a zip file but I get a Stream Closed Exception. When i use using swing gui it get this erro but if i use console there is no problem. Why do I get this exception? How can I fix it?

This is my code:

URLConnection conn = url.openConnection();
InputStream in = conn.getInputStream();
FileOutputStream out = new FileOutputStream(destination.getPath());
byte[] b = new byte[1024];
int count;

while ((count = in.read(b)) >= 0) {
    out.write(b, 0, count);
}
out.flush();
out.close();
in.close();
OptionPane.showMessageDialog(null, "Download is finished");
} catch (HttpUnauthorizedException e) {
    JOptionPane.showMessageDialog(null, "Proxy or Server Authentication Required");
} catch (IOException e) {
    System.out.println(e.getMessage());
}

this is stack trace

java.io.IOException: Stream closed.
at java.net.PlainSocketImpl.available(PlainSocketImpl.java:428)
at java.net.SocketInputStream.available(SocketInputStream.java:217)
at java.io.BufferedInputStream.read(BufferedInputStream.java:321)
at weblogic.net.http.KeepAliveStream.read(KeepAliveStream.java:86)
at java.io.FilterInputStream.read(FilterInputStream.java:90)
at be.azvub.ext.bcfidownloder.Download.downloadZipFile(Download.java:130)
at be.azvub.ext.bcfidownloder.Download.authorize(Download.java:91)
at be.azvub.ext.bcfidownloder.BcfiDownloadPanel$4.mouseClicked(BcfiDownloadPanel.java:110)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:212)
at java.awt.Component.processMouseEvent(Component.java:5520)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3129)
at java.awt.Component.processEvent(Component.java:5282)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3984)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3819)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3901)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1791)
at java.awt.Component.dispatchEvent(Component.java:3819)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at be.azvub.webutil.gui.WebEventQueue.dispatchEvent(WebEventQueue.java:34)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
6
  • Where do you get the exception?
    – Jon Skeet
    Jan 23, 2012 at 8:03
  • 12
    stack trace please Jan 23, 2012 at 8:04
  • I get exception here: while ((count = in.read(b)) >= 0) { out.write(b, 0, count); }
    – itro
    Jan 23, 2012 at 12:31
  • I did add stack trace: please see above
    – itro
    Jan 23, 2012 at 14:12
  • I use Weblogic, can it be from Weblogic?
    – itro
    Jan 23, 2012 at 14:27

3 Answers 3

5

This exception usually means the connection was closed abruptly. I would look at the logs on the server to see if there was an error.

0

it can be due to JVM delays, It can be caused because of unix/linux operating system's random number generator. You should replace it with /dev/./urandom

This link has more details on it.

http://devcorn.com/java-io-ioexception-stream-closed-no-available-router-to-destination/

0

I solved it when removed this tag of Primefaces from my xhtml.

<p:media ...

source

http://www.primefaces.org/showcase/ui/multimedia/media.xhtml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.