java

Java Cipher - AES Padding Problem

Hi all I am using a AES cipher with a 16 byte block size. If I try and encrypt a 16 byte string I have no problems, but any other length not a multiple of 16 is throwing an exception. I know with 3-DES you can specify a padding type as part of the algorithm and it's handled with no extra work (e.g. DES/CBC/PKCS5Padding), but is the...

Which transpilers are out there?

While examining aspell to figure out how to write my own spell checker in Java, I wondered how much work it would be to convert aspell to some dialect of C which is close enough to Java that it's possible to compile both a C and a Java version from the same source. Of course, there is UML which promises that you can "model" your problem...

What is the best practice for running a number of tasks (threads) with a single timeout (run for a max of 30 seconds across all threads)?

I came up with a solution, but I wanted to see if anyone had a better way or more standard way of doing this. The main method demonstrates how I would use this class. In a production version of this I would keep the thread pool open and continue to reuse it rather than shut it down after the calls. public class MultiCallManager<T> { p...

Null Pointer when populating Grails Domain object with Oracle 10g long field

We are trying to populate a domain object from an oracle 10g database. The field in question is defined as a string in the domain object with the following constraints. zdata(blank:false,maxSize:3000000) The size of the data is approximately 70K of XML. The table definition looks like this: ZDATA NOT NULL ...

Send a JPanel to the printer

Is it possible to just send a JPanel or any other component to the printer? Or do I have to implement all the drawing to the graphics object by hand? I have tried to use the Print* functions of the JPanel to print to the graphics object but the page that gets printed is blank. ...

constantPoolClass in Java heap?

I have inherited a Java applet (an actual <APPLET>) which throws an OutOfMemory exception after about 4 days of runtime. The nature of the applet is such that people really will leave it open for long periods of time. After almost two days running, jmap -histo shows the top heap consumers as: num #instances #bytes class name ...

What's the best way to handle coexistence of the "int enum" pattern with java enums as an API evolves?

Suppose you're maintaining an API that was originally released years ago (before java gained enum support) and it defines a class with enumeration values as ints: public class VitaminType { public static final int RETINOL = 0; public static final int THIAMIN = 1; public static final int RIBOFLAVIN = 2; } Over the years the API has ...

JSP: Creating Graph

I need to create some graphical representations of the usage of electricity by month. How do I go with it? What would be the simplest way? Languages: Java, JSP Thank you very much. ...

Why AbstractCollection does not implement equals() ?

Did you know that : Map<Object,Object> m1 = new HashMap<Object, Object>(); Map<Object,Object> m2 = new HashMap<Object, Object>(); System.out.println("m1.equals(m2) = "+m1.equals(m2)); System.out.println("m1.keySet().equals(m2.keySet()) = " +m1.keySet().equals(m2.keySet())); System.out.println("m1.entrySet().equals(m2.entrySe...

What are the alternatives to JSTL?

Are there any alternatives to JSTL? One company I worked for 3 years ago used JSTL and custom tag libraries to separate presentation from logic. Front-end developers used EL to do complex presentation logic, generate layouts in JSP pages and it worked out great. Perhaps new technologies have come out. Anything better these days? ...

What is an efficient way to create a W3C DOM programatically in Java?

Although I know how to build a DOM the long, arduous way using the DOM API, I'd like to do something a bit better than that. Is there a nice, tidy way to build hierarchical documents with, say, an API that works something like Hibernate's Criteria API? So that I can chain calls together like this, for example: Document doc = createDoc...

AOP problem running Spring unit tests

I have a Spring web application which is configured to use JDK proxying for AOP. The AOP annotations (such as @Transactional) are declared on the interfaces, rather than the implementation classes. The application itself works fine, but when I run the unit tests, it seems to be attempting to use CGLIB for the AOP functionality (instead ...

spring bean configuration

Hi, I want to specify a file system path as part of a Spring bean configuration. I know that I can set a path such as: <bean id="myBean" class="com.example.BeanImpl"> <property name="path" value="/WEB-INF/jsp"/> </bean> An the path /WEB-INF/jsp is interpreted as being relative to the web application root. But how do I specify a pat...

Unable to start Camel 1.5.0

Hi, I'm trying to run the Camel Example "camel-example-spring-jms" (also at http://activemq.apache.org/camel/tutorial-jmsremoting.html). However, when I try to start Camel using "org.apache.camel.spring.Main" class, I get the error saying "Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://...

What is the "Execute Around" idiom?

What is this "Execute Around" idiom (or similar) I've been hearing about? Why might I use it, and why might I not want to use it? ...

How to increment a java String through all the possibilities?

I need to increment a String in java from "aaaaaaaa" to "aaaaaab" to "aaaaaac" up through the alphabet, then eventually to "aaaaaaba" to "aaaaaabb" etc. etc. Is there a trick for this? ...

What are the best practices for naming ant targets?

What are the best practices for naming ant targets? For exmaple, what would you expect the target "test" to run? All unit tests? All functional tests? Both? What are the standard names used for running different types of tests (unit/functional/all)? Are there standards for target names to deploy software in J2SE? in J2EE? My proje...

Java File I/O Performance Decreases Over Time

I'm trying to perform a once-through read of a large file (~4GB) using Java 5.0 x64 (on Windows XP). Initially the file read rate is very fast, but gradually the throughput slows down substantially, and my machine seems very unresponsive as time goes on. I've used ProcessExplorer to monitor the File I/O statistics, and it looks like th...

read property value in Ant

Hi, I need to read the value of a property from a file in an Ant script and strip off the first few characters. The property in question is path=file:C:/tmp/templates This property is store in a file that I can access within the ant script via <property file="${web.inf.dir}/config.properties"/> I have two questions: How do I rea...

Calling Java from Clojure

When I try to run the following code (from the REPL) in Clojure: (dotimes [i 5] (.start (Thread. (fn [] (Thread/sleep (rand 1000)) (println (format "Finished %d on %s" i (Thread/currentThread))))))) I get the following error: java.lang.Exception: Unable to resolve symbol: i in this context clojure.lang.Compiler$C...