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