Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / March 2005

Tip: Looking for answers? Try searching our database.

Writing to byte[] array

Thread view: 
Frank - 14 Mar 2005 14:59 GMT
Hello,

I'm doing a self-study course on Java, but as an exercise I have to make a
webserver that works as follows:
A client logs onto the webserver, get a list of available dirs from the
server, clicks a dir.
The server must then show all JPG files that are inside that dir as a
slideshow.

The only thing that I don't know how to do is:
In the server I have to loop over all files, store the file length into a
4-byte byte-array and send it to the client.
How can I store the file length into a 4-byte byte-array ? I really don't
know how to do that.
(I'm sure there are other possibilities, but this is the way it must be
done)

Can someone help ?

thnx in advance,

greets
Frank
Andrey Kuznetsov - 14 Mar 2005 18:01 GMT
> How can I store the file length into a 4-byte byte-array ? I really don't
> know how to do that.

see DataOutput#writeInte();

Signature

Andrey Kuznetsov
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities

Oscar kind - 15 Mar 2005 20:22 GMT
>> How can I store the file length into a 4-byte byte-array ? I really don't
>> know how to do that.
>
> see DataOutput#writeInte();

Or, if you don't want to set up a stream to a 4-byte buffer:
   int source = 1234;
   byte[] dest = new byte[4];
   dest[0] = (byte)(source && 0x000000FF);
   dest[1] = (byte)((source && 0x0000FF00) >> 8);
   dest[2] = (byte)((source && 0x00FF0000) >> 16);
   dest[3] = (byte)((source && 0xFF000000) >> 24);

In more complex cases setting up a data stream to a byte buffer is easier,
IMHO.

Signature

Oscar Kind                                    http://home.hccnet.nl/okind/
Software Developer                    for contact information, see website

PGP Key fingerprint:    91F3 6C72 F465 5E98 C246  61D9 2C32 8E24 097B B4E2



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.