Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
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 989 times)
0 Members and 1 Guest are viewing this topic.
Offline Goika

Senior Newbie




Java games rock!


« Posted 2005-01-26 11: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.writeUTF(buffer);

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

dout.flush();

bout.reset();

dout.close();


Thanks for any valuable advice
Offline wooD

Senior Newbie




J2ME Developer


« Reply #1 - Posted 2005-01-26 14: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 14: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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (14 views)
2014-07-30 21:08:39

Riven (21 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (29 views)
2014-07-23 21:07:15

Riven (30 views)
2014-07-23 20:56:16
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org 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‑gaming.org
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!