package com.mindprod.example;
import de.schlichtherle.io.ArchiveDetector;
import de.schlichtherle.io.DefaultArchiveDetector;
import de.schlichtherle.io.File;
import java.io.IOException;
import static java.lang.System.err;
import static java.lang.System.out;
/**
* Example use of TrueZip.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 2009-05-14 - initial version
* @since 2009-05-14
*/
public final class TestTrueZip
{
/**
* Example use of TrueZip
* <p/>
* You must first download the truezip jar from https://truezip.dev.java.net and put it in your ext directories.
* <p/>
* Run with parms C:\temp\temp.zip and E:\dir\somefile.html
* where temp.zip does not exist but E:\dir\somefile.html does.
* Or where temp.dir is a TrueZip compatible Zip file.
*
* @param args name of a TrueZip-compatible zip file to be created(or existing), name of a file to add to the zip file.
*
* @throws java.io.IOException on I/O failure.
*/
public static void main( String[] args ) throws IOException
{
final File zipFile = new File( args[ 0 ], new DefaultArchiveDetector( "zip" ) );
if ( !zipFile.exists() )
{
if ( !zipFile.mkdirs() )
{
err.println( "mkdirs failed" );
}
}
if ( !zipFile.isArchive() )
{
err.println( "First file must be TrueZip compatible zip" );
}
if ( !zipFile.isDirectory() )
{
err.println( "Archive not being treated as virtual zip." );
}
final File toAdd = new File( args[ 1 ], DefaultArchiveDetector.NULL );
if ( !toAdd.exists() )
{
err.println( args[ 1 ] + " file does not exist." );
}
File zipEntry = new File( zipFile, toAdd.getName(), ArchiveDetector.NULL );
out.println( "about to copy " + toAdd.getCanOrAbsPath() + " to zipentry: " + zipEntry.getCanOrAbsPath() );
if ( !toAdd.copyTo( zipEntry ) )
{
err.println( "add to zip failed" );
}
final File[] contents = ( File[] ) zipFile.listFiles();
out.println( "contents of zip:" );
for ( File content : contents )
{
out.println( content.getCanOrAbsPath() );
}
File.umount();
}
}