Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (780)
Games in Android Showcase (233)
games submitted by our members
Games in WIP (856)
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 1620 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  

hadezbladez (728 views)
2018-11-16 13:46:03

hadezbladez (363 views)
2018-11-16 13:41:33

hadezbladez (715 views)
2018-11-16 13:35:35

hadezbladez (180 views)
2018-11-16 13:32:03

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

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

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

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

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

nelsongames (2609 views)
2018-04-24 18:14:32
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!