Monday 20 August 2012

IO-Utilities

Whenever I take any new project, I always require my Utilities library which provides me following features:

  1. Copying my library from dependency to  C Drive or  user's home directory in windows or *nix systems
  2. Compressing/Decompressing any Images or files for uploading or transferring it over network
  3. Getting extension of any file name in faster way
All this features can be achieved using just one library, and using this library is dam easy...even you can attach a listener to listen the processing i.e.
  • Name, count, size, compression level, copying from & copying to path of the file which library is processing ..

To attach a listener use this code



import fileutilslibrary.CopyEvent;
import fileutilslibrary.FileUtils;
import fileutilslibrary.Listener;
import fileutilslibrary.ZipEvent;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Naved Momin<naved.spartans.rocks75@gmail.com>
 */
public class Demo2 implements Listener{

    void start( ) throws IOException{
        FileUtils.getInstance().addListener(this);
     
        FileUtils.zipMyFolder(new File("C:\\Users\\Admin\\Desktop\\imgToVideo/RemoteDesktop"),
                  new File("C:/Users/Admin/Desktop/HMS Latest/RDnew.zip"),9);
                 

     
    }
    public static void main(String[] args) {
 
        try {
            // TODO code application logic here
            new Demo2().start();
        } catch (IOException ex) {
            Logger.getLogger(Demo2.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public void copyListener(CopyEvent e) {
        //notification about copying event
    }

    @Override
    public void zipListener(ZipEvent e) {
        //notification about zip event
        System.out.println( "name " +e.getZipingFileName() +  "\n" + "size " + e.getZipingFileSize() + "\n" +
        " count " + e.getFileCount( ) + "\n" +
        "level  " + e.getCompressionLevel() );
    }
}

Various Methods:-


Copy a Directory


FileUtils.copyDirectory(src, dest);

Copy a File


FileUtils.copyFile(src, dest);

Zip Directory 


FileUtils.zipMyFolder(src, dest);

Zip Directory With Custom Compression Level


FileUtils.zipMyFolder(src, dest, compressionLevel);

Note: Compression level must be between 0-9, by default 0 is used

Zip File


FileUtils.zipMyFile(src, dest);

Zip File With Custom Compression Level


FileUtils.zipMyFile(src, dest, compressionLevel);

Note: Compression level must be between 0-9, by default 0 is used

UnZip File


FileUtils.doUnZip(src, dest);

Get File Extension (10x faster)


FileUtils.getExtension(path);

Reverse a String


FileUtils.reverse(str);

Get File Name 


FileUtils.getName(pathToFile);


Note: The library is written in pure Java code except the Wallpaper class which throws NotSupportedOSException if OS is not supported by the library for more information see Javadoc included in the download package.
This library is totally compatible with various 3rd party zip utilities like winrar, which means you can zip your files programmatically and still use winrar for unzip'ing the file or vice-versa is also possible. 

For any bug or suggestions mail me at naved.spartans.rocks75@gmail.com

This Library is License under GNU General Public License

Download latest builds





1 comment:

  1. Awesome work! searching this for a while specially zip & unzip part

    ReplyDelete