File Processing for Java

Question

For my Java project I am looking for a convenient way to store my data. I have the following requirements:

1.It should be easy to synchronize with subversion (which I use for my Java code and other stuff). So I guess file-based is appropriate.

2.I want to be able to get certain elements without having to read all data into memory. Like in a database (“give me all objects with/without property x”, “give me all information about object with certain ID”).

3.I want to be able to read and write in this way.

I guess a database is overkill for my purpose, difficult to sync and I have to be admin/root on all machines to install it. (right?)

So I was thinking of using XML, but I heard that XML parsing in Java does not work very well. Or can anyone point me to a good library?

Then I was thinking of CSV. But all examples I saw (here and elsewhere) read the data into memory before processing it, which is not what I want.

I hope you can help me with this problem, because I am not so experienced with Java.

 

Answer

Here’re your problems: 1. Store data in file; 2. Convenient for structured computations; 3. The file is too large to be wholly read into memory.

Java doesn’t offer related class library to handle your problems. Hardcoding is complicated. Try using SPL to achieve these. esProc SPL (Structured Process Language) provides all-round structured computation class library, which is easily embedded into a Java application. Below is the SPL script for filtering a file:

A

1

=file("data.csv").cursor().select(BIRTHDAY>=date("1981-01-01")&&GENDER=="F")

 

To learn more about SPL’s integration with Java, see How to Call an SPL Script in Java.