java

Spring- How to use Spring Dependency Injection to write a Standalone Java Application

I want To write a standalone application with IOC,How do i use springs dependancy injection in there. Im using JIdea. There is spring 2.5 support but i want to use spring 3.0 here is the way i tried! I experience in using Spring MVC we can inject dependancies there in a WebApplicationContext but how do i inject dependancies in a st...

Executing shell scripts from a Java application independently

I have a java application consisting of a Thread that monitors a table in the database that contains shell scripts to be executed. I look up the database, every few seconds. for a script, execute it (via the Process class), and wait for another script in the table. My problem is: At times, some command in the script fails. The thread c...

Optimized implementations of java.util.Map and java.util.Set?

I am writing an application where memory, and to a lesser extent speed, are vital. I have found from profiling that I spend a great deal of time in Map and Set operations. While I look at ways to call these methods less, I am wondering whether anyone out there has written, or come across, implementations that significantly improve on acc...

Convert base64 encoded string to java byte array

I am writing a decryption class (AES/CBC/PKCS7Padding) where the encrypted data is coming from C#. I want to take the following string (which is base64 encoded): usiTyri3/gPJJ0F6Kj9qYL0w/zXiUAEcslUH6/zVIjs= and convert it to a byte array in java to pass into the SecretKeySpec as the key. I know there is the issue of C# having unsigned ...

Naming enum types

If you have a set of related words (e.g. Row & Column or On & Off), how do you find the collective word that describes those words? Specifically, how do you name an enum? If I have "Red", "Green" and "Blue", a sensible enum name might be "Color". Values of "On" and "Off" might have a sensible enum name of "Power". But how do I name t...

Is it possible to read a properties file from all .war files deployed in a JBoss container.

Hi. I've managed to deploy a .war to the Jboss web container containing and read the pom.properties located under /META-INF/groupid-dir/artifactid-dir/ To access the file I've used the following code inside a JSP in the same war: ServletContext servletContext = getServletConfig().getServletContext(); InputStream in = servletContext....

Java server socket buffers not being garbage collected on Mac--why?

I'm hunting a memory error in an application, and it seems to be related to the byte[] buffers generated by ServerSocketChannel.accept(). According to jvisualvm, of the 505 megs in use by the application, over 90% of the memory is being used by byte[] arrays. Tracking it further, there are 68k+ instances of byte[] and by far the most c...

How can you pipe an OutputStream to a StreamingDataHandler?

I've got a Java web service in JAX-WS that returns an OutputStream from another method. I can't seem to figure out how to stream the OutputStream into the returned DataHandler any other way than to create a temporary file, write to it, then open it back up again as an InputStream. Here's an example: @MTOM @WebService class Example { ...

Use an alternative Maven Profile during test phase

I'm trying to build an application starting from an Appfuse Archetype, but I get some strange problems. For once I'd like to use a hsqldb for automated unit tests and integration tests, and a mysql db for my manual testing so that I can easily manipulate the data when I need to, so it would be nice to automatically switch profiles during...

Easiest way to compare two Excel files in Java?

I'm writing a JUnit test for some code that produces an Excel file (which is binary). I have another Excel file that contains my expected output. What's the easiest way to compare the actual file to the expected file? Sure I could write the code myself, but I was wondering if there's an existing method in a trusted third-party library (...

How can I filter OSGi service visibility?

OSGi employs a service-oriented architecture: Bundles register service objects, that other bundles consume. Service publishing and binding is managed by the framework. This decouples service providers from service users completely (except for the need to agree on a service interface). Is there a way to limit (by configuration) what ser...

Java plugin development with debug interface problem

Hello i'm trying to develop an eclipse plugin (in eclipse) that uses the Java debugging interface and i'm getting the following error: Access restriction: The type VirtualMachine is not accessible due to restriction on required library /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/classes.jar Using the debug in...

How to design a bulletproof method of relating a string to base string ?

My service communicates with a server that manages accounts. Each Account has a cap on the number of operations performed per month. I want to circumvent this cap by creating new accounts that are related via a scheme. This is how it should work: User creates an account "denzel" via MyService. MyService in turn, proxies the account...

Java ResultSet how to check if there are any results

Resultset has no method for hasNext. I want to check if the resultSet has any value is this the correct way if (!resultSet.next() ) { System.out.println("no data"); } ...

Timer vs Thread primitive in Java

Has anyone observed that creating a thread that does work in a while(true) loop with a Thread.sleep(t) appears to consume more CPU than creating a Timer in Java with a wakeup of t? Anyone with JVM expertise know why this is? I've only really tried this on Windows and Linux x86. ...

download window java

Hi, i'm reading file through serialport i want file transfer window wich should not have any connection to parent window,and reading process should go on backside ...

In Java, can I define an integer constant in binary format?

Similar to how you can define an integer constant in hexadecimal or octal, can I do it in binary? I admit this is a really easy (and stupid) question. My google searches are coming up empty. ...

What is the best way to compare several javabean properties?

I need to compare dozens of fields in two objects (instances of the same class), and do some logging and updating in case there are differences. Meta code could look something like this: if (a.getfield1 != b.getfield1) log(a.getfield1 is different than b.getfield1) b.field1 = a.field1 if (a.getfield2!= b.getfield2) log(a.getfield...

Best GWT widget library?

Question for all the GWT gurus out there - which is the best GWT widgets library out there? And why? List based on the answers: Default EXT-GWT GWT Components Library GWT-EXT GWT Widget Library GWTiger Rocket GWT Dojo SmartGWT Vaadin Others ...

j2me networking, threads and deadlocks

The simple piece of midlet code (class Moo) below (after the excerpts) deadlocks (At least I assume it deadlocks after reading this post on threads here). I have reproduced the relevant excerpts from the post : String url = ... Connection conn = null; try { conn = Connector.open( url ); // do something here ...