FacebookTwitter
Hatrack River Forum   
my profile login | search | faq | forum home

  next oldest topic   next newest topic
» Hatrack River Forum » Active Forums » Books, Films, Food and Culture » Some Java questions

   
Author Topic: Some Java questions
Hobbes
Member
Member # 433

 - posted      Profile for Hobbes   Email Hobbes         Edit/Delete Post 
OK, first off, I have a rather simple question. Binary files.

I'm trying to do some simple data processing on binary files, basically files that are just data over and over, no headers, no special processing, but not created by Java programs either. So I'm using RandomAccessFile, and using statments like "InFile.readUnsignedShort()". Thing is, it's totally not working. My Java books don't do a very good job covering this subject so I'm hoping some people here know something about reading (I don't even have to write them!) binary files with Java.

My second question is a bit more open ended. For those who remember my problems creating a Web Service, well I think I can now convince my boss to allow me to write a totally Java web service instead of dealing with Perl or PHP, now I do have a book that looks like it covers this pretty well, but before I dive into it, I was hoping for some pointers in the right direction.

What the web service is going to do is convert data. It does it by first getting metadata from the user, then saves that as a file. Then the program will take that file, and the unconverted data from the user, convert it into the new format, and give that to the user. I have written a program that will do that as a non-server application (download the application and run it from your computer) and it has a really nice (I think [Smile] ) user interface developed for it. Where should I start, do you think, and is there any way of using this user interface as part of the web service, or is that just a pipe-dream?

Hobbes [Smile]

Posts: 10602 | Registered: Oct 1999  |  IP: Logged | Report this post to a Moderator
WishfulWiggin
Member
Member # 6823

 - posted      Profile for WishfulWiggin   Email WishfulWiggin         Edit/Delete Post 
Wow, my brain in fried. When I saw the title I thought the thread was about coffee.
Posts: 208 | Registered: Aug 2004  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
Use DataInputStream.

Regarding the web service:

Why does the metadata have to be written as a file?

Also, I thought it had been decided to do this with standard form processing rather than as a web service (which is completely different)?

As far as the GUI goes (assuming you're talking about a graphical UI instead of a programmatic UI), no, you can't reuse it. And you shouldn't. Local application paradigms do not translate well into Web application paradigms. You will, however, be able to use the objects/methods that actually do the processing, assuming you've got those properly separated out so they don't do any of the GUI stuff.

At what stage does the binary processing come into play if you've already written the file format converter?

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Hobbes
Member
Member # 433

 - posted      Profile for Hobbes   Email Hobbes         Edit/Delete Post 
I made the program so you can add on different file conversions, and now I'm trying to add on one for binary files.

DataInputStream? OK, thanks I'll look into it! [Smile]

I kind of figured on the GUI, but I really don't want to re-write it. Like any good programmer, I'm very lazy. [Big Grin]

I did seperate out the GUI and the file processor for this very reason so that's fine. However it totally depends on having a metadata file, I did this because you have to store a lot of metadata and it would be a huge pain if you to re-write it every time. Of course this point becomes kind of mute when you talk about a web version of it, but I designed it as an application first.

quote:
Also, I thought it had been decided to do this with standard form processing rather than as a web service (which is completely different)?
Well we also decided to use Perl, and we're changing that too. [Smile] If I wrote the whole thing as one Java program instead of partially in Perl and whatnot, what's the best way to do it?

Hobbes [Smile]

Posts: 10602 | Registered: Oct 1999  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
If I recall correctly, the original intent was for people to be able to go to a page and have it do the processing. If you want them to use a web service, that will require a different application which they would need to run rather than their browser (well, you could write it into a web service, then hook the server side code to display it to the browser into the web service, but that's likely overkill in this situation).

If you wrote your processing code correctly, it should be easy to adapt to using in-memory metadata instead of in-file metadata. That would be the standard way (and far better, file IO is expensive) to do it.

One thing that would potentially allow you to reuse your GUI code, but I don't think you're technically up to, is to actually do the web service thing, then take the view classes from the GUI app and hook them into a lightweight backend which uses the web service.

Making a working processing apparatus into a web service is a matter of hours for an experienced programmer (and can be done the quick and dirty way in minutes, often); while this is certainly good experience for you I hope your employer understands things could progress significantly faster.

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Hobbes
Member
Member # 433

 - posted      Profile for Hobbes   Email Hobbes         Edit/Delete Post 
So Java doesn't seem to read binary data the same way as Windows wants it to, is this true? I've done some experimenting and it's reading in the bytes in the opposite order that they're stored in. Now the way they're stored is one of two ways, a C++ program writting variables directly to file (ofstream.write(&short,2) or something) and also a binary file I've been working with that I got from NGDC (in other words, a file that came from someone else, so I didn't create it). Now you can tell me C++ just does it wrong and that's nice, but it needs to be compatiable to this other file type. Any way to switch byte order or am I pretty much screwed?

Hobbes [Smile]

Posts: 10602 | Registered: Oct 1999  |  IP: Logged | Report this post to a Moderator
Hobbes
Member
Member # 433

 - posted      Profile for Hobbes   Email Hobbes         Edit/Delete Post 
OK, any way to switch byte order without reading into byte array and then switching them and then reading them into a new variable? In other words, any way of getting the built in byte reader for the file to do it different?

Hobbes [Smile]

Posts: 10602 | Registered: Oct 1999  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
Hobess, what you're encountering is called endian-ness.

This page should educate you on the differences and solutions in java: http://mindprod.com/jgloss/endian.html

Your professors have never mentioned endian-ness? Note to self: do not attend computing classes at Purdue.

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Hobbes
Member
Member # 433

 - posted      Profile for Hobbes   Email Hobbes         Edit/Delete Post 
I know what it's called, I just didn't know how Java implemented it.

Hobbes [Smile]

Posts: 10602 | Registered: Oct 1999  |  IP: Logged | Report this post to a Moderator
   

   Close Topic   Feature Topic   Move Topic   Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:


Contact Us | Hatrack River Home Page

Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2