• Post Reply Bookmark Topic Watch Topic
  • New Topic

readLine(byte b[], int off, int len) method of Servlet InputStream returns -1

 
subba Sathi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please see the following code




We are trying to add a file as attachment in one of our applications ,,
I am getting invalid input data stream and the same code works fine in another application.

Please advise if anyone has encountered same issue before..

Thanks
Satya
 
subba Sathi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting null for firstLine

String firstLine = inputStream.readLine();

result=-1 for the first time itself..

result = this.readLine(buf, 0, buf.length);

I am trying to add a word document and is causing this error. I tried with a text file also.

Please let me know what I am doing wrong here..

 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
readLine returns null and read returns -1 if there simply is nothing to read.
 
subba Sathi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:readLine returns null and read returns -1 if there simply is nothing to read.


I am getting the same for reading a non empty file.

FIle is not empty and fails at the first read..

Thanks

 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show us the code for the readLine method as called in "this.readLine(buf, 0, buf.length);" ? Perhaps result is 0 for some reason; that will also cause the StringBuffer to remain empty.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!