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 version 6.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 2009-05-14 initial version
* @since 2009-05-14
*/
public final class TestTrueZIP6
{
/**
* Example use of TrueZIP 6
* <p/>
* You must first download the truezip-6.8.1.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.zip 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();
}
}