Example usage for org.apache.commons.compress.archivers ArchiveEntry getClass

List of usage examples for org.apache.commons.compress.archivers ArchiveEntry getClass

Introduction

In this page you can find the example usage for org.apache.commons.compress.archivers ArchiveEntry getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.apache.ant.compress.util.EntryHelper.java

/**
 * Extracts the permission bits from an entry.
 *//*from   ww w  .j  a va  2  s . c  om*/
public static int getMode(ArchiveEntry entry) {
    if (entry == null) {
        throw new IllegalArgumentException("entry must not be null.");
    }

    if (entry instanceof ArArchiveEntry) {
        return ((ArArchiveEntry) entry).getMode();
    }
    if (entry instanceof ArjArchiveEntry) {
        return ((ArjArchiveEntry) entry).getUnixMode();
    }
    if (entry instanceof CpioArchiveEntry) {
        return (int) ((CpioArchiveEntry) entry).getMode();
    }
    if (entry instanceof SevenZArchiveEntry) {
        return UNKNOWN_ID;
    }
    if (entry instanceof TarArchiveEntry) {
        return ((TarArchiveEntry) entry).getMode();
    }
    if (entry instanceof ZipArchiveEntry) {
        return ((ZipArchiveEntry) entry).getUnixMode();
    }
    if (entry instanceof DumpArchiveEntry) {
        return ((DumpArchiveEntry) entry).getMode();
    }
    throw new BuildException("archive entry " + entry.getClass() + " is not supported.");
}

From source file:org.apache.ant.compress.util.EntryHelper.java

/**
 * Extracts the user id an entry.// www  .j  a va 2  s.co  m
 */
public static int getUserId(ArchiveEntry entry) {
    if (entry == null) {
        throw new IllegalArgumentException("entry must not be null.");
    }

    if (entry instanceof ArArchiveEntry) {
        return ((ArArchiveEntry) entry).getUserId();
    }
    if (entry instanceof ArjArchiveEntry) {
        return UNKNOWN_ID;
    }
    if (entry instanceof CpioArchiveEntry) {
        return (int) ((CpioArchiveEntry) entry).getUID();
    }
    if (entry instanceof SevenZArchiveEntry) {
        return UNKNOWN_ID;
    }
    if (entry instanceof TarArchiveEntry) {
        return ((TarArchiveEntry) entry).getUserId();
    }
    if (entry instanceof ZipArchiveEntry) {
        return UNKNOWN_ID;
    }
    if (entry instanceof DumpArchiveEntry) {
        return ((DumpArchiveEntry) entry).getUserId();
    }
    throw new BuildException("archive entry " + entry.getClass() + " is not supported.");
}

From source file:org.apache.ant.compress.util.EntryHelper.java

/**
 * Extracts the group id an entry.//from   w w  w .  java2s .co  m
 */
public static int getGroupId(ArchiveEntry entry) {
    if (entry == null) {
        throw new IllegalArgumentException("entry must not be null.");
    }

    if (entry instanceof ArArchiveEntry) {
        return ((ArArchiveEntry) entry).getGroupId();
    }
    if (entry instanceof ArjArchiveEntry) {
        return UNKNOWN_ID;
    }
    if (entry instanceof CpioArchiveEntry) {
        return (int) ((CpioArchiveEntry) entry).getGID();
    }
    if (entry instanceof SevenZArchiveEntry) {
        return UNKNOWN_ID;
    }
    if (entry instanceof TarArchiveEntry) {
        return ((TarArchiveEntry) entry).getGroupId();
    }
    if (entry instanceof ZipArchiveEntry) {
        return UNKNOWN_ID;
    }
    if (entry instanceof DumpArchiveEntry) {
        return (int) ((DumpArchiveEntry) entry).getGroupId();
    }
    throw new BuildException("archive entry " + entry.getClass() + " is not supported.");
}

From source file:tikatest.Investigation.java

/**
 * Takes a file which has already been detected as a supported archive and
 * displays the contents.//from  w w  w.j  a v a2 s .  c om
 * <p>This method makes use of code which has been publicly available through
 * the Apache website.
 * @param The file to be inspected
 * @see java.io.BufferedInputStream
 */
private void handleGeneric(BufferedInputStream bis) {
    try {
        // File type is a known archive type and we can work with it (fingers crossed)
        ArchiveInputStream aisInput = new ArchiveStreamFactory().createArchiveInputStream(bis);
        ArchiveEntry aeFile = aisInput.getNextEntry();
        System.out.println("ArchiveInputStream: " + aisInput.getClass().getName());
        System.out.println("Archive Entry - Type: " + aeFile.getClass().getName());
        while (aeFile != null) {
            if (!aeFile.isDirectory()) {
                String[] segments = aeFile.getName().split("\\/");
                String filename = "";
                for (String segment : segments) {
                    filename = segment;
                }
                System.out.println("Archive Entry - Name: " + filename);
            }
            aeFile = aisInput.getNextEntry();
        }
    } catch (ArchiveException aX) {
        aX.printStackTrace();
    } catch (IOException ioX) {
        ioX.printStackTrace();
    }
}