All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.com.objectos.way.base.zip.WayZips Maven / Gradle / Ivy

/*
 * Copyright 2014 Objectos, Fábrica de Software LTDA.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package br.com.objectos.way.base.zip;

import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.transform;

import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;

/**
 * @author [email protected] (Marcio Endo)
 */
public class WayZips {

  private WayZips() {
  }

  public static WayZip unzip(File file) throws WayZipException {
    try {
      ZipFile zip;
      zip = new ZipFile(file);

      List stages;
      stages = newArrayList();

      for (Enumeration e = zip.entries(); e.hasMoreElements();) {
        ZipEntry entry = e.nextElement();
        stages.add(new WayZipStage(zip, entry));
      }

      List entries;
      entries = transform(stages, WayZipStage.TO_ENTRY);

      return new WayZip(entries);

    } catch (ZipException e1) {
      throw new WayZipException(e1);

    } catch (IOException e1) {
      throw new WayZipException(e1);

    }

  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy