my dog learned polymorphism
The moose likes Sockets and Internet Protocols and the fly likes Byte order and file transference. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Byte order and file transference." Watch "Byte order and file transference." New topic

Byte order and file transference.

Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
I need some help about deciding how an application that transfers files from one computer to another tackles with the issue of byte order.

I am using NIO.
Say Alice is sending a file to Bob. Say Alice's computer is little endian, but Bob's is big endian. I have heard that "well mannered" applications should transmit in network order. The simplest solution would be that the application sending the files would transmit before the transmition a code representing the byte order of its machine. Then it sends the file content using that byte order. Bob's machine should only convert the data to its corresponding byte order if the received byte order does not match its own.
In this way we can avoid a conversion in the sending machine, and probably conversions in the receiving machines given that most of the computers are based on little endian processors.

Dou you think it is ok to contravene the network order rule?


SCJP2. Please Indent your code using UBB Code
leon fan

Joined: Aug 02, 2004
Posts: 19
I don't think you need do any process relative byte order especially for many binary files.

If you want to deal text file, it's better to put byte order information into that text file.
leon fan

Joined: Aug 02, 2004
Posts: 19
If that text is unicode.
I agree. Here's the link:
subject: Byte order and file transference.
It's not a secret anymore!