This discussion is archived
0 Replies Latest reply: Jan 26, 2010 2:49 PM by 807580 RSS

java.io.IOException: Premature EOF

807580 Newbie
Currently Being Moderated
Hi guys!

I am getting a java.io.IOException: Premature EOF error in some urls (usually, the ones with a huge content), after executing the following peace of code. Any ideas?
public static void urlReader(String url, String path, String fileName) {
        String inputLine = null;
        
        URL x = null;
        BufferedReader in = null;
        
        createFile(path, fileName);

        try {
            // Create file
            FileWriter fwstream = new FileWriter(path + fileName);
            BufferedWriter out = new BufferedWriter(fwstream);

            x = new URL(url);
            in = new BufferedReader(new InputStreamReader(x.openStream()));

            while ((inputLine = in.readLine()) != null) {

                if (inputLine.length() > 0) {
                    //System.out.println(inputLine + "\n");
                    out.write(inputLine + "\n");
                }
            }

            // Close the input stream
            in.close();

            // Close the output stream
            out.close();
        } catch (IOException ex) {
            System.out.println(ex);
            System.out.println("Application aborted while function \"urlReader();\" was executing!");
            System.out.println("url = \"" + url + "\"\n");
            System.out.println("inputLine = \"" + inputLine + "\"\n");
            //System.exit(-1);
        }
    }
I am quoting you the stack trace...
As a newbie, I am not familiar with it.
Is there any way of using this kind information?
run:
Application aborted while function "urlReader();" was executing!
java.io.IOException: Premature EOF
java.io.IOException: Premature EOF
        at sun.net.www.http.ChunkedInputStream.readAheadBlocking(ChunkedInputStream.java:538)
        at sun.net.www.http.ChunkedInputStream.readAhead(ChunkedInputStream.java:582)
        at sun.net.www.http.ChunkedInputStream.read(ChunkedInputStream.java:669)
        at java.io.FilterInputStream.read(FilterInputStream.java:116)
        at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:2512)
        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 java.io.BufferedReader.fill(BufferedReader.java:136)
        at java.io.BufferedReader.readLine(BufferedReader.java:299)
        at java.io.BufferedReader.readLine(BufferedReader.java:362)
        at x.application.urlReader(application.java:429)
        at x.application.downloadPages(application.java:410)
        at x.application.main(application.java:46)
Java Result: -1
BUILD SUCCESSFUL (total time: 2 minutes 10 seconds)