java.nio.Files, java.nio.Paths on java 6 - java

I need to rewrite some java 7 file IO code that should run on a Java 6 VM too.
The implementation uses handy Java 7 features like autoclosing, Paths and Files.
To be more specific, I need to handle expressions like /tmp/foo/*.bar to return all .bar files (currently implemented with Files.newDirectoryStream(dir, glob)).
Does anyone know a handy library for this?

The Apache Commons IO API is also a good choice. I used it for a similar work (rewrite some code from java7 to java6 that used Path object) and they work very well.

The Apache Ant API would be a good candidate for this, in particular their FileSet class might do the job.

guava runs on java6 and it has a nice I/O api.

Related

Using GraalPython as a Jython replacement

I wonder if it is possible to use GraalPython as a Java library to interpret Python code on a standard JVM. If so, would it be a good choice to replace Jython (which only supports Python 2.7)?
Is this possible without importing the entire GraalVM project? I expect only Truffle and the Python interpreter built on top of it should be necessary.
If this is not possible, are there any good Java implementations of Python 3 available?
You should be able to run any GraalVM language on any JDK as their are just Java programs. However, the performance will be affected a lot. Moreover, languages like python consist of additional resources (standard library files, etc.) that you would have pull from GraalVM too.
This document about GraalVM JavaScript discusses this in more detail and describes how to run GraalVM JavaScript on stock JDK without compromising the performance. Some of it can be applicable to GraalPython.
https://github.com/graalvm/graaljs/blob/master/docs/user/RunOnJDK.md
Tl;dr: it will be much easier to use GraalVM. It's full JDK distribution. You are not missing on anything. If you can't, there are some ways.

Use python library in java code

There is some library called pymorphy written in python. Unfortunately, for java there is not any library with the similar functionality - natural language processing for Russian lang. So I need to invoke some methods of pymorphy library from Java code.
First I've tried to solve this problem with Jython. But I've spent 2 days and the goal was not accomplished because python modules cdb, bsddb3, sqlite are written in C and they will not work with Jython.
Now I want to run some python light-weight server with pymorphy for handling request from Java code.
How could I implement this kind of java-python interaction with the maximum production performance? Or is there more simple way to call python from java?
Try Jepp, "Java Embedded Python". http://jepp.sourceforge.net/
I haven't used it beyond small projects, but it works as advertised, allowing one to call CPython transparently from Java. If you have the opposite problem, needing to call Java from CPython, definitely check out JPype. I've used it extensively and it works very well.
I think these libraries (cdb, bsddb3, sqlite) has a jython implementation in https://code.google.com/p/django-jython/ check it out

How to use BCEL in java programming?

Is BCEL(Byte code Engineering Library) directly usable in normal java 1.6 or we need to download something for using it?
Or is this an in built library in java1.6?
It's not built in at all. You'll have to add the BCEL JARs to your CLASSPATH and write code in your app to use it.
I would not use BCEL. It seems to be more or less dead. Use ASM instead.
They are in com.sun packages, I would avoid the ones which come with the jdk; I agree with
both jmg and duffymo

Java compression and splitting library - preferrably 7zip

I am looking for a java library which can compress files and directories.
I need the following features
-compress
-decompress
-split archives to multiple files based on a size limit
I would really like the following features as well
-encrypt archives
-encrypt file names
I would prefer if the solution was a 7zip library but it's not required.
I know there is an lzma Java sdk but i'm not sure if it supports all the features above. I know it doesn't support encryption, but does it support splitting archives?
Any library supporting all the features above would be preferred.
Thanks.
How about the Deflater/Inflater classes mentioned in the question "What’s a good compression library for Java?".
I know the current interfaces proposed by Java are Stream-based, not "filename"-based, but according to the following article on Java compression.
TrueZip should be able to do most of what you need

Updating gzip library in jre

Is there a way to update gzip library that JRE uses?
There is a bug in gzip library that is used by latest JRE, and it has been fixed in later version of gzip library, so I would like to make latest JRE work by updating just gzip.
Bug is in a native code from gzip library that JRE uses.
Basically no (but you can probably do operating system magic to override the native library loader to include the new one).
Have you located this issue in the Java Bug Database? http://bugs.sun.com/
I think it's possible by setting the bootclasspath: http://java.sun.com/javase/6/docs/technotes/tools/solaris/java.html to override the class with the newer version.
Please read the warning: "Applications that use this option for the purpose of overriding a class in rt.jar should not be deployed as doing so would contravene the Java 2 Runtime Environment binary code license."
(Or if the bug is located in a native library, you could use java.library.path)
The short and simple answer is "no". At least you would not want to go there for all sorts of reasons.
Unfortunately Commons Compress also only uses the native compressor from java.util.zip but in your case I would still use Commons Compress so the compressor becomes easy to replace from the API point of view. Then write your own Compressor. In java if you don't need the speed or using JNI if want to really go for it. As soon as the bug is fixed in the JRE you can just switch the implementation back to the JRE one.

Categories