473,717 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Java Big Endian to Linux Little Endian problems

5 New Member
I have read a bit about the endian differences, got a couple of jar/libs to help (Android and com.mindprod), but still am not sure how to fix this program that I have (written in JDK 1.4 by someone else who is not here anymore). I have some complicated structures in this program that I don't know how to fix. I have fixed DataInputStream and DataOutputStrea m but using com.mindprod and now have LEDataInput and Output Streams (Little Endian). The purpose is to talk over sockets to a Linux program which is Little Endian, from a Java App which is BigEndian. The structures that I am not sure what to do with are (showing imports): java.io.InputSt ream, java.io.OutputS tream, toByteArray(), java.io.ByteArr ayOutputStream, java.io.ByteArr ayOutputStream, java.io.ObjectI nputStream, java.io.ObjectO utputStream. The program was elegantly written, very complicated, and I am not sure what is going to take more time. Fixing this to talk to Linux (LE), or re-writing parts of it with some of the new stuff in JDK 1.6, Android, etc. Anyone have any suggestions?
Dec 11 '08 #1
8 9991
JosAH
11,448 Recognized Expert MVP
A DataOutputStrea m always writes its data in big endian format. A DataInputStream always reads data in big endian format. If you couple the two streams between two machines there should be no problem at all. If your Linux box expects the data on the wire to be in little endian format don't use a DataOutputStrea m to write to the wire.

kind regards,

Jos
Dec 11 '08 #2
marknvicf
5 New Member
Well, not using DataInput or DataOutputStrea ms means a rewrite of a large and complicated program. In any case com.mindprod has LE versions of those. It's all the others in this program that cause all the problems.

Let me be clear: the Java program was originally developed to run on Solaris(Unix) and communicate with programs(call them simulator programs) on the same - and all are Big Endian. However, there has been a movement thru my company to replace Unix boxes with Linux ones, and the simulator programs have been migrated to Linux, but no one payed attention to the endianness problems. So, I am stuck with BE java not being able to communicate with LE Linux simulators. This also leaves me with a number of streaming formats that don't have LE replacements like DataInput & OutputStreams.

So I am still left wonder what to do.
Dec 12 '08 #3
JosAH
11,448 Recognized Expert MVP
Aren't all those simulator programs (running on those LE Linux boxes now) written using Java? If not I guess your best option is to use that LEDataOutputStr eam to send the data over in little endian format so your Linux (Intel?) boxes can read and understand the data.

Also you might look at the IntBuffer and ByteOrder classes although I don't know of any out-of-the-box solution right now; I'll think about it.

kind regards,

Jos
Dec 12 '08 #4
marknvicf
5 New Member
No, the simulators are written in ADA. They are unchangeable for all intents and purposes. The communication between the java and ada is on two separate sockets with very different formats.Fixing this problem is not as simple as I first thought as I have found inconsistent results when trying various standard coding methods such as swapping bytes etc.

I think this is going to take a while.
Dec 12 '08 #5
JosAH
11,448 Recognized Expert MVP
I bet these ADA programs write binary data back to that Java module? Right? And they write it back in LE form? Can I conclude that all your binary data communication must be done in LE form?

kind regards,

Jos
Dec 13 '08 #6
marknvicf
5 New Member
Yes, you can quite safely say that the data is binary and the Java must use LE binary data methods.

Thanks for helping. If you have any ideas let me know. All the work I've done has only produced inconsistent results so far.
Dec 15 '08 #7
JosAH
11,448 Recognized Expert MVP
@marknvicf
If you can change the Java part of it all you can do the following:

1) find the file src.zip in your JDK installation and extract the files DataOutputStrea m.java and DataInputStream .java

2) Change the writeX and readX methods to their little endian equivalents; this is easy to do when you see the code of the original mehods: change the methods that write/read chars/shorts/ints and longs.

3) Rename the files to LEDataOutputStr eam.java and LEDataInputStre am.java and put them in another package.

4) Everywhere in your Java code use the two new classes (see above) instead of the original classes.

That should do the job ...

kind regards,

Jos
Dec 16 '08 #8
marknvicf
5 New Member
Jos,

Ok, first let me say that the ADA is in Linux on an Intel machine. The Java is on a PC, but I move the jar file to a location on the linux. Ok, here it is. One, there will not be funding to fix the foobar ADA code since they never gave thought to such things as I am encountering now. Everything was great when the ADA was on Unix(Solaris 8) on Unix boxes.

What I am encountering now makes simple endian conversion look like simple math compared to chaos theory. The bit streams are coming over in unknown formats and while I have been able to fix the headers that contain information about the data, I have not been able to fix the data. Simply put, and another extremely intelligent guy at work agrees with me, I would have to convert each packet of data differently (by packet I just mean each short or int or whatever). The overhead would kill the program by slowing it down to a crawl. That doesn't include the method by which the data and handshaking go back and forth. This has to do with the first socket which contains a type of information (can't tell anything about it - proprietary). The second I have had some actual success with as it is completely different from the first one, but still have some bugs to work out.

Endianess has gone from black box to simple as pie, on its own. I could write endian code all day in my sleep now. Too bad this problem is so screwy. I may just tackle the ADA side myself and looking into things like lhost etc. It's better to ask forgiveness than permission has been my motto for, oh, about 26 professional years now.

My aforementioned friend from work said that if I fix this problem, people all over the world will thank me. I think that is just geek talk for getting a white paper out of it.

thanks for all your previous help,

Mark
Feb 16 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

6
9134
by: Patrick | last post by:
Hello all! I am porting an application from C++ to Java and have run into a problem using the DataInputStream reader object. The file I am trying to read in is anywhere from 20 to 60 MB and has a short (25 lines or so) ASCII text "header". The file structure is a double dimensioned array of objects. The ASCII header defines how many "columns" (the first array index) there will be in the file. After the ASCII header, the first value is...
2
29010
by: hicham | last post by:
Hi, I am looking for help, i would like to know how can i use the endian.h and config.h to convert compiled files under solaris from BIG-ENDIAN to compiled files LITTLE-ENDIAN. I am working under linux debian 3.0 woody Thank you for your help.
11
9263
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in C++. I find my self sometimes, trying Object app = Object(); Object *app = Object(); Object app = new Object();
133
8549
by: Gaurav | last post by:
http://www.sys-con.com/story/print.cfm?storyid=45250 Any comments? Thanks Gaurav
30
10937
by: Richard | last post by:
Level: Java newbie, C experienced Platform: Linux and Win32, Intel Another programmer and I are working on a small project together. He's writing a server process in Java that accepts input from processes I've written over a TCP connection. My processes are all written in C; his are all done in Java. He's new to Java, and I've never really used it. My input is basically a stream of 32-bit unsigned integers (e.g., the
5
10216
by: glueless | last post by:
I have to read files from UNIX systems on my PC. The problem is that these binary files are in big endian and I need to convert them. I saw that there are functions ntohl for my visual C++ (4.0), but I don't know in what librarieses these are. I want to kep the code as simple as possible, since I also want to compile it on UNIX systems. Does anyone know of existing functions that do the conversion as I am a bit lazy to program thi myself?
1
9641
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
148
5175
by: BillJosephson | last post by:
Want to do OOP. Does c++ have all the abilities of java, or is it some subset? Thanks...
2
4053
by: Ramesh | last post by:
Hi I have a structure as below on big endian based system typedef struct { unsigned long LedA:5; unsigned long LedB:4; unsigned long LedC:8;
0
9348
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9202
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9109
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9048
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6648
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5970
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4739
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3177
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2545
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.