• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

applet and servlet communication error: java.io.EOFException

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My environment: Applet is in Apache2(redhat9), Servlet is supported by Tomacat4.1.30 From website, Applet sends a filename to servlet, servlet reads this file line by line (each line contains three data, like 3.45 4.56 -1.23), and change each line to a data array, then send the data array back to Applet by serialized object and post method.

Problem: the applet got the error:java.io.EOFException
If servlet only reads line(inBuff.readLine),comments the part that converts each line to the data array(see my code below), no error. If adding this part, get the above error. Why? Is there any class or method not supported by Tomcat servlet in my code? Thansk for any help!!

Servlet side code to read the file:

void readdata (long arg5){ /**arg5 is the file name from applet**/

char[] tempchar={'0','0','0','0','0','0','0'};

File ff=new File(filepath+Long.toString(arg5));

/******begin reading data into the float array channel********/

try{

if(ff.exists()){

try{

BufferedReader inBuff=new BufferedReader(new FileReader(filepath+Long.toString(arg5)));

inBuff.readLine();//read the first line of DAQ file

for(int i=0;i<datanum;i++){

String temp=inBuff.readLine();
int k=0,m=0;
/***the part to conver each line to the data array***/

//for(int j=0;j<temp.length();j++){

//if(temp.charAt(j)!=' '&&temp.charAt(j)!='\t'){

//tempchar[k]=temp.charAt(j);

//k++;

//if(j==temp.length()-1){

//String s=String.copyValueOf(tempchar);

//float f=Float.parseFloat(s);

//channel3[i][m]=f;
//channel3[i][m]=0;

//}

//}

//else{

//String s=String.copyValueOf(tempchar);

//float f=Float.parseFloat(s);

//channel3[i][m]=f;
//channel3[i][m]=0;

//m++;k=0;

//tempchar[6]='0';

//}

//}

}

inBuff.close();

}catch(FileNotFoundException e)

{df.servleterror2=true;df.servleterrormessage2=e.toString();}
catch(IOException e)

{df.servleterror2=true;df.servleterrormessage2=e.toString();}

}

else{

for(int p=0;p<channelnum3;p++)

for(int q=0;q<datanum;q++)

channel3[q][p]=0;

}

}catch(SecurityException e)
{df.servleterror2=true;df.servleterrormessage2=e.toString();}

}/****end of readdata*****/
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using a the CODE tag below the Add Reply button to post code in a thread.

The CODE tag will retain your formatting like indentation, which makes the code easier to read.

Unfortunately, I can't really read and understand your code the way that it is posted.

However, it appears that you are not checking when you reach the end of the file.

That is what an EOFException is. End Of File Exception.

Good Luck

Mark
 
may Lee
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I didn't check the end of the file. In fact, I know there are total 401 lines in each file, first line is date, no need to convert, just convert the other 400 lines to data array, so when I use to readLine(), I set the datanum to be 400 here (for(int i=0;i<datanum;i++){) so no need to know if it is file end or not, then I close the inbuff.close()

In this case, how could I get the error End of File Exception?
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But obviously it is reaching the end of the file. Set it to two hundred if you have to have a number, and see if you get the error too.

Maybe there is something wrong with the file, or there aren't carriage returns, or something such that you get your EOFException.

Basically Java will not throw an EOFException unless it reached the end of the file.

Good Luck

Mark
 
may Lee
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I set to 200, still the same error.
I found that:

Each time I comment out the part that converts each line to data array, no EOFException error at applet side, it means the function of readLine() is working well.

Each time I add the part of converting each line to data array, it shows EOFException on applet side. So it means the part of converting is not working with applet and servlet communication? But I cannot find what is wrong Any suggestion please?


Servlet side code to read the file:

void readdata (long arg5){ /**arg5 is the file name from applet**/
char[] tempchar={'0','0','0','0','0','0','0'};
File ff=new File(filepath+Long.toString(arg5));
/******begin reading data into the float array channel********/
try{
if(ff.exists()){
try{
BufferedReader inBuff=new BufferedReader(new
FileReader(filepath+Long.toString(arg5)));
inBuff.readLine();//read the first line of DAQ file
for(int i=0;i<datanum;i++){
String temp=inBuff.readLine();
int k=0,m=0;
/***the part to conver each line to the data array***/
/***if I commnet out this part, no error***/
// for(int j=0;j<temp.length();j++){
// if(temp.charAt(j)!=' '&&temp.charAt(j)!='\t'){
// tempchar[k]=temp.charAt(j);
// k++;
// if(j==temp.length()-1){
// String s=String.copyValueOf(tempchar);
// float f=Float.parseFloat(s);
// channel3[i][m]=f;
// }
// }
// else{
// String s=String.copyValueOf(tempchar);
// float f=Float.parseFloat(s);
// channel3[i][m]=f;
// m++;k=0;
// tempchar[6]='0';
// }
// }
}
inBuff.close();
}catch(FileNotFoundException e)
catch(IOException e)
else{
for(int p=0;p<channelnum3;p++)
for(int q=0;q<datanum;q++)
channel3[q][p]=0;
}
}catch(SecurityException e)
}/****end of readdata*****/
 
may Lee
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry the code is not clear in last post.

 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A better way to read a line input stream is:


Not everyone likes doing an assignement inside a "when" condition, but it's a little tidier than the alternatives. Also, I'm not sure all input streams throw end of file exceptions, but they all return null when attempting to read past the end of fileXXXX data.
[ June 22, 2004: Message edited by: Tim Holloway ]
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim's method is preferred.

Also, for a way to debug to see how many lines it does read,

you can put a

System.out.println("Count: " + i);

this way you can see how many times it goes through the loop before hitting the End of File.

I really think that the file must not have carriage returns or line feeds, so it thinks that there is only one line.

But that is a complete guess.

Good Luck.

Mark
 
may Lee
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried Tim's method, same error when I add the convert part.
I tried to only use readLine() and display the line, it works, I mean, it read line by line.
Also when I use applet to do the servlet part function, it is working with the same code. So there must be some secret error not found. Keep working to find it.

I am wondering, is there a way to do step by step debug of applet and servlet communication programs?
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What ahppened when you tried this?


System.out.println("Count: " + i);

this way you can see how many times it goes through the loop before hitting the End of File.




What was the last count given?

Mark
 
may Lee
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found the error, it is array dimention mistake. I use channel3[400][3] in the part that convert string to float data, after I write the new part,I define it as channel3[3][400], but I still copy the part of converting, so get error. Interesting thing is, it told me EOFException error, not array index error, which led me to think about my file end,...
anyway, found the misktake finally!!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic