Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

input and output readers

 
david russell
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey,
does anyone know of a way to break an input stream into chunks, other than to read the stream into a buffer and seach it character by character for delimiters??
ideally i want to be able to read a line of data from a servlet, break the line into its component parts (3 record fields) and then pass this data to a record store, creating a record for each line of data. unfortunately it looks like i will have to read data a character at a time, which will be very slow.
if anyone has any experience or thoughts i would be grateful
cheers
dave
[ February 28, 2002: Message edited by: david russell ]
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have control over what the servlet sends to your device then you could at least use DataOutputStream.writeUTF() (on the servlet-side) and DataInputStream.readUTF() (on the device-side) so that you can read one line at a time. But if you don't have that control, I don't see how it could be done otherwise.
Here is an interesting tech-tip about communication between servlets and devices which shows the concept:CLIENT-SERVER COMMUNICATION OVER HTTP USING MIDP AND SERVLETS
[ February 28, 2002: Message edited by: Valentin Crettaz ]
 
david russell
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dear all,
has anyone tried to implement the client server example that was given in the previous thread?? i keep getting uncaught out of memory exceptions.
basically if i implement the code as it is i get the exception, so i changed the client code from:
int n = din.readInt();
while(n-- > 0){
text.append(din.readUTF() );
text.append( '\n' );
to this:
int n = 10
while(n-- > 0){
text.append(din.readUTF() );
text.append( '\n' );
now it processes the request, but the screen is blank (ie showing no response). however, if you remove the UTF encoding and just read(), the response comes up, albeit just a bunch of numbers. im a bit bamboozled, if anyone can help that would be great!!
dave
 
Eric Giguere
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The example in the Tech Tip works, I know, I wrote it. The initial readInt in the client is important because it tells the client how many strings it should read.
 
david russell
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry folks, i found the problem. my servlet was returning a crazy value for the number of records, thats why it was causing an exception. its sorted now and working fine.
cheers
dave
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic