Isuru Sampath

Ranch Hand
+ Follow
since Jun 26, 2003
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Isuru Sampath

Thanks for reading my post.

I have an application being developed which uses ViewPager. The primary use of the View Pager is to obtain swipe functions in navigating the pages. I'm required to enhance the application by introducing Fragments which render multiple fragments based on the screen resolution/orientation. I've searched the web bout I could not find an example with all these elements; where multiple fragments are used within a ViewPager. Can someone please help me out.

Thank you.
9 years ago
Hi Steven,

Thanks for your suggestion. CountDownLatch is what I need. Thanks again.
Hi Mike,

Thanks a lot for your explanation. Saved me from lots of trouble. Now I get it. The moment I call the join() method my calling thread will start waiting untill the spawned thread completes.
Won't this do rather than looping again to join the threads again???


Thanks for reading my post. I'm working on a project which involves a significant amount of XML message parsing and routing. I'm planning to use JAXB for XML marshaling/unmarshaling. Please note that this project does not involve web services. I'm using JAXB for marshaling/unmarshaling of XML. I realize that there is very limited amount of documentation when it come to this topic. I found this tutorial at javabeat extremely useful as this is what I'm exactly going to do.

But I've hit a rough patch due to the way the XML messages are formed. I tried to change the message format but it seems it is impossible as what I'm working on is one single component of an existing component chain . This is my background. My problem is:

The messages received by my component are of the following format:

The message contains multiple counts of <MSG> tags. And the first <MSG> tag represents a batch header which describes elements common to the rest of the <MSG> elements. I have a object hierarchy which implements the above structure. But I'm stuck when it comes to describing JAXB that the first element is the header and the rest are messages, simply because the base element name is <MSG> for both of them.

You help, comments, ideas will be most helpful. Thanks in advance.
14 years ago
Try pairing the two devices first if you can this will resolve any auth challenge issues if there are any.

Invoke your phone's Application Manager. It will show you a list of installed applications. Select your program from the list. Go to options. There will be a item called "Network Access", select 'Ask first time' from it.

Now try your program.

Hope this helps. Good luck.
17 years ago
If you're getting an Out Of Memory error it could very well be due to a coding bug. Check whether you are having any conditions that will result memory leaks. You can use a profiler to detect this. Pay special attention to the conditions in your loops.

I am creating a array of byte and loading the entire file on a particular port

, why do you do this? you can obtain an input stream from the file for reading it. I don't see why do you need to load the whole file into a byte array. If your file is larger than the allocated heap (keep in mind that you are programming for a limited resource device), this could also result the same error.
17 years ago
Thanks Earnest. Your answer helps a lot.

The SUN definition was so abstract like the satement of a politician.
17 years ago
I ran a profiler on my application and found that 1 thread is created for every client request. Tried with several client configurations; each time the number of clients were equal to the number of new threads spawned. Also the thread spawning time is analogous to the client request initiation time.

So, what�s with the definition?
[ February 08, 2007: Message edited by: Isuru Sampath ]
17 years ago
Thanks for reading my post. I need some definitive answer or I�m going to get my eyes crossed in this matter

I have a RMI bound service which will be used by multiple clients simultaneously via RMI calls. How do I serve all the clients in parallel? Do I have to bind new instances of my server object multiple times in multiple names to achieve true parallelism or does the RMI Registry do this for me, by creating a copy of my object and running it in a separate thread for each remote client.

I was able to find this nice little explanation in the RMI Spec.

Thread Usage in Remote Method Invocations
A method dispatched by the RMI runtime to a remote object implementation may or may not execute in a separate thread. The RMI runtime makes no guarantees with respect to mapping remote object invocations to threads. Since remote method invocation on the same remote object may execute concurrently, a remote object implementation needs to make sure its implementation is thread-safe.

Thread Usage in Remote Method Invocations

Though I can read all the words in it, I feel the meaning is in 500 BC Greek.
[ February 08, 2007: Message edited by: Isuru Sampath ]
17 years ago
Thanks for reading my post.

I�m using javax.swing.JPasswordField to read a user entered password. The extracted password (via the getPassword() method) is ued as a seed to create a SecureKey which will be used for encrypting some file contents.

I encrypt the original file contents by hard coding the password on a test program. I use the same set of classes with the Swing GUI too. But when I obtain the password from the JPasswordField object, my cipher instance is throwing the exception: "javax.crypto.BadPaddingException: Given final block not properly padded".

When I hardcode the password in the GUI code I am able to successfully de-cipher the file. I did print the password obtained from the JPasswordField to console and it prints correctly.

I undertand that javax.crypto.spec.SecureKeySpec is considering byte values for the seed and if there is a difference in this the key would be different.

Is there any specific encoding or something I should use to convert the JPasswordField.getPassword() output to a String?

Currently I'm using the String constructor:

String(char[] chars)

to convert the output of the JPasswordField.getPassword().
17 years ago
Thanks for reading my post.

I need a component to create an application which has a simple text editor functions. Intended functions include adding, deleting and inserting characters. No need to bold, Italics, Underlining or any other fancy formatting since I'm writing the outpt to a text file. Which of the following is ideal for this purpose:

  • JTextArea
  • JEditorPane
  • JTextPane

  • Can you kindly explain any advantages of using the either component.
    [ November 03, 2006: Message edited by: Isuru Sampath ]
    17 years ago
    Very many thanks to Jesper and Bauke.

    Yes Jesper, what I wanted was the binary representation of the int in Big Endean order. And the code snippet you provided is really nifty and guess it is really fast since bit shifting is the fastest operations we can get (my belief :roll: ).

    But the reason I like the previous code is that it does not have to have the byte array length hard coded. It will create a byte array to hold the input integer whatever it's size. I 100% agree with you that it is kind of overkill if the integer size is limited or known. On the other hand if the integer size is dynamic, the previous code snippet is ideal. Guess the choice should be based on the requirement.

    All this... pretty nifty and interesting stuff.
    17 years ago
    Thanks Peter. U clarified a lots of doubts I had.

    Meanwhile, I found this code snippet on sun java forum which can easily convert an Int to a byte arry. Re-posting it for the advantage of others. Credit goes to the original writer of the code.

    Nifty ha?
    17 years ago
    Thanks for reading my post.

    The description provided in the Java doc for the method is:

    Returns the value of this Integer as a byte.

    It is obvious that one byte can only represent upto a value of 255. If the value contained is larger than 255, there would be a loss of data.

    My question is why the Java API developers did not provide something like a byte array rather than a byte as the return type. Am I missing someting here?
    [ October 31, 2006: Message edited by: Isuru Sampath ]
    17 years ago