Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (769)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (855)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Binary Data Files  (Read 1583 times)
0 Members and 1 Guest are viewing this topic.
Offline Goika

Senior Newbie

Java games rock!

« Posted 2005-01-26 10:28:59 »

In my application I have begun to use data files as resources in order to read in the game specific data that I need for the app. My question is - is my java code converting the textfiles of data into the correct format as I have ten different .txt files which I convert into binary format but once this is done each of the ten converted data files are slightly bigger than each of the  equivelant .txt files. I realise that the reading in of the data in this format is quicker for the j2me app and that it is better to have all your game data into these data files for localisation and for heap memory etc but I also assumed that the actual size of a converted data file would be smaller than the .txt file it had been converted from?

Is this correct and am I converting the txt files in the correct manner i.e. (I am requiring the text files to be in UTF 8 format):

//Main idea of how the .txt files are being converted

ByteArrayOutputStream bout = new ByteArrayOutputStream();
                 DataOutputStream      dout = new DataOutputStream( bout   );


dout.writeInt( Integer.parseInt(buffer) );




Thanks for any valuable advice
Offline wooD

Senior Newbie

J2ME Developer

« Reply #1 - Posted 2005-01-26 13:06:44 »

This makes sense to me.

1. Writing a UTF may be a little longer because there is string lenth information being transmitted where in your text file this may not be the case. Also, Unicode may be larger than ascii. I don't know the exact format of writeUTF, but my bet is that there is a little bit of overhead.

2. Writing an int may also be longer because to represent the number 9 in ascii only takes 1 byte where as an integer is 4 bytes.  The same goes for 10, 2 bytes in ascii and 4 bytes as an integer. Larger numbers will be larger in ascii, but I find that most of my programming numbers 1-4 digits making the average smaller than 4.

Offline jbanes

JGO Coder

Projects: 1

"Java Games? Incredible! Mr. Incredible, that is!"

« Reply #2 - Posted 2005-01-26 13:34:34 »

What you're writing will be in close to the same format as a text file. The only difference in the text is that there will be an integer stored for length, and a null terminator for backward compatibility. That should only add about 3-5 bytes to the file. Your "writeInt()" call adds another 4 bytes.

Speaking of which, why are you storing both the text and the integer versions? Wouldn't it be more efficient to store just one, then derive the other at runtime?

Java Game Console Project
Last Journal Entry: 12/17/04
Pages: [1]
  ignore  |  Print  

EgonOlsen (1569 views)
2018-06-10 19:43:48

EgonOlsen (1541 views)
2018-06-10 19:43:44

EgonOlsen (1141 views)
2018-06-10 19:43:20

DesertCoockie (1568 views)
2018-05-13 18:23:11

nelsongames (1172 views)
2018-04-24 18:15:36

nelsongames (1549 views)
2018-04-24 18:14:32

ivj94 (2306 views)
2018-03-24 14:47:39

ivj94 (1515 views)
2018-03-24 14:46:31

ivj94 (2602 views)
2018-03-24 14:43:53

Solater (879 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!