java

Efficient way of handling file pointers in Java? (Using BufferedReader with file pointer)

I have a log file which gets updated every second. I need to read the log file periodically, and once I do a read, I need to store the file pointer position at the end of the last line I read and in the next periodic read I should start from that point. Currently, I am using a random access file in Java and using the getFilePointer() m...

How can I associate an Enum with its opposite value, as in cardinal directions (North - South, East - West, etc)?

I'm still working on my Cell class for my maze game I'm attempting to make. After help in a different thread it was suggested that I use an EnumMap for my Walls/Neighbors and this is working great so far. Here is what I have thus far: enum Dir { NORTH, SOUTH, EAST, WEST } class Cell { public Map<Dir, Cell> neighbors = Collect...

Double click document file in Mac OS X to open Java application

I have a Java application in an application bundle that I want to associate a file type with. For example, if there's a file foo.example when that file, or any file with the .example extension, is double-clicked, I want my application to start and open the file. I also want the files to have my application's icon. I'd like to do this...

Problems with setting the classpath in ant

Hi, I'm having problems getting my Java program to run (it uses some third party .jar s). I can compile it fine but when I call my run target in ant it says it can't find the class that I told it run in the classpath. Here's what my build.xml looks like: <project basedir="." default="build"> <property name="build" value="build" /> <prop...

SOAP and Spring

Hi guys, I've just finished reading about SOAP via Spring-WS in "Spring in Action", 2nd edition, by Craig Walls from Manning Publications Co. They write about Contract First, much like the Spring docs, with making a message and method XML and then transforming that to XSD and then again to WSDL, while wiring up the marshalling and servi...

Practical usage of the T3 File Service

In the BEA WLS console, it's possible to define "T3 File Service". After googling about it, I was unable any practical info. Is it something useful ? EDIT: Deprecated since 6.1 ... a complete overview here , it's sad that no real alternative is provided. ...

How to instantly termainate an un-supervised script on demand?

I have a GUI which resembles an interpreter. It allows the user to write a script in Jython (implementation of Python in Java) and run it whenever he wants. Apart from that, I also wish to allow the user to instantly terminate the run whenever he wants. Thing is, I don't really know how to do it. The script is being run on a different T...

How to fill a binary tree from a string, java.

Hi, I'm suppose to fill a binary tree with integers based upon a string like this. [int](LT)(RT) LT is an expression of the same form for the left part of the tree. Same with RT. A valid string would be something like this: 4(2(1)(3))(6(5)(7). How can I fill this tree? This is not a sorted tree of any kind. So it can just fill every...

Java Encryption using XTEA

How would I encrypt a string using the XTEA scheme in Java. Thanks public class run { public static void main(String[] args) throws Exception{ XTEA2 x= new XTEA2("keykey"); String s = "hi there"; byte[] theBytes = s.getBytes(); System.out.println("Plaintext: " + new String(theBytes)); ...

How could I stop from printing both sides of a wall in my ascii maze?

I've written some code that generates mazes for me. The maze consists of (n x n) cells, each cell has a boolean value to represent a wall (north, south, east west). It is working fine, and I wrote the function below to print out the maze: public static void printMaze(Cell[][] maze) { for(int i = 0; i < maze.length; i++) ...

Compass Autocomplete to only return index words

I am currently trying to configure a compass query for autocomplete. I have it working so that the compass query will return an object. I would like to modify it so that it will return matching words in the index, not matching results. Thanks. ...

Mutlithread-safe JDBC Save or Update

We have an interesting problem: We have a JMS queue of job statuses, and two identical processes pulling from the queue to persist the statuses via JDBC. When a job status is pulled from the queue, the database is checked to see if there is already a row for the job. If so, the existing row is updated with new status. If not, a row is c...

debugging tomcat crash

I have an instance of Tomcat which periodically crashes for unknown reasons. There are no errors left in the logs, only a line in Event Viewer saying "Tomcat terminated unexpectedly". In a test environment I have been unable to replicate the issue. I am therefore mostly restricted to passive monitoring of the production environment. T...

What is the difference between the ways a Swing window can be initialized?

I am curious as to the differences between the following approaches to creating a Swing window: Using java.awt.EventQueue.invokeLater() in main(); Using SwingUtilities.invokeLater() in main(); not bothering with threads at all, simply instantiating the JFrame subclass and calling setVisible(true) from main without wrapping it inside a ...

Porting java apps to Android platform

I know Java apps can be run in Android. But what I want to know is this: I have a perfectly normal Java app and I want to port it to an android platform. What changes would I need to do to my app in terms of GUI and other code to make it usable in Android? I know Android uses XML file to control the look and feel of its app. So would I n...

Hibernate is rounding my double ?

Hi, I've got a double which I'm trying to save to a postgres numeric column. The value I'm trying to save is 151.33160591125488, and I've verified that this is in fact the argument being received by Hibernates internals pre-insert. However the value in the database post insert is 151.331605911255, ie it's been rounded to 12dp. I know...

Disable logging in Java Xerces ("[Fatal Error] :1:1: Content is not allowed in prolog.")

My application expects that it will sometimes try to parse invalid XML documents. I currently catch the "SAXParseException: Content is not allowed in prolog." exception, which works fine. However, Xerces still feels the need to print it's own message to the console: [Fatal Error] :1:1: Content is not allowed in prolog. Is there any wa...

Request View and View Updates from Another Application

I am looking to create an app with plugin functionality. What I want is to allow a separate plugin "app" to provide me with the view, and take care of the updating of the view that I will use in my list adapter. Essentially, I want the separate app to take care of the bindView and newView methods of my adapter. I am looking at RemoteVie...

Spring MVC - jsp not rendering

I'm just starting with Spring MVC trying to create a new project, and came accross an issue for which no manual or tutorial seems to help... I have set up a simple application with no logic, just trying to get Spring configured properly. The controller just returns the name of a view to be displayed, but the view resolver is not renderi...

Java: Finding matches between Strings

Given 2 strings, I want to find the first match of at least four characters. This is the code I currently have to do it. It works correctly, but I'm thinking there may be a better way to do this. Are there any screaming inefficiencies or bad practices in what I'm doing? Are there common libraries, like Apache Commons, that I should be t...