java

How to read and write network sockets in Java ME on a device with simplex connectivity?

Dear all, I am working on a mobile communicator and after establishing connection to the server using following method (to illustrate that I am using StreamConnection, InputStream and OutputStream) I distribute inputStream and outputStream between two separate threads, lets call them Sender and Receiver. Connection method: private I...

Decompress a Gzip archive in Java

I'm trying to decompress about 8000 files in gzip format in Java. My first try was to use GZIPInputStream but the performance was awful. Anyone know any alternative to decompress gzip archives? I tried ZipInputStream but it's not recognizing the gzip format. Thank you in advance. ...

Should I make a constants class for my annotations?

Which is better? @SuppressWarnings("unchecked") @SuppressWarnings(AnnotationConstants.UNCHECKED) Where AnnotationConstants is a typical constants class... public final class AnnotationConstants { private AnnotationConstants() { } public static final String UNCHECKED = "unchecked"; ... } I know that there are a lot of...

GWT-DnD (drag and drop) layout question

The following is when using the drag and drop library from here: http://code.google.com/p/gwt-dnd/ When placing an absolute panel inside a relative panel, it appears to disable the drag ability. A simple example: private AbsolutePanel leftPanelTree = new AbsolutePanel(); private HorizontalPanel drawingAppPanel = new Horizonta...

Spring Controller destroy method?

Does Spring's Controller have any sort of destroy/cleanup method? I couldn't find anything in the JavaDocs for Controller and AbstractController. I'm looking for the equivalent of javax.servlet.Servlet's destroy() method. The reason for this is that I'm starting a thread in my Spring controller. I want the thread to terminate whenever t...

How to use Junit to test asynchronous processes

How do you test methods that fire asynchronous processes with Junit? I don't know how to make my test wait for the process to end (it is not exactly a unit test, it is more like an integration test as it involves several classes and not just one) ...

Java StringBuilder and Thread Safety

I am building up a String out of multiple pieces and want to use either StringBuffer or StringBuilder to do so. From the Java 5 docs, I see that StringBuilder is preferred when possible, with the caveat that "Instances of StringBuilder are not safe for use by multiple threads". From this statement I understand that I should not have a si...

Help with packages in java - import does not work

I'm a C++ developer - not a java developer, but have to get this code working... I have 2 public classes that will be used by another product. I used the package directive in each of the java files. package com.company.thing; class MyClass ... When I try to compile a test app that uses that I add import com.company.thing.*; T...

Why am I getting a Hibernate LazyInitializationException in this Spring MVC web application when the data displays correctly?

I am attempting to create a web application using Spring MVC, with Hibernate as its ORM layer. However, due to my inexperience with both frameworks I'm struggling. The following code will properly display all the records I am looking for but still throw a stack trace into my logs. I'm having trouble finding thorough documentation concer...

How to minimize question-marks when encoding a String as Latin-1?

When encoding a java String to Latin-1 (ie. charset ISO-8859-1) I currently convert the German symbol β ('\u03B2') to ß ('\u00DF') before performing the encoding. I'm trying to avoid a question mark in the encoding where possible. Can anyone suggest other un-encodable characters which can be replaced an encodable character? Or better ...

How to quote "*/" in JavaDocs

I have a need to include */ in my JavaDoc comment. The problem is that this is also the same sequence for closing a comment. What the proper way to quote/escape this? Example: /** * Returns true if the specified string contains "*/". */ public boolean containsSpecialSequence(String str) Follow up: It appears I can use / for the...

Deploying to OC4j: Unable to find/read file META-INF/application.xml

Continuum build server deploys to my oc4j instance I get the following error it seems every other build. 09/03/10 13:47:49 Notification ==>Operation failed with error: Unable to find/read file META-INF/application.xml in C:\oc4j\j2ee\home\applications\rrs (META-INF/application.xml) Continuum is running in a windows environment Any inp...

Overriding Java generic methods

I wanted to create an interface for copying an object to a destination object of the same class. The simple way is to use casting: import org.junit.Test; import org.junit.internal.runners.JUnit4ClassRunner; import org.junit.runner.RunWith; @RunWith(JUnit4ClassRunner.class) public class TestGenerics { public static interface Copyable { ...

How do I extract child element from XML to a string in Java?

If I have an XML document like <root> <element1> <child attr1="blah"> <child2>blahblah</child2> <child> </element1> </root> I want to get an XML string with the first child element. My output string would be <element1> <child attr1="blah"> <child2>blahblah</child2> <child> </e...

Java; String replace (using regular expressions)?

As part of a project for school, I need to replace a string from the form: 5 * x^3 - 6 * x^1 + 1 to something like: 5x<sup>3</sup> - 6x<sup>1</sup> + 1 I believe this can be done with regular expressions, but I don't know how to do it yet. Can you lend me a hand? P.S. The actual assignment is to implement a Polynomial Processing...

How to calculate java BufferedImage filesize

I have a servlet based application that is serving images from files stored locally. I have added logic that will allow the application to load the image file to a BufferedImage and then resize the image, add watermark text over the top of the image, or both. I would like to set the content length before writing out the image. Apart f...

Cannot Find Symbol

...

How to change the image of a JButton?

I'm working on a memory game program. I have 30 JButtons on a JPanel. When the user is clicking and finds a match (meaning two buttons with the same image) I want to change the image on the JButton to a different image. However this does not happen while the program is running. How can I do this? I was doing this: cards[i].setIcon...

Simple code to handle JNI exceptions

I'd like to have a nice, tidy way of expressing the following java code as JNI: try { SomeMethod (); } catch (ExceptionType1 e) { SomeAction (); } catch (ExceptionType2 e) { SomeAction (); } catch (ExceptionType3 e) { SomeAction (); } Is there a tidy JNI patter for doing this? At present, I have this: java_class = (*...

Are XML chunks valid?

Hello! I want to store some fragments of an XML file in separate files. It seems, there is no way to do it in a straight way: Reading the chunks fails. I always get the Exception "javax.xml.transform.TransformerException: org.xml.sax.SAXParseException: The markup in the document following the root element must be well-formed." It only...