aspose file tools*
The moose likes Java Micro Edition and the fly likes Best way to transfer data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Best way to transfer data" Watch "Best way to transfer data" New topic
Author

Best way to transfer data

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

I know in general XML is the best way to transfer data. Because in a Servlet what gets returned is text. However in some cases the extra code for reading the XML is unneccessary.
For instance, I have a login screen, and I want to return the user ID and also a list of jobs this user has access to. Usually it won't be more than 5 jobs for a user. So returning XML might be overkill. I was thinking of a straight text with a comma seperator as what should be returned. as in, "727, 12345, 65345, 12124, 62166" where 727 is the user ID and the other 4 are job numbers.
But if I recall the StringTokenizer is not a class in the J2ME jar file.
What do you guys think?
Thanks
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Michael Yuan
author
Ranch Hand

Joined: Mar 07, 2002
Posts: 1427
In your case, the easiest way to go is to use
DataOutputStream.writeInt()
on the server side to write the five integers to the HTTP stream. On the client side, you can retrieve them in order by calling
DataInputStream.readInt()
five times.


Seam Framework: http://www.amazon.com/exec/obidos/ASIN/0137129394/mobileenterpr-20/
Ringful: http://www.ringful.com/
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

So then the first int would have to be how many numbers are coming back, since it is not always just 5 times.
Thanks Michael
Mark
David Price
Ranch Hand

Joined: Jan 22, 2003
Posts: 93
Michael's right. Sometimes it's useful though to have a human-readable data format (e.g. makes testing easier in some cases). In that case, you can just use comma-separated data as you originally described. Although StringTokenizer isn't available, it's little extra work to use String's indexOf(',') and substring methods. You'd probably also take advantage of String's trim() method to get rid of extra whitespace.
Niklas Junel
Greenhorn

Joined: Oct 12, 2002
Posts: 17
I used a comma-separated txt-file for my j2me, when I read it in the midlet I read one character at a time, in that way I could check for a comma, if I found one, I knew the next "job" was up!
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

Thanks Niklas, but this thread is almost two years old, and two jobs ago.

Mark
Mateen Dar
Ranch Hand

Joined: Jan 14, 2005
Posts: 55
i faced the same problem . their is no split function in j2me. so i just wrote my own function thata takes a string and a delimiter. about 5 lines of code. thats all.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

OK, if there are any statements or questions, please create a new thread.

Don't resurrect this two year old thread, Or I will delete it.

Not because I am a Sheriff, but because I started the thread in the first place back then.

Mark
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Best way to transfer data