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

Junior Member




Java games rock!


« Posted 2005-02-16 07: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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
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];
        in.read(rawData, 0, rawData.length);
       
        store.closeRecordStore();
        bais.close();
         
        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
1  
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 Member




Doh!


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

Are you sure that:
1  
in.read(rawData, 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.

shmoove

[edit]
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.
[/edit]
Offline Serethos

Junior Member




Java games rock!


« Reply #2 - Posted 2005-02-16 12: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

Quote

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 Coder


Medals: 11


falling into the abyss of reality


« Reply #3 - Posted 2005-02-16 17: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! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline Serethos

Junior Member




Java games rock!


« Reply #4 - Posted 2005-02-17 11: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 16: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:

1  
2  
3  
4  
5  
6  
lengthSoFar = 0;                        
do
{
    readLength = iStrm.read(buffer, lengthSoFar, expectedLength-lengthSoFar);
    lengthSoFar += readLength;
} while (lengthSoFar < expectedLength);
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.

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

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

Riven (6 views)
2014-07-23 20:56:16

ctomni231 (40 views)
2014-07-18 06:55:21

Zero Volt (36 views)
2014-07-17 23:47:54

danieldean (30 views)
2014-07-17 23:41:23

MustardPeter (32 views)
2014-07-16 23:30:00

Cero (47 views)
2014-07-16 00:42:17

Riven (48 views)
2014-07-14 18:02:53

OpenGLShaders (38 views)
2014-07-14 16:23:47
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!