API for Java to rename/move files based on rulesets - java

I'm looking for an API to move/copy and rename files based on rulesets. Is there a better way than using only java.io and regexp?
Background: I want to write a small program to convert files (images) between different similar tools, but they all have different folder structures and different filenaming rules.

Ant knows to do this very well. Why not to write a task for ant that does what you want and use Ant filter for file filtering? Take a look on http://ant.apache.org/manual/Tasks/filter.html

Related

External Libraries in File Reading

Right now I am working on a project where I have to read a series of Strings in from a text file in java.
I know how to do it in the general way (using a FileReader, Buffer, etc.). My issue arises because I am not allowed to use external libraries at all. Are these considered external libraries?
To put things more easily, whats a good definition of an external library? Is it anything that I would have to import?
As a follow up question, how would I be able to read from a text file without using any of those libraries, if they're not allowed?
External libraries would be ones you download that do not come with Java API. An example would be the apache commons API. If you can just import it then it's not an external library.

Functional/regression testing for Java Applications working with files

I'm trying to find the best way to create automated testing for functional/acceptance/regression testing for some java applications. All the applications work in this way:
They read a File from a given folder
They write a new file in another format with the content of the input file.
They send to database some of the information of processed files.
They wait until a new file is left in the input folder.
This is a cyclic application, it never stops.
New files/formats are added continuously and several of our libraries are shared by all the formats. Manual testing is taking more and more cost with each new format. All the files are plain text files but with different format in the way data is saved.
We need a way/tool that could help us to automated the functional/acceptance/regression tests (specially QA tests).
The question is: What tool/way of testing can be used for this?
I was thinking in something that can left files in the input folder and compare what the application creates in output folder with an expected file. I donĀ“t know if this can be done easily with a tool or if we have to make all of this entirely.
I would use a generic functional test automation framework and use a set of libraries to read/parse/compare files. I am familiar with Robot Framework and there are some Python Libraries to read/compare files (some embedded in Robot itself, some elsewhere). That is very convenient and quite easy to use for QA Tests. Check out the demo project for a good start.
If you prefer to stick in the Java ecosystem, you might want to try Cucumber-jvm or JBehave.

What are the criteria(in the programming point of view) that one should keep in mind while creating a java jar(as library) file for android

I know how to create a jar file using Eclipse.
I was trying to create a share library so that I can avoid redundant source code. I have figured out that a jar should be :-
independent
should not make call to external class attributes(properties)/methods except the standard library imports.
The resources should be given as a parameter to jar file to perform a action.
Should work as a independent entity.
I tried to well organised my code in different packages also added MANIFEST.MF file.
This is first time I'm trying for data abstraction.
I would like to request suggestions/instructions as per the programmer point of view, what are the criteria that jar code should have ?
Is it good idea that my jar is or depend on another jar (viz java mail api jar) ?
Thanks in advance.
As you've tagged this with Android, I assume that Android is the intended use case.
The easiest way to share your code between several projects is probably to create a library project, this way you can keep the source code at hand too (less convenient to attach source to the jar every time you use it).

in java how to get files in a given directory

I want to write a java code, where given a directory name, I should be able to get all the files starting with list (so something like list*) and read each file one by one (linewise), and do some processing .
What classes are available and recommended to read a directory. Is my option is to read all file names by File.list and then pick the ones which start with list..
Thanks
Well, the most central class would be File.
Besides that there are some classes that File's methods need (like FileFilter etc.)
You can also try and have a look at utility libraries like Apache Commons IO.
You can list using a file filter as described here

Java library to create cabinet files on Unix?

Is there a Java library to create cabinet files on Unix. I don't need any compression support. I just want to create a plain cab file using Java.
Something similar to cablib (http://sourceforge.net/projects/cablib/) which can only be used for reading cab files would be perfect.
If there is really no library can I use a feasible work around? E.g. create a ZIP file and somehow convert it into a CAB file?
If there is really no library can I use a feasible work around?
Comments have suggested using the Linux Icab tool.
E.g. create a ZIP file and somehow convert it into a CAB file?
The ZIP file format is different in too many respects for there to be a simple transformation to turn a ZIP file into a CAB file.
Edit: The answer below isn't a pure java solution. Ant's CAB task documentation says it relies on a 3rd-party tool: Either MS's "CABARC" or the open-source "libcabinet", which seems to no longer exist. So there is no benefit to this approach compared to a 3rd-party system call.
Previous Answer (read above first):
If you need a pure java way of creating cab files (not extracting them), you can use ant's built-in "cab" task.
This gives you a few options:
Call the ant task from within your java code by using ant's
Launcher class;
Find the source code for the task definition (here) , and remove references to the ant context to create your own Cab extract utility
Run ant via a system call.

Categories