Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (777)
Games in Android Showcase (231)
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  
  creating an image from recordstore ...  (Read 2191 times)
0 Members and 1 Guest are viewing this topic.
Offline Serethos

Junior Devvie

Java games rock!

« Posted 2005-02-16 06:02:28 »

i have the following task:
an image file gets read via http-connection from a server. this byte-array is written to a recordstore and loaded for creating (restoring) the image.

theoretically this works fine. i got real devices and emulators which perform this without any issues but others seem to have quite big problems creating the image from recordstore.
i am very sure that the bytes get read from server and written into recordstore properly (number of bytes is correct, i can output the png-header etc).

first, the code to read and create the image:

public static Image getImage(String recordStoreName) throws RecordStoreFullException, RecordStoreNotFoundException, RecordStoreException, IOException
        RecordStore store = RecordStore.openRecordStore(recordStoreName, false);
        // input streams
        ByteArrayInputStream bais = new ByteArrayInputStream(store.getRecord(1));
        DataInputStream in               = new DataInputStream(bais);
        // reading length of data
        int imageDataLength = in.readInt();

        byte[] rawData = new byte[imageDataLength];, 0, rawData.length);
        return Image.createImage(rawData, 0, imageDataLength);

the only modification ill do is to write an integer value at the beginning of the recordstore to measure the length of bytes to come.

the results are very different on phones:
sharp gx10 does it with no problems, others just hang or seem to have problems with creating the image from png data
Image.createImage(rawData, 0, imageDataLength);

there ill get BadArgumentExceptions (though im sure the png data is correct), EofExceptions (huh?) or the image is just not displayable.

any hints, comments, tips ?!
Offline shmoove

Junior Devvie


« Reply #1 - Posted 2005-02-16 06:42:40 »

Are you sure that:
1, 0, rawData.length); 

is actually reading in all the data?
Try checking the return value of that method and see if it's actually the size of the data.


I would also try and make sure that the byte array contains the correct data by packagind the same image in the jar, opening it with getResourceAsStream and comparing it the the rawData array.
Offline Serethos

Junior Devvie

Java games rock!

« Reply #2 - Posted 2005-02-16 11:27:34 »

oohoo, i found the mistake. i am the error.  Embarrassed
today i learned the rule again: RTFM!

the problem was indeed that the data wasnt load properly from the server. i used an inputstream with the read(byte[] )
method. but i only flew over the api and did not read the passage


Reads **some** number of bytes from the input stream...

now i use a DataInputStream.readFulle(...) and all problems are gone ... shame on me...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Abuse

JGO Ninja

Medals: 70

falling into the abyss of reality

« Reply #3 - Posted 2005-02-16 16:23:14 »

I seem to remember readFully(...) has its own set of quirks on certain handsets, as does available();

As with all mobile development, its trial and error =/
Offline Serethos

Junior Devvie

Java games rock!

« Reply #4 - Posted 2005-02-17 10:36:47 »

hmm, dont make make another headache now. ive tested it succsessfully on all available phones here and thought the problem was solved.
but nothing i can do about it now, as with all mobile development ..  Wink
Offline Scorchio

Innocent Bystander

Java games rock!

« Reply #5 - Posted 2005-02-24 15:42:23 »

I ran into the same problem when I swapped from the emulator to certain handsets. If readFully() is giving you trouble, you might want to try something like this:

lengthSoFar = 0;                        
    readLength =, lengthSoFar, expectedLength-lengthSoFar);
    lengthSoFar += readLength;
} while (lengthSoFar < expectedLength);
Pages: [1]
  ignore  |  Print  

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

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

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

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

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

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

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

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

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

nelsongames (2299 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!