<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Platform-dependent files?</title>
		<link>http://www.allegro.cc/forums/view/588082</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 20 Oct 2006 17:50:23 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi all,</p><p>I have tried making a small Allegro app for my Java game that takes a bitmap and writes out all of the coordinates of non-white pixels to a file. It writes the pixels in pairs of two integers, no spaces, no tabs, no newlines, just integers. The app runs fine (after some debugging of course), so I went on to try and read the file in my Java game, however the results seem very wrong. When I should get a pair of 4 4 I get 67108864 67108864, and so on. I tried reading the file using the Allegro app and the numbers come out fine (eexcept for the last pair that comes twice for some reason, but I think I&#39;m doing wrong EOF checks). The application is running on an Ubuntu Linux and the Java game is running on Windows XP, so I thought it might be some endian problems, and here comes my problem: How can you choose different byte order in Java for reading files? I would also be glad for any other endian-issues feedback/random info.</p><p>(I&#39;m using simple fwrite-fread in order to write and check the file, and DataInputStream in order to read it, oh, and both applications read/write the same number of pairs)</p><p>Cookies promised.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ron Ofir)</author>
		<pubDate>Tue, 17 Oct 2006 23:10:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I wouldn&#39;t rely on any specific format when using DataInputStream. You should use your own stream handler if you make any assumptions.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Fladimir da Gorf)</author>
		<pubDate>Tue, 17 Oct 2006 23:26:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I agree with Fladimir; DataInputStream should probably only be used with files created by DataOutputStream.</p><p>However you should be able to find the format used with Google. Assuming it&#39;s simply a big endian format, you can use the relevant Allegro functions, for example
</p><div class="source-code snippet"><div class="inner"><pre><span class="p">#include &lt;allegro.h&gt;</span>

<span class="k1">int</span> main<span class="k2">(</span><span class="k1">int</span> argc, <span class="k1">char</span><span class="k3">*</span> argv<span class="k2">[</span><span class="k2">]</span><span class="k2">)</span>
<span class="k2">{</span>
  <a href="http://www.allegro.cc/manual/PACKFILE" target="_blank"><span class="a">PACKFILE</span></a><span class="k3">*</span> f <span class="k3">=</span> <a href="http://www.allegro.cc/manual/pack_fopen" target="_blank"><span class="a">pack_fopen</span></a><span class="k2">(</span>argv<span class="k2">[</span><span class="n">1</span><span class="k2">]</span>, F_WRITE<span class="k2">)</span><span class="k2">;</span>
  <span class="k1">int</span> i <span class="k3">=</span> <span class="n">4</span><span class="k2">;</span>
  <a href="http://www.allegro.cc/manual/pack_mputl" target="_blank"><span class="a">pack_mputl</span></a><span class="k2">(</span>i, f<span class="k2">)</span><span class="k2">;</span>
  <a href="http://www.allegro.cc/manual/pack_fclose" target="_blank"><span class="a">pack_fclose</span></a><span class="k2">(</span>f<span class="k2">)</span><span class="k2">;</span>
  <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="k2">}</span> <a href="http://www.allegro.cc/manual/END_OF_MAIN" target="_blank"><span class="a">END_OF_MAIN</span></a><span class="k2">(</span><span class="k2">)</span>
</pre></div></div><p>
produces a file with a 4 in it, that can be read by this program
</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td>import java.io.<span class="k3">*</span><span class="k2">;</span></td></tr><tr><td class="number">2</td><td>&#160;</td></tr><tr><td class="number">3</td><td><span class="k1">class</span> Fr</td></tr><tr><td class="number">4</td><td><span class="k2">{</span></td></tr><tr><td class="number">5</td><td>    <span class="k1">public</span> <span class="k1">static</span> <span class="k1">void</span> main<span class="k2">(</span>String<span class="k2">[</span><span class="k2">]</span> args<span class="k2">)</span></td></tr><tr><td class="number">6</td><td>    <span class="k2">{</span></td></tr><tr><td class="number">7</td><td>        System.out.println<span class="k2">(</span>args<span class="k2">[</span><span class="n">0</span><span class="k2">]</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">8</td><td>        <span class="k1">try</span> <span class="k2">{</span></td></tr><tr><td class="number">9</td><td>            FileInputStream is <span class="k3">=</span> <span class="k1">new</span> FileInputStream<span class="k2">(</span>args<span class="k2">[</span><span class="n">0</span><span class="k2">]</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">10</td><td>            DataInputStream ds <span class="k3">=</span> <span class="k1">new</span> DataInputStream<span class="k2">(</span>is<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">11</td><td>            <span class="k1">int</span> i <span class="k3">=</span> ds.readInt<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">12</td><td>            System.out.println<span class="k2">(</span><span class="s">"Answer "</span> <span class="k3">+</span> i<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">13</td><td>        <span class="k2">}</span> <span class="k1">catch</span><span class="k2">(</span>Exception xep<span class="k2">)</span> <span class="k2">{</span>System.err.println<span class="k2">(</span>xep<span class="k2">)</span><span class="k2">;</span><span class="k2">}</span></td></tr><tr><td class="number">14</td><td>    <span class="k2">}</span></td></tr><tr><td class="number">15</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>

Random info: I had leeks for dinner today</p><p>Pete
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Hull)</author>
		<pubDate>Wed, 18 Oct 2006 00:02:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>For general communication between programs made with different languages, I&#39;d use XML.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Fladimir da Gorf)</author>
		<pubDate>Wed, 18 Oct 2006 00:19:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ll check the pack_mputl solution. I don&#39;t want to use XML as it will make the files about 20 times bigger and complicate the writing (not so much, but still).</p><p>BTW, don&#39;t you have to initialize allegro (in console mode, SYSTEM_NONE) in order to use it&#39;s routines?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ron Ofir)</author>
		<pubDate>Wed, 18 Oct 2006 17:24:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>For general communication between programs made with different languages, I&#39;d use A SIMPLE TEXT FILE.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Wed, 18 Oct 2006 19:10:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Java uses big-endian so Peter&#39;s solution works. I&#39;ve just tried it with a couple of things and it looks great (I&#39;ll post screenshots later when I add some more effects).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ron Ofir)</author>
		<pubDate>Wed, 18 Oct 2006 19:22:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I had leeks for dinner today
</p></div></div><p>
Leeks are horrible!<br />Coincidentally, my Grandads vicar steals leeks from the fields.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (James Stanley)</author>
		<pubDate>Fri, 20 Oct 2006 17:50:23 +0000</pubDate>
	</item>
</rss>
