package com.mindprod.example;
import de.schlichtherle.truezip.file.TArchiveDetector;
import de.schlichtherle.truezip.file.TFile;
import java.io.EOFException;
import java.io.IOException;
import static java.lang.System.err;
import static java.lang.System.out;
/**
* Example use of TrueZIP 7.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 2011-05-13 initial version
* @since 2011-05-13
*/
public final class TestTrueZIP7
{
/**
* Example use of TrueZIP
* <p/>
* You must first download the truezip-7.jar, from https://truezip.dev.java.net
* prune out the ant and sample classes and put it in your ext directories.
* <p/>
* Run with parms C:\temp\temp.zip 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 TFile zipFile = new TFile( args[ 0 ], new TArchiveDetector( "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 TFile toAdd = new TFile( args[ 1 ], TArchiveDetector.NULL );
if ( !toAdd.exists() )
{
err.println( args[ 1 ] + " file does not exist." );
}
TFile zipEntry = new TFile( zipFile, toAdd.getName(), TArchiveDetector.NULL );
out.println( "about to copy " + toAdd.getCanOrAbsPath() + " to zipentry: " + zipEntry.getCanOrAbsPath() );
try
{
toAdd.cp_p( zipEntry );
}
catch ( EOFException e )
{
err.println( "add to zip failed" );
}
final TFile[] contents = ( TFile[] ) zipFile.listFiles();
out.println( "contents of zip:" );
for ( TFile content : contents )
{
out.println( content.getCanOrAbsPath() );
}
TFile.umount();
}
}