Skip to content

Commit c358911

Browse files
author
Nicola Ken Barozzi
committed
Samples for bzip2
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk@140300 13f79535-47bb-0310-9956-ffa450edef68
1 parent fb63d00 commit c358911

4 files changed

Lines changed: 176 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (C) The Apache Software Foundation. All rights reserved.
3+
*
4+
* This software is published under the terms of the Apache Software License
5+
* version 1.1, a copy of which has been included with this distribution in
6+
* the LICENSE.txt file.
7+
*/
8+
9+
package org.apache.commons.io.compress.bzip2;
10+
11+
import java.io.File;
12+
import java.io.FileInputStream;
13+
import java.io.FileOutputStream;
14+
import java.io.IOException;
15+
import java.io.InputStream;
16+
import java.io.OutputStream;
17+
import org.apache.excalibur.bzip2.CBZip2OutputStream;
18+
19+
/**
20+
* This simple example shows how to use the Bzip2 classes to compress a file.
21+
*
22+
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
23+
* @version $Revision: 1.1 $ $Date: 2002/07/08 22:13:43 $
24+
*/
25+
public class Bzip2Compress
26+
{
27+
public static void main( final String[] args )
28+
throws Exception
29+
{
30+
if( 2 != args.length )
31+
{
32+
System.out.println( "java Bzip2Compress <input> <output>" );
33+
System.exit( 1 );
34+
}
35+
36+
final File source = new File( args[ 0 ] );
37+
final File destination = new File( args[ 1 ] );
38+
final CBZip2OutputStream output =
39+
new CBZip2OutputStream( new FileOutputStream( destination ) );
40+
final FileInputStream input = new FileInputStream( source );
41+
copy( input, output );
42+
input.close();
43+
output.close();
44+
}
45+
46+
/**
47+
* Copy bytes from an <code>InputStream</code> to an <code>OutputStream</code>.
48+
*/
49+
private static void copy( final InputStream input,
50+
final OutputStream output )
51+
throws IOException
52+
{
53+
final byte[] buffer = new byte[ 8024 ];
54+
int n = 0;
55+
while( -1 != ( n = input.read( buffer ) ) )
56+
{
57+
output.write( buffer, 0, n );
58+
}
59+
}
60+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (C) The Apache Software Foundation. All rights reserved.
3+
*
4+
* This software is published under the terms of the Apache Software License
5+
* version 1.1, a copy of which has been included with this distribution in
6+
* the LICENSE.txt file.
7+
*/
8+
9+
package org.apache.commons.io.compress.bzip2;
10+
11+
import java.io.File;
12+
import java.io.FileInputStream;
13+
import java.io.FileOutputStream;
14+
import java.io.IOException;
15+
import java.io.InputStream;
16+
import java.io.OutputStream;
17+
import org.apache.excalibur.bzip2.CBZip2InputStream;
18+
19+
/**
20+
* This simple example shows how to use the Bzip2 classes to uncompress a file.
21+
*
22+
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
23+
* @version $Revision: 1.1 $ $Date: 2002/07/08 22:13:43 $
24+
*/
25+
public class Bzip2Uncompress
26+
{
27+
public static void main( final String[] args )
28+
{
29+
if( 2 != args.length )
30+
{
31+
System.out.println( "java Bzip2Uncompress <input> <output>" );
32+
System.exit( 1 );
33+
}
34+
final File source = new File( args[ 0 ] );
35+
final File destination = new File( args[ 1 ] );
36+
final FileOutputStream output =
37+
new FileOutputStream( destination );
38+
final CBZip2InputStream input = new CBZip2InputStream( new FileInputStream( source ) );
39+
copy( input, output );
40+
input.close();
41+
output.close();
42+
}
43+
44+
/**
45+
* Copy bytes from an <code>InputStream</code> to an <code>OutputStream</code>.
46+
*/
47+
private static void copy( final InputStream input,
48+
final OutputStream output )
49+
throws IOException
50+
{
51+
final byte[] buffer = new byte[ 8024 ];
52+
int n = 0;
53+
while( -1 != ( n = input.read( buffer ) ) )
54+
{
55+
output.write( buffer, 0, n );
56+
}
57+
}
58+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2+
<html>
3+
<head>
4+
<title></title>
5+
</head>
6+
<body>
7+
<br>
8+
As always, the if you have any questions : <br>
9+
<ol>
10+
<li>Make sure you followed any directions </li>
11+
<li>Review documentation included in this package</li>
12+
<li>Ask on the commons-dev list. This is a great source of support
13+
information. </li>
14+
</ol>
15+
To join, read http://jakarta.apache.org/site/mail.html and then follow
16+
the link at the bottom to join the lists. <br>
17+
<br>
18+
<hr width="100%" size="2"><span
19+
style="text-decoration: underline; font-weight: bold;">basic</span> <br>
20+
<br>
21+
This simple example shows how to use the Bzip2 classes to compress and uncompress
22+
a file.<br>
23+
If the file is a bzip2 archive it will uncompress else it will compress the
24+
file. <br>
25+
Compile it by running <br>
26+
&nbsp; &nbsp;javac -classpath ../../build/lib/@dist.name@.jar *.java (Unix)
27+
<br>
28+
or <br>
29+
&nbsp; &nbsp;javac -classpath ..\..\build\lib\@dist.name@.jar *.java (Windows)<br>
30+
<br>
31+
Run it using the following to compress:<br>
32+
&nbsp; &nbsp; java -classpath ../../build/lib/@dist.name@.jar:. Bzip2Compress
33+
README.txt README.txt.bz2 (Unix) <br>
34+
or <br>
35+
&nbsp; &nbsp; java -classpath ..\..\build\lib\@dist.name@.jar;. Bzip2Compress
36+
README.txt README.txt.bz2 (Windows) <br>
37+
<br>
38+
And the following to uncompress:<br>
39+
&nbsp;&nbsp; java -classpath ../../build/lib/@dist.name@.jar:. Bzip2Uncompress
40+
README.txt.bz2 README.txt (Unix) <br>
41+
or <br>
42+
&nbsp; &nbsp;java -classpath ..\..\build\lib\@dist.name@.jar;. Bzip2Uncompress
43+
README.txt.bz2 README.txt (Windows) <br>
44+
</body>
45+
</html>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<html>
2+
<head></head>
3+
<body bgcolor="white">
4+
<p>
5+
This simple example shows how to use the Bzip2 classes to compress and
6+
uncompress a file. If the file is a bzip2 archive it will uncompress
7+
else it will compress the file.
8+
</p>
9+
</body>
10+
</html>
11+
12+
13+

0 commit comments

Comments
 (0)