package com.mindprod.example;
import net.java.truevfs.access.TArchiveDetector;
import net.java.truevfs.access.TFile;
import net.java.truevfs.access.TVFS;
import java.io.EOFException;
import java.io.IOException;
import static java.lang.System.err;
import static java.lang.System.out;
/**
* Example use of TrueVFS.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 2012-11-23 initial version
* @since 2011-11-23
*/
public final class TestTrueVFS
{
/**
* Example use of TrueVFS
* <p/>
* You must first download the truevfs-profile-default-0.10.1-shaded.jar
* from http://truevfs.java.net/kick-start/no-maven.html
* put it in your ext directories.
* You also need slf4j-nop-1.7.2.jar to turn off logging.
* <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 TrueVFS compatible ZIP file.
*
* @param args name of a TrueVFS-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 TrueVFS 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." );
}
final 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 = zipFile.listFiles();
out.println( "contents of zip:" );
for ( TFile content : contents )
{
out.println( content.getCanOrAbsPath() );
}
TVFS.umount();
}
}