aspose file tools*
The moose likes I/O and Streams and the fly likes java.io.IOException: Premature EOF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "java.io.IOException: Premature EOF" Watch "java.io.IOException: Premature EOF" New topic
Author

java.io.IOException: Premature EOF

Eva Lin
Greenhorn

Joined: Jan 10, 2010
Posts: 9
Hi guys!

I am getting a java.io.IOException: Premature EOF - for some urls, yet different on each execution - after executing the following function. Any ideas?

Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8968
    
    9

You didn't give us the exception stack trace, which is a vital piece of debugging information, but your problem sounds like this post


[How To Ask Questions On JavaRanch]
Eva Lin
Greenhorn

Joined: Jan 10, 2010
Posts: 9
Joe Ess wrote:You didn't give us the exception stack trace, which is a vital piece of debugging information, but your problem sounds like this post


Thanks for your reply.
I am not enough familiar with the debugging process. So i would appreciate if you could provide me further information on how to carry out the following change: "...not to read using BufferedReader but one byte at a time and put the read in a try-catch for EOFException. ".

Kind regards,
Eva Lin.
Eva Lin
Greenhorn

Joined: Jan 10, 2010
Posts: 9
No one?

Please, tell me what you mean when you talk about "I think the straight forward solution will be, not to read using BufferedReader but one byte at a time and put the read in a try-catch for EOFException."! And how can I give you the exception stack trace?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8968
    
    9

Eva Lin wrote:And how can I give you the exception stack trace?


Introduction to Java Stack Traces
Evan Caballero
Ranch Hand

Joined: Dec 10, 2009
Posts: 59
Please, tell me what you mean when you talk about "I think the straight forward solution will be, not to read using BufferedReader but one byte at a time and put the read in a try-catch for EOFException."! And how can I give you the exception stack trace?


instead of using



try



where inputChar is declared as a int or a char.
Eva Lin
Greenhorn

Joined: Jan 10, 2010
Posts: 9
Okay. Here we are!

I added the following command (i.e. ex.printStackTrace();) inside the catch block in order to show you the stack trace.
I really concern about the behavior of my application because the "stuck" comes from different urls in each execution...
Also, it is worth to notice that, after the installation of netBeans and the app-execution in a new machine, the app completed successfully!
But, this doesn't happen again! What the !@#$ is going on? How can I solve the bug?
Some guys told me about Thread.wait(1000); function but neither this worked out!
@Evan Caballero: can you explain with details what you mean?

Evan Caballero
Ranch Hand

Joined: Dec 10, 2009
Posts: 59
try this :

Eva Lin
Greenhorn

Joined: Jan 10, 2010
Posts: 9
Nope.
Exactly the same behavior...
About 4 out of 84 pages (urls) refuse to completely downloaded....
No hope....
Evan Caballero
Ranch Hand

Joined: Dec 10, 2009
Posts: 59
If the purpose of your application is to "download" pages over HTTP, you should take a look at HttpURLConnection. There are plenty of examples on the internet to show you how to use it.
Eva Lin
Greenhorn

Joined: Jan 10, 2010
Posts: 9
Evan Caballero wrote:If the purpose of your application is to "download" pages over HTTP, you should take a look at HttpURLConnection. There are plenty of examples on the internet to show you how to use it.


Yes. This is actually what i want...
Do you mean a modification like this one:


Evan Caballero
Ranch Hand

Joined: Dec 10, 2009
Posts: 59
HttpURLConnection conn = (HttpURLConnection) x.openConnection(); is better I think ;)
Eva Lin
Greenhorn

Joined: Jan 10, 2010
Posts: 9
No.
Neither this does work...
As a newbie, I am not familiar with the stack trace.
Is there any way of using this kind information?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8968
    
    9

Evan Caballero wrote:HttpURLConnection conn = (HttpURLConnection) x.openConnection(); is better I think ;)


To my knowledge, all the Java API HTTP/HTTPS classes use the same sun.* classes under the covers. If you have a problem with one, you'll have a problem with all.
this guy looks like he solved the problem by switching to the Apache HttpClient.
 
Consider Paul's rocket mass heater.
 
subject: java.io.IOException: Premature EOF