Example usage for java.util.zip ZipError toString

List of usage examples for java.util.zip ZipError toString

Introduction

In this page you can find the example usage for java.util.zip ZipError toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.facebook.buck.util.unarchive.Unzip.java

/**
 * Gets a set of files that are contained in an archive
 *
 * @param archiveAbsolutePath The absolute path to the archive
 * @return A set of files (not directories) that are contained in the zip file
 * @throws IOException If there is an error reading the archive
 *///from w ww  .j a v  a2s .c o m
public static ImmutableSet<Path> getZipMembers(Path archiveAbsolutePath) throws IOException {
    try (FileSystem zipFs = FileSystems.newFileSystem(archiveAbsolutePath, null)) {
        Path root = Iterables.getOnlyElement(zipFs.getRootDirectories());
        return Files.walk(root).filter(path -> !Files.isDirectory(path)).map(root::relativize)
                .map(path -> Paths.get(path.toString())) // Clear the filesystem from the path
                .collect(ImmutableSet.toImmutableSet());
    } catch (ZipError error) {
        // For some reason the zip filesystem support throws an error when an IOException would do
        // just as well.
        throw new IOException(
                String.format("Could not read %s because of %s", archiveAbsolutePath, error.toString()), error);
    }
}