java

Copying Files with Spaces

I'm trying to copy one file to another directory, but the way I am copying the file is not working when the source path has a directory with spaces in it, e.g. /Volumes/public/Music/Directory With Spaces/01.mp3 I am using: http://commons.apache.org/io/ I can't find a way around this, any ideas? Edit: The problem should probably be p...

Mapping calculated properties with JPA

Hi, Is there a way to map a calculated property using JPA? Assuming I have an Invoice object with one or more InvoiceLineItems within it, I want to have a persistent calculated property on the Invoice class that gives me the total amount: class Invoice { ... @Column(name = "TOTAL_AMOUNT") public BigDecimal getTotalAmount(...

How to send HTTP request in java?

I want to compose a HTTP request message in java and then want to send it to a HTTP WebServer. I also want the document content of the page recieved which I would have recieved if I sent the same HTTP request from a webpage. ...

Query partial entities with JPA

I have a JPA entity similar to; public class Inventory { private String productname; private String manufacturer; private Float retailprice; private Integer unitssold; private String ourcomment; } In about 2 out of 5 queries I need the whole entity, but the rest of the time I am not interested in unitssold and ourcomment. It fee...

Is there an alternative to ParameterMetaData that can tell you valid parameter names

MSSQL has an interesting JDBC inconsistency. Regarding the parameters on a stored procedure, when you access their names, they are referenced with an @ sign in front of them (the way they are declared in the stored procedure). When you use a callable statement to set parameters by name, however the Microsoft JDBC driver requires you to ...

java - BigDecimal

I was trying to make my own class for currencies using longs, but Apparently I should use BigDecimal (and then whenever I print it just add the $ sign before it). Could someone please get me started? What would be the best way to use BigDecimals for Dollar currencies, like making it at least but no more than 2 decimal places for the cent...

Proper replacement for usage of the Sun internal com.sun.image.codec.jpeg package?

We have some code kicking around that uses this old internal Sun package for manipulating images, essentially encoding JPEGs to a specific size and quality after reading in / decoding from an inputstream. Code examples below. I would appreciate a best practice replacement example using proper java.* or javax.* APIs. private void encod...

What is the correct way to set ANT_OPS in OS X?

I'm running into 'Error: Java heap space, java.lang.OutOfMemoryError: Java heap space' when compiling an existing project on OS X (Snow Leopard). I am using the default Java 1.6 64-bit SDK, and default install of Ant (both are provided as part of the OS). I have encountered this issue in other OS environments and normally solve it by...

How to handle numbers in a generic fashion?

My question is eerily similar to "Writing a generic class to handle built-in types" including being inspired by the fact of working on a class to handle operations on matrices. Although that question was asked using C# and pointed to an article on Generic Operators. I don't get it. Java Number does not have an add method so you can hav...

Facebook API and Facebook Connect using Java?

New to Facebook API and Facebook Connect. Found the Facebook Java API open source library on Google Code... I am really excited that there's an API pre-written in Java for it! Am interested in writing a server side Java layer which uses REST to be able to access a user’s Facebook Friends List, their wall, send them messages in-network...

Is Java Regex Thread Safe?

I have a function that uses Pattern.compile and a Matcher to search a list of strings for a pattern. This function is used in multiple threads. Each thread will have a unique pattern passed to the Pattern.compile when the thread is created. The number of threads and patterns are dynamic, meaning that I can add more patterns and thread...

Eclipse: How to prevent an entire rebuild of a project after changing classpath

Is there away to prevent eclipse from rebuilding the entire project every time I change an entry in the class path. Unfortunately, I have to play around with the build path often and rebuilding the projects takes a long time (easily 20-30 mins). Is there away to avoid this? ...

How to de-select a JList item from my program

I have a JList, and a JButton, user can click an item in the JList or they can click the button, when the button is clicked how do I de-select (change the selected list item bgcolor to normal, in other words, nothing in the JList will be selected after the button is clicked) the item from the JList ? ...

Help setting up Java VM size

Well I am very new to Java and can't understand how am I supposed to set the virtual machine's size. I've built a small web applet that displays images. Sometimes the images can be pretty large, when this happens I get: *Exception in thread "Image Fetcher 0" java.lang.OutOfMemoryError: Java heap space* I've been trying to follow diffe...

Persist collection fields with hibernate

Using hibernate, how can I persist a class with a List<String> field? Consider the following entity class: @Entity public class Blog { private Long id; private List<String> list; @Id @GeneratedValue public Long getId() { return id; } public void setId(Long id) { this.id = id; } public List<String> getList(...

File copying in Java

What is a better option (in terms of performance): copying a file using fileinputstream and fileoutputstream or running a OS specific command copy command from Java? ...

Java: Fonts look garbled on Linux, but fine on windows

I'm writing a java application that renders PDF documents to images, and when I run it on windows it works fine. But when I render the PDF on Linux, the standard fonts look a bit garbled, like there would be a few pixels missing on the right side of some characters. I only tested it on a fresh install of Ubuntu 9.04 with OpenJDK 6, but ...

When should we call connection.rollback() method?

Please let me know when do we require to call the method connection.rollback(); try{ connection = getConnection(); connection.setAutoCommit(false); pstmt1 = connection.preparedstatement ( ... ); ... pstt1.executeUpdate(); pstmt2 = connection.preparedstatement ( ... ); ... pstt2.executeUpdate(); connection.commit(); }ca...

Evaluation of Drools Flow with Drools Expert on a web based J2ee project

I am evaluating drools flow as wrokflow engine with drools expert rule. Key evaluation points: Generating Customize Rules and Workflow through own custom Web UI Admin user can see all of the items in workflow in UI (View job queue: current queue, executed jobs, exceptions) Rule Actions can be web services, Java classes or it can be ...

How to get adress of a Java Object?

Is there a way to get address of a Java object? Where the question comes from?: At First, I read properties file and all the data from file was placed into table. Properties file can update. So, I want to listen that file. I listen an object using PropertyChangeSupport and PropertyChangeListener. updatedStatus = new basit.data.MyStri...