Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (636)
Games in Android Showcase (178)
games submitted by our members
Games in WIP (686)
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 1511 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: 42

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 =/

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here!
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  
You cannot reply to this message, because it is very, very old.

Dwinin (68 views)
2015-11-07 13:29:08

Rems19 (77 views)
2015-10-31 01:36:56

Rems19 (70 views)
2015-10-31 01:32:37

williamwoles (104 views)
2015-10-23 10:42:59

williamwoles (91 views)
2015-10-23 10:42:45

Jervac_ (105 views)
2015-10-18 23:29:12

DarkCart (132 views)
2015-10-16 00:58:11

KaiHH (115 views)
2015-10-11 14:10:14

KaiHH (154 views)
2015-10-11 13:26:18

BurntPizza (167 views)
2015-10-08 03:11:46
Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30

Rendering resources
by Roquen
2015-10-15 07:40:48

Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11 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!