java

Java constants in JSP

Hi, I have a class that defines the names of various constants, e.g. class Constants { public static final String ATTR_CURRENT_USER = "current.user"; } I would like to use these constants within a JSP without using Scriptlet code such as: <%@ page import="com.example.Constants" %> <%= Constants.ATTR_CURRENT_USER %> There appea...

Java annotations for design patterns?

Is there a project that maintains annotations for patterns? For example, when I write a builder, I want to mark it with @Builder. Annotating in this way immediately provides a clear idea of what the code implements. Also, the Javadoc of the @Builder annotation can reference explanations of the builder pattern. Furthermore, navigating f...

How to use JVLC (Java bindings for VLC)?

I'm trying to use JVLC but I can't seem to get it work. I've downloaded the jar, I installed VLC and passed the -D argument to the JVM telling it where VLC is installed. I also tried: NativeLibrary.addSearchPath("libvlc", "C:\\Program Files\\VideoLAN\\VLC"); with no luck. I always get: Exception in thread "main" java.lang.Unsati...

What are the advantages/disadvantages for distributing multi stage tasks via JMS or JavaSpaces?

When trying to distribute work that requires a multiple stage processing pipeline what are the communication, synchronization and throughput costs limitations in JMS vs JavaSpaces? ...

Why does "piping" a CharBuffer hang?

Why does the following method hang? public void pipe(Reader in, Writer out) { CharBuffer buf = CharBuffer.allocate(DEFAULT_BUFFER_SIZE); while( in.read(buf) >= 0 ) { out.append(buf.flip()); } } ...

Java idiom for "piping"

Is there a more concise/standard idiom (e.g., a JDK method) for "piping" an input to an output in Java than the following? public void pipe(Reader in, Writer out) { CharBuffer buf = CharBuffer.allocate(DEFAULT_BUFFER_SIZE); while( in.read(buf) >= 0 ) { out.append(buf.flip()); buf.clear(); } } [EDIT] Please not...

Using Blitz implementation of JavaSpaces

I have great doubts about this forum, but I am willing to be pleasantly surprised ;) Kudos and great karma to those who get me back on track. I am attempting to use the blitz implementation of JavaSpaces (http://www.dancres.org/blitz/blitz_js.html) to implement the ComputeFarm example provided at http://today.java.net/pub/a/today/2005/0...

SAX vs XmlTextReader - SAX in C#

I am attempting to read a large XML document and I wanted to do it in chunks vs XmlDocument's way of reading the entire file into memory. I know I can use XmlTextReader to do this but I was wondering if anyone has used SAX for .NET? I know Java developers swear by it and I was wondering if it is worth giving it a try and if so what are t...

When using a HashMap are values and keys guaranteed to be in the same order when iterating?

When I iterate over the values or keys are they going to correlate? Will the second key map to the second value? ...

Java, Swing: how do I set the maximum width of a JTextField ?

I'm writing a custom file selection component. In my UI, first the user clicks a button, which pops a JFileChooser; when it is closed, the absolute path of the selected file is written to a JTextField. The problem is, absolute paths are usually long, which causes the text field to enlarge, making its container too wide. I've tried this...

How can I lock a file using java (if possible)

I have a java process that opens a file using a FileReader. How can I prevent another (java) process to open this file, or at least make that second process know that the file is already opened? Does this automaticaly makes the second process get an exception if the file is open(which solves my problem) or do i have to explicitly open it...

Java Threads priority in Linux

I have a multi thread application built on Java and I need to set different priorities to this threads. In windows it works fine, a bigger value (priority) gets more CPU time just like it was supposed. On Linux, I cant find a logical answer to how it is working. Looked online, but can't seem to find a definitive answer on how its worki...

What to do with null fields in compare() ?

In Java, I use a class in which some fields can be null. For example: class Foo { String bar; //.... } I want to write a BarComparator for this class, private static class BarComparator implements Comparator<Foo> { public int compare( final Foo o1, final Foo o2 ) { // Implementation...

Algorithm for merging large files

I have several log files of events (one event per line). The logs can possibly overlap. The logs are generated on separate client machines from possibly multiple time zones (but I assume I know the time zone). Each event has a timestamp that was normalized into a common time (by instantianting each log parsers calendar instance with the ...

Determining the index of an Item on a Form (J2ME)

Given an Item that has been appended to a Form, whats the best way to find out what index that item is at on the Form? Form.append(Item) will give me the index its initially added at, but if I later insert items before that the index will be out of sync. ...

Unconditionally execute a task in ant?

I'm trying to define a task that emits (using echo) a message when a target completes execution, regardless of whether that target was successful or not. Specifically, the target executes a task to run some unit tests, and I want to emit a message indicating where the results are available: <target name="mytarget"> <testng outputDir...

What is the 'best' way to do distributed transactions across multiple databases using Spring and Hibernate

I have an application - more like a utility - that sits in a corner and updates two different databases periodically. It is a little standalone app that has been built with a Spring Application Context. The context has two Hibernate Session Factories configured in it, in turn using Commons DBCP data sources configured in Spring. Curr...

Best java open source toolkit to visualize a GML fragment

Hi, I'm looking for a way to visualize a piece of GML I'm receiving. What is the best freely available java library to use for this task? ...

How to compute the hashCode() from the object's address?

In Java, I have a subclass Vertex of the Java3D class Point3f. Now Point3f computes equals() based on the values of its coordinates, but for my Vertex class I want to be stricter: two vertices are only equal if they are the same object. So far, so good: class Vertex extends Point3f { // ... public boolean equals(Object other) ...

looking for Java GUI components / ideas for syntax highlighting

I'm not committed to any particular GUI tookit or anything - just needs to be Java based. I want to do simple syntax highlighting ( XML and XQuery ) inside editable text areas. My only candidate so far is Swing's JTextPane, as it supports seems to support the styling of text, but I have no idea how to implement it in this context. If a...