File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes transfering arrays over network Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "transfering arrays over network" Watch "transfering arrays over network" New topic
Author

transfering arrays over network

Svend Rost
Ranch Hand

Joined: Oct 23, 2002
Posts: 904
Hi,

Im trying to transfer an 2-dim array of integers from a servlet
to a mobile device.. but how?

My approach:


Now.. how do I proceed?

There is a readInt() method in DataInputStream, which returns the next
byte as an integer. Is that the way to go (I know the array is an 2x10
integer matrix) ? or can I do something more clever

Thanks in advance.

/Svend, who's tired and would like to ZzZzz
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
I dont know whether it's a good approach. But why cant you think about serialization. Serialize the required data send it to the output stream , read it back at other end and deserialize it.


Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24045
    
  13

Serialization will make the data stream bigger and the code slower; for a mobile app, this may not be worth it.

On the server side, you could use a DataOutputStream to write the individual ints of the array, and on the client side, read them using a DataInputStream and plug them into a new array object. You'd have to compute the full size of the data to put into the Content-length header, of course. If the array isn't of a fixed size, you'll want to transmit the array dimensions as the first two integers, then read them first at the client and use them to allocate the array.


[Jess in Action][AskingGoodQuestions]
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Thanks Ernest for a valuable reply.
 
I agree. Here's the link: jrebel
 
subject: transfering arrays over network
 
Similar Threads
Comparing contents of a file with String[]
array
extracting bytes from byte array
How do I indentify an object type ?
How get "base class" of an array?