<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FFile%2FZip_Unzip</id>
		<title>Java Tutorial/File/Zip Unzip - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FFile%2FZip_Unzip"/>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/File/Zip_Unzip&amp;action=history"/>
		<updated>2026-04-07T00:34:51Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://jexp.ru/index.php?title=Java_Tutorial/File/Zip_Unzip&amp;diff=5352&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/File/Zip_Unzip&amp;diff=5352&amp;oldid=prev"/>
				<updated>2010-06-01T05:19:50Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 05:19, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://jexp.ru/index.php?title=Java_Tutorial/File/Zip_Unzip&amp;diff=5351&amp;oldid=prev</id>
		<title> в 17:44, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/File/Zip_Unzip&amp;diff=5351&amp;oldid=prev"/>
				<updated>2010-05-31T17:44:27Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==  Compare two zip files ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*   Copyright 2004 The Apache Software Foundation&lt;br /&gt;
 *&lt;br /&gt;
 *   Licensed under the Apache License, Version 2.0 (the &amp;quot;License&amp;quot;);&lt;br /&gt;
 *   you may not use this file except in compliance with the License.&lt;br /&gt;
 *   You may obtain a copy of the License at&lt;br /&gt;
 *&lt;br /&gt;
 *       http://www.apache.org/licenses/LICENSE-2.0&lt;br /&gt;
 *&lt;br /&gt;
 *   Unless required by applicable law or agreed to in writing, software&lt;br /&gt;
 *   distributed under the License is distributed on an &amp;quot;AS IS&amp;quot; BASIS,&lt;br /&gt;
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.&lt;br /&gt;
 *   See the License for the specific language governing permissions and&lt;br /&gt;
 *  limitations under the License.&lt;br /&gt;
 */&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
import java.util.Enumeration;&lt;br /&gt;
import java.util.Iterator;&lt;br /&gt;
import java.util.LinkedHashSet;&lt;br /&gt;
import java.util.Set;&lt;br /&gt;
import java.util.zip.ZipEntry;&lt;br /&gt;
import java.util.zip.ZipFile;&lt;br /&gt;
// From xml beans&lt;br /&gt;
public class ZipCompare {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    if (args.length != 2) {&lt;br /&gt;
      System.out.println(&amp;quot;Usage: zipcompare [file1] [file2]&amp;quot;);&lt;br /&gt;
      System.exit(1);&lt;br /&gt;
    }&lt;br /&gt;
    ZipFile file1;&lt;br /&gt;
    try {&lt;br /&gt;
      file1 = new ZipFile(args[0]);&lt;br /&gt;
    } catch (IOException e) {&lt;br /&gt;
      System.out.println(&amp;quot;Could not open zip file &amp;quot; + args[0] + &amp;quot;: &amp;quot; + e);&lt;br /&gt;
      System.exit(1);&lt;br /&gt;
      return;&lt;br /&gt;
    }&lt;br /&gt;
    ZipFile file2;&lt;br /&gt;
    try {&lt;br /&gt;
      file2 = new ZipFile(args[1]);&lt;br /&gt;
    } catch (IOException e) {&lt;br /&gt;
      System.out.println(&amp;quot;Could not open zip file &amp;quot; + args[0] + &amp;quot;: &amp;quot; + e);&lt;br /&gt;
      System.exit(1);&lt;br /&gt;
      return;&lt;br /&gt;
    }&lt;br /&gt;
    System.out.println(&amp;quot;Comparing &amp;quot; + args[0] + &amp;quot; with &amp;quot; + args[1] + &amp;quot;:&amp;quot;);&lt;br /&gt;
    Set set1 = new LinkedHashSet();&lt;br /&gt;
    for (Enumeration e = file1.entries(); e.hasMoreElements();)&lt;br /&gt;
      set1.add(((ZipEntry) e.nextElement()).getName());&lt;br /&gt;
    Set set2 = new LinkedHashSet();&lt;br /&gt;
    for (Enumeration e = file2.entries(); e.hasMoreElements();)&lt;br /&gt;
      set2.add(((ZipEntry) e.nextElement()).getName());&lt;br /&gt;
    int errcount = 0;&lt;br /&gt;
    int filecount = 0;&lt;br /&gt;
    for (Iterator i = set1.iterator(); i.hasNext();) {&lt;br /&gt;
      String name = (String) i.next();&lt;br /&gt;
      if (!set2.contains(name)) {&lt;br /&gt;
        System.out.println(name + &amp;quot; not found in &amp;quot; + args[1]);&lt;br /&gt;
        errcount += 1;&lt;br /&gt;
        continue;&lt;br /&gt;
      }&lt;br /&gt;
      try {&lt;br /&gt;
        set2.remove(name);&lt;br /&gt;
        if (!streamsEqual(file1.getInputStream(file1.getEntry(name)), file2.getInputStream(file2&lt;br /&gt;
            .getEntry(name)))) {&lt;br /&gt;
          System.out.println(name + &amp;quot; does not match&amp;quot;);&lt;br /&gt;
          errcount += 1;&lt;br /&gt;
          continue;&lt;br /&gt;
        }&lt;br /&gt;
      } catch (Exception e) {&lt;br /&gt;
        System.out.println(name + &amp;quot;: IO Error &amp;quot; + e);&lt;br /&gt;
        e.printStackTrace();&lt;br /&gt;
        errcount += 1;&lt;br /&gt;
        continue;&lt;br /&gt;
      }&lt;br /&gt;
      filecount += 1;&lt;br /&gt;
    }&lt;br /&gt;
    for (Iterator i = set2.iterator(); i.hasNext();) {&lt;br /&gt;
      String name = (String) i.next();&lt;br /&gt;
      System.out.println(name + &amp;quot; not found in &amp;quot; + args[0]);&lt;br /&gt;
      errcount += 1;&lt;br /&gt;
    }&lt;br /&gt;
    System.out.println(filecount + &amp;quot; entries matched&amp;quot;);&lt;br /&gt;
    if (errcount &amp;gt; 0) {&lt;br /&gt;
      System.out.println(errcount + &amp;quot; entries did not match&amp;quot;);&lt;br /&gt;
      System.exit(1);&lt;br /&gt;
    }&lt;br /&gt;
    System.exit(0);&lt;br /&gt;
  }&lt;br /&gt;
  static boolean streamsEqual(InputStream stream1, InputStream stream2) throws IOException {&lt;br /&gt;
    byte[] buf1 = new byte[4096];&lt;br /&gt;
    byte[] buf2 = new byte[4096];&lt;br /&gt;
    boolean done1 = false;&lt;br /&gt;
    boolean done2 = false;&lt;br /&gt;
    try {&lt;br /&gt;
      while (!done1) {&lt;br /&gt;
        int off1 = 0;&lt;br /&gt;
        int off2 = 0;&lt;br /&gt;
        while (off1 &amp;lt; buf1.length) {&lt;br /&gt;
          int count = stream1.read(buf1, off1, buf1.length - off1);&lt;br /&gt;
          if (count &amp;lt; 0) {&lt;br /&gt;
            done1 = true;&lt;br /&gt;
            break;&lt;br /&gt;
          }&lt;br /&gt;
          off1 += count;&lt;br /&gt;
        }&lt;br /&gt;
        while (off2 &amp;lt; buf2.length) {&lt;br /&gt;
          int count = stream2.read(buf2, off2, buf2.length - off2);&lt;br /&gt;
          if (count &amp;lt; 0) {&lt;br /&gt;
            done2 = true;&lt;br /&gt;
            break;&lt;br /&gt;
          }&lt;br /&gt;
          off2 += count;&lt;br /&gt;
        }&lt;br /&gt;
        if (off1 != off2 || done1 != done2)&lt;br /&gt;
          return false;&lt;br /&gt;
        for (int i = 0; i &amp;lt; off1; i++) {&lt;br /&gt;
          if (buf1[i] != buf2[i])&lt;br /&gt;
            return false;&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
      return true;&lt;br /&gt;
    } finally {&lt;br /&gt;
      stream1.close();&lt;br /&gt;
      stream2.close();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Compress a Byte Array ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.io.ByteArrayOutputStream;&lt;br /&gt;
import java.util.zip.Deflater;&lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] argv) throws Exception {&lt;br /&gt;
    byte[] input = &amp;quot;asdf&amp;quot;.getBytes();&lt;br /&gt;
    Deflater compressor = new Deflater();&lt;br /&gt;
    compressor.setLevel(Deflater.BEST_COMPRESSION);&lt;br /&gt;
    compressor.setInput(input);&lt;br /&gt;
    compressor.finish();&lt;br /&gt;
    ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length);&lt;br /&gt;
    byte[] buf = new byte[1024];&lt;br /&gt;
    while (!compressor.finished()) {&lt;br /&gt;
      int count = compressor.deflate(buf);&lt;br /&gt;
      bos.write(buf, 0, count);&lt;br /&gt;
    }&lt;br /&gt;
    bos.close();&lt;br /&gt;
    byte[] compressedData = bos.toByteArray();&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Compress Java objects ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.io.FileOutputStream;&lt;br /&gt;
import java.io.ObjectOutputStream;&lt;br /&gt;
import java.io.Serializable;&lt;br /&gt;
import java.util.zip.GZIPOutputStream;&lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] args) throws Exception {&lt;br /&gt;
    User admin = new User();&lt;br /&gt;
    admin.setId(new Long(1));&lt;br /&gt;
    User foo = new User();&lt;br /&gt;
    foo.setId(new Long(2));&lt;br /&gt;
    &lt;br /&gt;
    ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(new FileOutputStream(new File(&amp;quot;user.dat&amp;quot;))));&lt;br /&gt;
    oos.writeObject(admin);&lt;br /&gt;
    oos.writeObject(foo);&lt;br /&gt;
    oos.flush();&lt;br /&gt;
    oos.close();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class User implements Serializable {&lt;br /&gt;
  private Long id;&lt;br /&gt;
  public User() {&lt;br /&gt;
  }&lt;br /&gt;
  public Long getId() {&lt;br /&gt;
    return id;&lt;br /&gt;
  }&lt;br /&gt;
  public void setId(Long id) {&lt;br /&gt;
    this.id = id;&lt;br /&gt;
  }&lt;br /&gt;
  @Override&lt;br /&gt;
  public String toString() {&lt;br /&gt;
    StringBuilder sb = new StringBuilder();&lt;br /&gt;
    sb.append(&amp;quot;id=&amp;quot;).append(id);&lt;br /&gt;
    return sb.toString();&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Compress string(byte array) by Deflater ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.FileOutputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.util.zip.Deflater;&lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] args) throws IOException {&lt;br /&gt;
    Deflater def = new Deflater();&lt;br /&gt;
    byte[] input = new byte[1024];&lt;br /&gt;
    byte[] output = new byte[1024];&lt;br /&gt;
    FileInputStream fin = new FileInputStream(&amp;quot;a.dat&amp;quot;);&lt;br /&gt;
    FileOutputStream fout = new FileOutputStream(&amp;quot;b.dat&amp;quot;);&lt;br /&gt;
    int numRead = fin.read(input);&lt;br /&gt;
    def.setInput(input, 0, numRead);&lt;br /&gt;
    while (!def.needsInput()) {&lt;br /&gt;
      int numCompressedBytes = def.deflate(output, 0, output.length);&lt;br /&gt;
      if (numCompressedBytes &amp;gt; 0) {&lt;br /&gt;
        fout.write(output, 0, numCompressedBytes);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    def.finish();&lt;br /&gt;
    fin.close();&lt;br /&gt;
    fout.flush();&lt;br /&gt;
    fout.close();&lt;br /&gt;
    def.reset();&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Decompress a Byte Array ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.io.ByteArrayOutputStream;&lt;br /&gt;
import java.util.zip.Inflater;&lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] argv) throws Exception {&lt;br /&gt;
    byte[] compressedData = null;&lt;br /&gt;
    Inflater decompressor = new Inflater();&lt;br /&gt;
    decompressor.setInput(compressedData);&lt;br /&gt;
    ByteArrayOutputStream bos = new ByteArrayOutputStream(compressedData.length);&lt;br /&gt;
    byte[] buf = new byte[1024];&lt;br /&gt;
    while (!decompressor.finished()) {&lt;br /&gt;
      int count = decompressor.inflate(buf);&lt;br /&gt;
      bos.write(buf, 0, count);&lt;br /&gt;
    }&lt;br /&gt;
    bos.close();&lt;br /&gt;
    byte[] decompressedData = bos.toByteArray();&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Decompress a zip file using ZipFile ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.io.BufferedInputStream;&lt;br /&gt;
import java.io.BufferedOutputStream;&lt;br /&gt;
import java.io.FileOutputStream;&lt;br /&gt;
import java.util.Enumeration;&lt;br /&gt;
import java.util.zip.ZipEntry;&lt;br /&gt;
import java.util.zip.ZipFile;&lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] args) throws Exception {&lt;br /&gt;
    String zipname = &amp;quot;data.zip&amp;quot;;&lt;br /&gt;
    ZipFile zipFile = new ZipFile(zipname);&lt;br /&gt;
    Enumeration enumeration = zipFile.entries();&lt;br /&gt;
    while (enumeration.hasMoreElements()) {&lt;br /&gt;
      ZipEntry zipEntry = (ZipEntry) enumeration.nextElement();&lt;br /&gt;
      System.out.println(&amp;quot;Unzipping: &amp;quot; + zipEntry.getName());&lt;br /&gt;
      BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(zipEntry));&lt;br /&gt;
      int size;&lt;br /&gt;
      byte[] buffer = new byte[2048];&lt;br /&gt;
      BufferedOutputStream bos = new BufferedOutputStream(&lt;br /&gt;
          new FileOutputStream(zipEntry.getName()), buffer.length);&lt;br /&gt;
      while ((size = bis.read(buffer, 0, buffer.length)) != -1) {&lt;br /&gt;
        bos.write(buffer, 0, size);&lt;br /&gt;
      }&lt;br /&gt;
      bos.flush();&lt;br /&gt;
      bos.close();&lt;br /&gt;
      bis.close();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Decompress Java objects ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.ObjectInputStream;&lt;br /&gt;
import java.io.Serializable;&lt;br /&gt;
import java.util.zip.GZIPInputStream;&lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] args) throws Exception {&lt;br /&gt;
    ObjectInputStream ois = new ObjectInputStream(new GZIPInputStream(new FileInputStream(new File(&lt;br /&gt;
        &amp;quot;user.dat&amp;quot;))));&lt;br /&gt;
    User admin = (User) ois.readObject();&lt;br /&gt;
    User foo = (User) ois.readObject();&lt;br /&gt;
    ois.close();&lt;br /&gt;
    System.out.println(&amp;quot;Admin = [&amp;quot; + admin + &amp;quot;]&amp;quot;);&lt;br /&gt;
    System.out.println(&amp;quot;Foo = [&amp;quot; + foo + &amp;quot;]&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class User implements Serializable {&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  gzip ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.FileOutputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
import java.io.OutputStream;&lt;br /&gt;
import java.util.zip.GZIPOutputStream;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public final static String GZIP_SUFFIX = &amp;quot;.gz&amp;quot;;&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    for (int i = 0; i &amp;lt; args.length; i++) {&lt;br /&gt;
      try {&lt;br /&gt;
        InputStream fin = new FileInputStream(args[i]);&lt;br /&gt;
        OutputStream fout = new FileOutputStream(args[i] + GZIP_SUFFIX);&lt;br /&gt;
        GZIPOutputStream gzout = new GZIPOutputStream(fout);&lt;br /&gt;
        for (int c = fin.read(); c != -1; c = fin.read()) {&lt;br /&gt;
          gzout.write(c);&lt;br /&gt;
        }&lt;br /&gt;
        gzout.close();&lt;br /&gt;
      } catch (IOException ex) {&lt;br /&gt;
        System.err.println(ex);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Put file To Zip File ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright 2004 Outerthought bvba and Schaubroeck nv&lt;br /&gt;
 *&lt;br /&gt;
 * Licensed under the Apache License, Version 2.0 (the &amp;quot;License&amp;quot;);&lt;br /&gt;
 * you may not use this file except in compliance with the License.&lt;br /&gt;
 * You may obtain a copy of the License at&lt;br /&gt;
 *&lt;br /&gt;
 *     http://www.apache.org/licenses/LICENSE-2.0&lt;br /&gt;
 *&lt;br /&gt;
 * Unless required by applicable law or agreed to in writing, software&lt;br /&gt;
 * distributed under the License is distributed on an &amp;quot;AS IS&amp;quot; BASIS,&lt;br /&gt;
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.&lt;br /&gt;
 * See the License for the specific language governing permissions and&lt;br /&gt;
 * limitations under the License.&lt;br /&gt;
 */&lt;br /&gt;
// revised from outerj daisy&lt;br /&gt;
import java.io.*;&lt;br /&gt;
import java.util.zip.ZipOutputStream;&lt;br /&gt;
import java.util.zip.ZipEntry;&lt;br /&gt;
public class ZipHelper {&lt;br /&gt;
    private static int BUFFER_SIZE = 32768;&lt;br /&gt;
    public static void fileToZip(File file, File zipFile, int compressionLevel) throws Exception {&lt;br /&gt;
        zipFile.createNewFile();&lt;br /&gt;
        FileOutputStream fout = new FileOutputStream(zipFile);&lt;br /&gt;
        ZipOutputStream zout = null;&lt;br /&gt;
        try {&lt;br /&gt;
            zout = new ZipOutputStream(new BufferedOutputStream(fout));&lt;br /&gt;
            zout.setLevel(compressionLevel);&lt;br /&gt;
            if (file.isDirectory()) {&lt;br /&gt;
                File[] files = file.listFiles();&lt;br /&gt;
                for (int i = 0; i &amp;lt; files.length; i++)&lt;br /&gt;
                    fileToZip(files[i], zout, file);&lt;br /&gt;
            } else if (file.isFile()) {&lt;br /&gt;
                fileToZip(file, zout, file.getParentFile());&lt;br /&gt;
            }&lt;br /&gt;
        } finally {&lt;br /&gt;
            if (zout != null)&lt;br /&gt;
                zout.close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    private static void fileToZip(File file, ZipOutputStream zout, File baseDir) throws Exception {&lt;br /&gt;
        String entryName = file.getPath().substring(baseDir.getPath().length() + 1);&lt;br /&gt;
        if (File.separatorChar != &amp;quot;/&amp;quot;)&lt;br /&gt;
          entryName = entryName.replace(File.separator, &amp;quot;/&amp;quot;);&lt;br /&gt;
        if (file.isDirectory()) {&lt;br /&gt;
            zout.putNextEntry(new ZipEntry(entryName + &amp;quot;/&amp;quot;));&lt;br /&gt;
            zout.closeEntry();&lt;br /&gt;
            File[] files = file.listFiles();&lt;br /&gt;
            for (int i = 0; i &amp;lt; files.length; i++)&lt;br /&gt;
                fileToZip(files[i], zout, baseDir);&lt;br /&gt;
        } else {&lt;br /&gt;
            FileInputStream is = null;&lt;br /&gt;
            try {&lt;br /&gt;
                is = new FileInputStream(file);&lt;br /&gt;
                zout.putNextEntry(new ZipEntry(entryName));&lt;br /&gt;
                streamCopy(is, zout);&lt;br /&gt;
            } finally {&lt;br /&gt;
                zout.closeEntry();&lt;br /&gt;
                if (is != null)&lt;br /&gt;
                    is.close();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    private static void streamCopy(InputStream is, OutputStream os) throws IOException {&lt;br /&gt;
        byte[] buffer = new byte[BUFFER_SIZE];&lt;br /&gt;
        int len;&lt;br /&gt;
        while ((len = is.read(buffer)) &amp;gt; 0) {&lt;br /&gt;
            os.write(buffer, 0, len);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Unpack an archive from a URL ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Licensed to the Apache Software Foundation (ASF) under one or more&lt;br /&gt;
 * contributor license agreements.  See the NOTICE file distributed with&lt;br /&gt;
 * this work for additional information regarding copyright ownership.&lt;br /&gt;
 * The ASF licenses this file to You under the Apache License, Version 2.0&lt;br /&gt;
 * (the &amp;quot;License&amp;quot;); you may not use this file except in compliance with&lt;br /&gt;
 * the License.  You may obtain a copy of the License at&lt;br /&gt;
 *&lt;br /&gt;
 *      http://www.apache.org/licenses/LICENSE-2.0&lt;br /&gt;
 *&lt;br /&gt;
 * Unless required by applicable law or agreed to in writing, software&lt;br /&gt;
 * distributed under the License is distributed on an &amp;quot;AS IS&amp;quot; BASIS,&lt;br /&gt;
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.&lt;br /&gt;
 * See the License for the specific language governing permissions and&lt;br /&gt;
 * limitations under the License.&lt;br /&gt;
 */&lt;br /&gt;
 &lt;br /&gt;
import java.io.BufferedInputStream;&lt;br /&gt;
import java.io.BufferedOutputStream;&lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.io.FileOutputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
import java.io.OutputStream;&lt;br /&gt;
import java.net.URL;&lt;br /&gt;
import java.util.Enumeration;&lt;br /&gt;
import java.util.zip.ZipEntry;&lt;br /&gt;
import java.util.zip.ZipFile;&lt;br /&gt;
public class Utils {&lt;br /&gt;
  /**&lt;br /&gt;
   * Unpack an archive from a URL&lt;br /&gt;
   * &lt;br /&gt;
   * @param url&lt;br /&gt;
   * @param targetDir&lt;br /&gt;
   * @return the file to the url&lt;br /&gt;
   * @throws IOException&lt;br /&gt;
   */&lt;br /&gt;
  public static File unpackArchive(URL url, File targetDir) throws IOException {&lt;br /&gt;
      if (!targetDir.exists()) {&lt;br /&gt;
          targetDir.mkdirs();&lt;br /&gt;
      }&lt;br /&gt;
      InputStream in = new BufferedInputStream(url.openStream(), 1024);&lt;br /&gt;
      // make sure we get the actual file&lt;br /&gt;
      File zip = File.createTempFile(&amp;quot;arc&amp;quot;, &amp;quot;.zip&amp;quot;, targetDir);&lt;br /&gt;
      OutputStream out = new BufferedOutputStream(new FileOutputStream(zip));&lt;br /&gt;
      copyInputStream(in, out);&lt;br /&gt;
      out.close();&lt;br /&gt;
      return unpackArchive(zip, targetDir);&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Unpack a zip file&lt;br /&gt;
   * &lt;br /&gt;
   * @param theFile&lt;br /&gt;
   * @param targetDir&lt;br /&gt;
   * @return the file&lt;br /&gt;
   * @throws IOException&lt;br /&gt;
   */&lt;br /&gt;
  public static File unpackArchive(File theFile, File targetDir) throws IOException {&lt;br /&gt;
      if (!theFile.exists()) {&lt;br /&gt;
          throw new IOException(theFile.getAbsolutePath() + &amp;quot; does not exist&amp;quot;);&lt;br /&gt;
      }&lt;br /&gt;
      if (!buildDirectory(targetDir)) {&lt;br /&gt;
          throw new IOException(&amp;quot;Could not create directory: &amp;quot; + targetDir);&lt;br /&gt;
      }&lt;br /&gt;
      ZipFile zipFile = new ZipFile(theFile);&lt;br /&gt;
      for (Enumeration entries = zipFile.entries(); entries.hasMoreElements();) {&lt;br /&gt;
          ZipEntry entry = (ZipEntry) entries.nextElement();&lt;br /&gt;
          File file = new File(targetDir, File.separator + entry.getName());&lt;br /&gt;
          if (!buildDirectory(file.getParentFile())) {&lt;br /&gt;
              throw new IOException(&amp;quot;Could not create directory: &amp;quot; + file.getParentFile());&lt;br /&gt;
          }&lt;br /&gt;
          if (!entry.isDirectory()) {&lt;br /&gt;
              copyInputStream(zipFile.getInputStream(entry), new BufferedOutputStream(new FileOutputStream(file)));&lt;br /&gt;
          } else {&lt;br /&gt;
              if (!buildDirectory(file)) {&lt;br /&gt;
                  throw new IOException(&amp;quot;Could not create directory: &amp;quot; + file);&lt;br /&gt;
              }&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
      zipFile.close();&lt;br /&gt;
      return theFile;&lt;br /&gt;
  }&lt;br /&gt;
  public static void copyInputStream(InputStream in, OutputStream out) throws IOException {&lt;br /&gt;
      byte[] buffer = new byte[1024];&lt;br /&gt;
      int len = in.read(buffer);&lt;br /&gt;
      while (len &amp;gt;= 0) {&lt;br /&gt;
          out.write(buffer, 0, len);&lt;br /&gt;
          len = in.read(buffer);&lt;br /&gt;
      }&lt;br /&gt;
      in.close();&lt;br /&gt;
      out.close();&lt;br /&gt;
  }&lt;br /&gt;
  public static boolean buildDirectory(File file) {&lt;br /&gt;
      return file.exists() || file.mkdirs();&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Unpack a segment from a zip ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.io.FileOutputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
import java.util.zip.ZipEntry;&lt;br /&gt;
import java.util.zip.ZipInputStream;&lt;br /&gt;
public class Utils {&lt;br /&gt;
  /**&lt;br /&gt;
   * unpack a segment from a zip&lt;br /&gt;
   * &lt;br /&gt;
   * @param addsi&lt;br /&gt;
   * @param packetStream&lt;br /&gt;
   * @param version&lt;br /&gt;
   */&lt;br /&gt;
  public static void unpack(InputStream source, File destination) throws IOException {&lt;br /&gt;
    ZipInputStream zin = new ZipInputStream(source);&lt;br /&gt;
    ZipEntry zipEntry = null;&lt;br /&gt;
    FileOutputStream fout = null;&lt;br /&gt;
    byte[] buffer = new byte[4096];&lt;br /&gt;
    while ((zipEntry = zin.getNextEntry()) != null) {&lt;br /&gt;
      long ts = zipEntry.getTime();&lt;br /&gt;
      // the zip entry needs to be a full path from the&lt;br /&gt;
      // searchIndexDirectory... hence this is correct&lt;br /&gt;
      File f = new File(destination, zipEntry.getName());&lt;br /&gt;
      f.getParentFile().mkdirs();&lt;br /&gt;
      fout = new FileOutputStream(f);&lt;br /&gt;
      int len;&lt;br /&gt;
      while ((len = zin.read(buffer)) &amp;gt; 0) {&lt;br /&gt;
        fout.write(buffer, 0, len);&lt;br /&gt;
      }&lt;br /&gt;
      zin.closeEntry();&lt;br /&gt;
      fout.close();&lt;br /&gt;
      f.setLastModified(ts);&lt;br /&gt;
    }&lt;br /&gt;
    fout.close();&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Unzip ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.io.FileOutputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
import java.util.Enumeration;&lt;br /&gt;
import java.util.zip.ZipEntry;&lt;br /&gt;
import java.util.zip.ZipFile;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) throws IOException {&lt;br /&gt;
    ZipFile zf = new ZipFile(args[0]);&lt;br /&gt;
    Enumeration e = zf.entries();&lt;br /&gt;
    while (e.hasMoreElements()) {&lt;br /&gt;
      ZipEntry ze = (ZipEntry) e.nextElement();&lt;br /&gt;
      System.out.println(&amp;quot;Unzipping &amp;quot; + ze.getName());&lt;br /&gt;
      FileOutputStream fout = new FileOutputStream(ze.getName());&lt;br /&gt;
      InputStream in = zf.getInputStream(ze);&lt;br /&gt;
      for (int c = in.read(); c != -1; c = in.read()) {&lt;br /&gt;
        fout.write(c);&lt;br /&gt;
      }&lt;br /&gt;
      in.close();&lt;br /&gt;
      fout.close();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  unzip File Into Directory ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.io.FileOutputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
import java.util.Enumeration;&lt;br /&gt;
import java.util.zip.ZipEntry;&lt;br /&gt;
import java.util.zip.ZipFile;&lt;br /&gt;
/**&lt;br /&gt;
 * @author csterling&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
public class ZipFileUtil {&lt;br /&gt;
  /**&lt;br /&gt;
   * @param zipFile&lt;br /&gt;
   * @param jiniHomeParentDir&lt;br /&gt;
   */&lt;br /&gt;
  public static void unzipFileIntoDirectory(ZipFile zipFile, File jiniHomeParentDir) {&lt;br /&gt;
    Enumeration files = zipFile.entries();&lt;br /&gt;
    File f = null;&lt;br /&gt;
    FileOutputStream fos = null;&lt;br /&gt;
    &lt;br /&gt;
    while (files.hasMoreElements()) {&lt;br /&gt;
      try {&lt;br /&gt;
        ZipEntry entry = (ZipEntry) files.nextElement();&lt;br /&gt;
        InputStream eis = zipFile.getInputStream(entry);&lt;br /&gt;
        byte[] buffer = new byte[1024];&lt;br /&gt;
        int bytesRead = 0;&lt;br /&gt;
  &lt;br /&gt;
        f = new File(jiniHomeParentDir.getAbsolutePath() + File.separator + entry.getName());&lt;br /&gt;
        &lt;br /&gt;
        if (entry.isDirectory()) {&lt;br /&gt;
          f.mkdirs();&lt;br /&gt;
          continue;&lt;br /&gt;
        } else {&lt;br /&gt;
          f.getParentFile().mkdirs();&lt;br /&gt;
          f.createNewFile();&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        fos = new FileOutputStream(f);&lt;br /&gt;
  &lt;br /&gt;
        while ((bytesRead = eis.read(buffer)) != -1) {&lt;br /&gt;
          fos.write(buffer, 0, bytesRead);&lt;br /&gt;
        }&lt;br /&gt;
      } catch (IOException e) {&lt;br /&gt;
        e.printStackTrace();&lt;br /&gt;
        continue;&lt;br /&gt;
      } finally {&lt;br /&gt;
        if (fos != null) {&lt;br /&gt;
          try {&lt;br /&gt;
            fos.close();&lt;br /&gt;
          } catch (IOException e) {&lt;br /&gt;
            // ignore&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Uses Zip compression to compress any number of files given on the command line ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.io.BufferedInputStream;&lt;br /&gt;
import java.io.BufferedOutputStream;&lt;br /&gt;
import java.io.BufferedReader;&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.FileOutputStream;&lt;br /&gt;
import java.io.FileReader;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.util.Enumeration;&lt;br /&gt;
import java.util.zip.Adler32;&lt;br /&gt;
import java.util.zip.CheckedInputStream;&lt;br /&gt;
import java.util.zip.CheckedOutputStream;&lt;br /&gt;
import java.util.zip.ZipEntry;&lt;br /&gt;
import java.util.zip.ZipFile;&lt;br /&gt;
import java.util.zip.ZipInputStream;&lt;br /&gt;
import java.util.zip.ZipOutputStream;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) throws IOException {&lt;br /&gt;
    FileOutputStream f = new FileOutputStream(&amp;quot;test.zip&amp;quot;);&lt;br /&gt;
    CheckedOutputStream csum = new CheckedOutputStream(f, new Adler32());&lt;br /&gt;
    ZipOutputStream zos = new ZipOutputStream(csum);&lt;br /&gt;
    BufferedOutputStream out = new BufferedOutputStream(zos);&lt;br /&gt;
    zos.setComment(&amp;quot;A test of Java Zipping&amp;quot;);&lt;br /&gt;
    for (int i = 0; i &amp;lt; args.length; i++) {&lt;br /&gt;
      System.out.println(&amp;quot;Writing file &amp;quot; + args[i]);&lt;br /&gt;
      BufferedReader in = new BufferedReader(new FileReader(args[i]));&lt;br /&gt;
      zos.putNextEntry(new ZipEntry(args[i]));&lt;br /&gt;
      int c;&lt;br /&gt;
      while ((c = in.read()) != -1)&lt;br /&gt;
        out.write(c);&lt;br /&gt;
      in.close();&lt;br /&gt;
    }&lt;br /&gt;
    out.close();&lt;br /&gt;
&lt;br /&gt;
    System.out.println(&amp;quot;Checksum: &amp;quot; + csum.getChecksum().getValue());&lt;br /&gt;
    System.out.println(&amp;quot;Reading file&amp;quot;);&lt;br /&gt;
    FileInputStream fi = new FileInputStream(&amp;quot;test.zip&amp;quot;);&lt;br /&gt;
    CheckedInputStream csumi = new CheckedInputStream(fi, new Adler32());&lt;br /&gt;
    ZipInputStream in2 = new ZipInputStream(csumi);&lt;br /&gt;
    BufferedInputStream bis = new BufferedInputStream(in2);&lt;br /&gt;
    ZipEntry ze;&lt;br /&gt;
    while ((ze = in2.getNextEntry()) != null) {&lt;br /&gt;
      System.out.println(&amp;quot;Reading file &amp;quot; + ze);&lt;br /&gt;
      int x;&lt;br /&gt;
      while ((x = bis.read()) != -1)&lt;br /&gt;
        System.out.write(x);&lt;br /&gt;
    }&lt;br /&gt;
    System.out.println(&amp;quot;Checksum: &amp;quot; + csumi.getChecksum().getValue());&lt;br /&gt;
    bis.close();&lt;br /&gt;
&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Zip a list of file into one zip file. ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.FileNotFoundException;&lt;br /&gt;
import java.io.FileOutputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.util.zip.ZipEntry;&lt;br /&gt;
import java.util.zip.ZipOutputStream;&lt;br /&gt;
public class Utils {&lt;br /&gt;
  /**&lt;br /&gt;
   * Zip a list of file into one zip file.&lt;br /&gt;
   * &lt;br /&gt;
   * @param files&lt;br /&gt;
   *          files to zip&lt;br /&gt;
   * @param targetZipFile&lt;br /&gt;
   *          target zip file&lt;br /&gt;
   * @throws IOException&lt;br /&gt;
   *           IO error exception can be thrown when copying ...&lt;br /&gt;
   */&lt;br /&gt;
  public static void zipFile(final File[] files, final File targetZipFile) throws IOException {&lt;br /&gt;
    try {&lt;br /&gt;
      FileOutputStream   fos = new FileOutputStream(targetZipFile);&lt;br /&gt;
      ZipOutputStream zos = new ZipOutputStream(fos);&lt;br /&gt;
      byte[] buffer = new byte[128];&lt;br /&gt;
      for (int i = 0; i &amp;lt; files.length; i++) {&lt;br /&gt;
        File currentFile = files[i];&lt;br /&gt;
        if (!currentFile.isDirectory()) {&lt;br /&gt;
          ZipEntry entry = new ZipEntry(currentFile.getName());&lt;br /&gt;
          FileInputStream fis = new FileInputStream(currentFile);&lt;br /&gt;
          zos.putNextEntry(entry);&lt;br /&gt;
          int read = 0;&lt;br /&gt;
          while ((read = fis.read(buffer)) != -1) {&lt;br /&gt;
            zos.write(buffer, 0, read);&lt;br /&gt;
          }&lt;br /&gt;
          zos.closeEntry();&lt;br /&gt;
          fis.close();&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
      zos.close();&lt;br /&gt;
      fos.close();&lt;br /&gt;
    } catch (FileNotFoundException e) {&lt;br /&gt;
      System.out.println(&amp;quot;File not found : &amp;quot; + e);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Zip files ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.FileOutputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.util.zip.ZipEntry;&lt;br /&gt;
import java.util.zip.ZipOutputStream;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) throws IOException {&lt;br /&gt;
    String outputFile = &amp;quot;new.zip&amp;quot;;&lt;br /&gt;
    // Default to maximum compression&lt;br /&gt;
    int level = 9;&lt;br /&gt;
    int start = 1;&lt;br /&gt;
    FileOutputStream fout = new FileOutputStream(outputFile);&lt;br /&gt;
    ZipOutputStream zout = new ZipOutputStream(fout);&lt;br /&gt;
    zout.setLevel(level);&lt;br /&gt;
    for (int i = start; i &amp;lt; args.length; i++) {&lt;br /&gt;
      ZipEntry ze = new ZipEntry(args[i]);&lt;br /&gt;
      FileInputStream fin = new FileInputStream(args[i]);&lt;br /&gt;
      try {&lt;br /&gt;
        System.out.println(&amp;quot;Compressing &amp;quot; + args[i]);&lt;br /&gt;
        zout.putNextEntry(ze);&lt;br /&gt;
        for (int c = fin.read(); c != -1; c = fin.read()) {&lt;br /&gt;
          zout.write(c);&lt;br /&gt;
        }&lt;br /&gt;
      } finally {&lt;br /&gt;
        fin.close();&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    zout.close();&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Zip up a directory ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Licensed to the Apache Software Foundation (ASF) under one or more&lt;br /&gt;
 * contributor license agreements.  See the NOTICE file distributed with&lt;br /&gt;
 * this work for additional information regarding copyright ownership.&lt;br /&gt;
 * The ASF licenses this file to You under the Apache License, Version 2.0&lt;br /&gt;
 * (the &amp;quot;License&amp;quot;); you may not use this file except in compliance with&lt;br /&gt;
 * the License.  You may obtain a copy of the License at&lt;br /&gt;
 *&lt;br /&gt;
 *      http://www.apache.org/licenses/LICENSE-2.0&lt;br /&gt;
 *&lt;br /&gt;
 * Unless required by applicable law or agreed to in writing, software&lt;br /&gt;
 * distributed under the License is distributed on an &amp;quot;AS IS&amp;quot; BASIS,&lt;br /&gt;
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.&lt;br /&gt;
 * See the License for the specific language governing permissions and&lt;br /&gt;
 * limitations under the License.&lt;br /&gt;
 */&lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.FileOutputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.util.zip.ZipEntry;&lt;br /&gt;
import java.util.zip.ZipOutputStream;&lt;br /&gt;
/**&lt;br /&gt;
 * File utilities&lt;br /&gt;
 * &lt;br /&gt;
 * @version $Revision: 691982 $&lt;br /&gt;
 */&lt;br /&gt;
public final class FileUtil {&lt;br /&gt;
    /**&lt;br /&gt;
     * Zip up a directory&lt;br /&gt;
     * &lt;br /&gt;
     * @param directory&lt;br /&gt;
     * @param zipName&lt;br /&gt;
     * @throws IOException&lt;br /&gt;
     */&lt;br /&gt;
    public static void zipDir(String directory, String zipName) throws IOException {&lt;br /&gt;
        // create a ZipOutputStream to zip the data to&lt;br /&gt;
        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipName));&lt;br /&gt;
        String path = &amp;quot;&amp;quot;;&lt;br /&gt;
        zipDir(directory, zos, path);&lt;br /&gt;
        // close the stream&lt;br /&gt;
        zos.close();&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Zip up a directory path&lt;br /&gt;
     * @param directory&lt;br /&gt;
     * @param zos&lt;br /&gt;
     * @param path&lt;br /&gt;
     * @throws IOException&lt;br /&gt;
     */&lt;br /&gt;
    public static void zipDir(String directory, ZipOutputStream zos, String path) throws IOException {&lt;br /&gt;
        File zipDir = new File(directory);&lt;br /&gt;
        // get a listing of the directory content&lt;br /&gt;
        String[] dirList = zipDir.list();&lt;br /&gt;
        byte[] readBuffer = new byte[2156];&lt;br /&gt;
        int bytesIn = 0;&lt;br /&gt;
        // loop through dirList, and zip the files&lt;br /&gt;
        for (int i = 0; i &amp;lt; dirList.length; i++) {&lt;br /&gt;
            File f = new File(zipDir, dirList[i]);&lt;br /&gt;
            if (f.isDirectory()) {&lt;br /&gt;
                String filePath = f.getPath();&lt;br /&gt;
                zipDir(filePath, zos, path + f.getName() + &amp;quot;/&amp;quot;);&lt;br /&gt;
                continue;&lt;br /&gt;
            }&lt;br /&gt;
            FileInputStream fis = new FileInputStream(f);&lt;br /&gt;
            try {&lt;br /&gt;
                ZipEntry anEntry = new ZipEntry(path + f.getName());&lt;br /&gt;
                zos.putNextEntry(anEntry);&lt;br /&gt;
                bytesIn = fis.read(readBuffer);&lt;br /&gt;
                while (bytesIn != -1) {&lt;br /&gt;
                    zos.write(readBuffer, 0, bytesIn);&lt;br /&gt;
                    bytesIn = fis.read(readBuffer);&lt;br /&gt;
                }&lt;br /&gt;
            } finally {&lt;br /&gt;
                fis.close();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>