I am using JSF2.0, jetty server and Postgres database. I want to store mp3 file in database in byte array formet. I upload the byte array of mp3 file. But when I retrive same byte array from database I get byte array of double size and my because of that my mp3 file is not working as well. Output: Upload
Tag: java
How to parse a String variable into any data type in Java?
I want to build a method that can convert a String value to a given Field object data type through Java Reflection. Here is my code: String value = …; Class clazz = …
How to match any combination of letters using regex?
How can I match letters a,b,c once in any combination and varying length like this: The expression should match these cases: but should not match these ones: Answer Use regex pattern You can use this pattern with any set and size, just replace [abc] with desired set… Example: (above output is from myreg…
Why do I need Transaction in Hibernate for read-only operations?
Why do I need Transaction in Hibernate for read-only operations? Does the following transaction put a lock in the DB? Example code to fetch from DB: Can I use session.close() instead of tx.commit()? Answer Transactions for reading might look indeed strange and often people don’t mark methods for transac…
Java Heap and Pass By Value
I am a little confused as to how my Java program is allocating memory. Below is a typical situation in my program. I have an object created on the Heap inside of a class which I pass to other functions inside of other classes. My question(s) are about how the memory is used. When A’s list gets passed to…
How to tell if one of the heap-generations is full?
We are experiencing some problems in our production environment, where we get an InvalidPropertyException from one of the compiled jsps (which one differs from time to time) after a bit of time. I have a suspicion that this is caused by something “disappearing” from the heap. Further, I suspect th…
JFileChooser change default directory in Windows
I want to change the default directory of my JFileChooser to “My Music” on Windows. This directory is C:UsersFreMusic on my account because my username is Fre The default is set on C:UsersFreDocuments (depends on OS i think). How can I change this? Answer You can use the API method setCurrentDirec…
Needing to double click EditText for click listener to respond
I have a section of code where I want to change the text showing in a textView when the user selects an EditText box. The problem I am having is that the textView only changes when I double click the EditText box, one click and there is no change to the textView. Is there another click listener that I should
Headless environment error in java.awt.Robot class with MAC OS
I am trying to capture screen shots in my JavaFX application using Robot class, this is the code which I used in my application: It is working perfectly in windows operating system, but showing an error of headless environment in MAC OS at Robot robot = new Robot(); Answer This is to answer my own question, a…
Monads with Java 8
In the interests of helping to understand what a monad is, can someone provide an example using java ? Are they possible ? Lambda expressions are possible using java if you download the pre-release …