You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ni...@apache.org on 2002/07/09 00:13:43 UTC
cvs commit: jakarta-commons-sandbox/io/src/examples/org/apache/commons/io/bzip2 Bzip2Compress.java Bzip2Uncompress.java package.html
nicolaken 2002/07/08 15:13:43
Added: io/src/examples/org/apache/commons/io/bzip2
Bzip2Compress.java Bzip2Uncompress.java
package.html
Log:
Samples for bzip2
Revision Changes Path
1.1 jakarta-commons-sandbox/io/src/examples/org/apache/commons/io/bzip2/Bzip2Compress.java
Index: Bzip2Compress.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.commons.io.compress.bzip2;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.excalibur.bzip2.CBZip2OutputStream;
/**
* This simple example shows how to use the Bzip2 classes to compress a file.
*
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/07/08 22:13:43 $
*/
public class Bzip2Compress
{
public static void main( final String[] args )
throws Exception
{
if( 2 != args.length )
{
System.out.println( "java Bzip2Compress <input> <output>" );
System.exit( 1 );
}
final File source = new File( args[ 0 ] );
final File destination = new File( args[ 1 ] );
final CBZip2OutputStream output =
new CBZip2OutputStream( new FileOutputStream( destination ) );
final FileInputStream input = new FileInputStream( source );
copy( input, output );
input.close();
output.close();
}
/**
* Copy bytes from an <code>InputStream</code> to an <code>OutputStream</code>.
*/
private static void copy( final InputStream input,
final OutputStream output )
throws IOException
{
final byte[] buffer = new byte[ 8024 ];
int n = 0;
while( -1 != ( n = input.read( buffer ) ) )
{
output.write( buffer, 0, n );
}
}
}
1.1 jakarta-commons-sandbox/io/src/examples/org/apache/commons/io/bzip2/Bzip2Uncompress.java
Index: Bzip2Uncompress.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.commons.io.compress.bzip2;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.excalibur.bzip2.CBZip2InputStream;
/**
* This simple example shows how to use the Bzip2 classes to uncompress a file.
*
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/07/08 22:13:43 $
*/
public class Bzip2Uncompress
{
public static void main( final String[] args )
{
if( 2 != args.length )
{
System.out.println( "java Bzip2Uncompress <input> <output>" );
System.exit( 1 );
}
final File source = new File( args[ 0 ] );
final File destination = new File( args[ 1 ] );
final FileOutputStream output =
new FileOutputStream( destination );
final CBZip2InputStream input = new CBZip2InputStream( new FileInputStream( source ) );
copy( input, output );
input.close();
output.close();
}
/**
* Copy bytes from an <code>InputStream</code> to an <code>OutputStream</code>.
*/
private static void copy( final InputStream input,
final OutputStream output )
throws IOException
{
final byte[] buffer = new byte[ 8024 ];
int n = 0;
while( -1 != ( n = input.read( buffer ) ) )
{
output.write( buffer, 0, n );
}
}
}
1.1 jakarta-commons-sandbox/io/src/examples/org/apache/commons/io/bzip2/package.html
Index: package.html
===================================================================
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
<br>
As always, the if you have any questions : <br>
<ol>
<li>Make sure you followed any directions </li>
<li>Review documentation included in this package</li>
<li>Ask on the commons-dev list. This is a great source of support
information. </li>
</ol>
To join, read http://jakarta.apache.org/site/mail.html and then follow
the link at the bottom to join the lists. <br>
<br>
<hr width="100%" size="2"><span
style="text-decoration: underline; font-weight: bold;">basic</span> <br>
<br>
This simple example shows how to use the Bzip2 classes to compress and uncompress
a file.<br>
If the file is a bzip2 archive it will uncompress else it will compress the
file. <br>
Compile it by running <br>
javac -classpath ../../build/lib/@dist.name@.jar *.java (Unix)
<br>
or <br>
javac -classpath ..\..\build\lib\@dist.name@.jar *.java (Windows)<br>
<br>
Run it using the following to compress:<br>
java -classpath ../../build/lib/@dist.name@.jar:. Bzip2Compress
README.txt README.txt.bz2 (Unix) <br>
or <br>
java -classpath ..\..\build\lib\@dist.name@.jar;. Bzip2Compress
README.txt README.txt.bz2 (Windows) <br>
<br>
And the following to uncompress:<br>
java -classpath ../../build/lib/@dist.name@.jar:. Bzip2Uncompress
README.txt.bz2 README.txt (Unix) <br>
or <br>
java -classpath ..\..\build\lib\@dist.name@.jar;. Bzip2Uncompress
README.txt.bz2 README.txt (Windows) <br>
</body>
</html>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>