Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
ingvar_e
Posts: 551
Registered: ‎10-31-2009
My Carrier: Movistar, Telenor

Re: Java question

I just wanted to first collect all data needed to install a cod file containing sibling segments. 

The name of the codfile, the individual cod segments, their respective length and the total length of the cod. When doing the install of the first segment I need to know the total lenght. So I want to get all the segments into memory before starting the install. The name of the cod, and its attributes and each segment and its length, store all in a class that I can pass onto the install routine. I felt that would be an elegant way of doing it. And I stumbled when the class needed to contain both array and non array info

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-
Please use plain text.
Developer
Ted_Hopp
Posts: 1,305
Registered: ‎01-21-2009

Re: Java question

If you know how to do what you want using C structs, you can do it more or less the same way in Java using public members. The only thing you might use in C that is missing in Java is realloc. To compensate, you can do one of two things: use a Vector (or IntVector) instead of an array or use the following idiom (shown for int arrays, but works for any array type):

int[] tmp = values;

values = new int[values.length + 10]; // increase array size by 10

System.arraycopy(tmp, 0, values, 0, tmp.length);

Java classes can contain array and non-array info just as easily as C structs can contain both pointer and non-pointer fields. (Java object references--including arrays--are the same as C++ references: just like pointers except you can't do pointer arithmetic.)

 

To get back to your specific question--get and set the size of a particular segment--you can define segment size get/set methods (using the class structure I suggested earlier):

 

public int getSegmentSize(int segmentIndex) {
    return A[segmentIndex]._segmentSize;
}

public void setSegmentSize(int segmentIndex, int size) {
    A[segmentIndex]._segmentSize = size;
}

public byte[] getSegmentData(int segmentIndex) {
    return A[segmentIndex]._segment;
}

public void setSegmentData(int segmentIndex, byte[] data) {
    A[segmentIndex]._segment = data;
}

And that's about all there is to this, I think. (You might want to define the total size as just an accessor function that just sums up the segment sizes on demand, rather than as a member variable that needs to be maintained separately.)




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Please use plain text.
Developer
ingvar_e
Posts: 551
Registered: ‎10-31-2009
My Carrier: Movistar, Telenor

Re: Java question

Thanks Ted. Will see if I can change my 2-class solution to one class. Currently I am stuck with more serious problems with timeouts and other disruptions reading files from the internet

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-
Please use plain text.