Example usage for java.util.jar JarInputStream available

List of usage examples for java.util.jar JarInputStream available

Introduction

In this page you can find the example usage for java.util.jar JarInputStream available.

Prototype

public int available() throws IOException 

Source Link

Document

Returns 0 after EOF has reached for the current entry data, otherwise always return 1.

Usage

From source file:com.flexive.testRunner.FxTestRunnerThread.java

/**
 * {@inheritDoc}/*  w  ww  .  java 2  s  .com*/
 */
@Override
public void run() {
    synchronized (lock) {
        if (testInProgress)
            return;
        testInProgress = true;
    }
    try {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        URL jar = cl.getResource("lib/flexive-tests.jar");

        //build a list of all test classes
        List<Class> testClasses = new ArrayList<Class>(100);
        try {
            JarInputStream jin = new JarInputStream(jar.openStream());
            while (jin.available() != 0) {
                JarEntry je = jin.getNextJarEntry();
                if (je == null)
                    continue;

                final String name = je.getName();
                //only classes, no inner classes, abstract or mock classes
                if (name.endsWith(".class") && !(name.indexOf('$') > 0) && !(name.indexOf("Abstract") > 0)
                        && !(name.indexOf("Mock") > 0)) {
                    boolean ignore = false;
                    //check ignore package
                    for (String pkg : FxTestRunner.ignorePackages)
                        if (name.indexOf(pkg) > 0) {
                            ignore = true;
                            break;
                        }
                    if (ignore)
                        continue;
                    final String className = name.substring(name.lastIndexOf('/') + 1);
                    //check ignore classes
                    for (String cls : FxTestRunner.ignoreTests)
                        if (className.indexOf(cls) > 0) {
                            ignore = true;
                            break;
                        }
                    if (ignore)
                        continue;
                    final String fqn = name.replaceAll("\\/", ".").substring(0, name.lastIndexOf('.'));
                    try {
                        testClasses.add(Class.forName(fqn));
                    } catch (ClassNotFoundException e) {
                        LOG.error("Could not find test class: " + fqn);
                    }
                }
            }
        } catch (IOException e) {
            LOG.error(e);
        }
        TestNG testng = new TestNG();
        testng.setTestClasses(testClasses.toArray(new Class[testClasses.size()]));
        // skip.ear groups have to be excluded, else tests that include these will be skipped as well (like ContainerBootstrap which is needed)
        testng.setExcludedGroups("skip.ear");
        System.setProperty("flexive.tests.ear", "1");
        TestListenerAdapter tla = new TestListenerAdapter();
        testng.addListener(tla);

        if (callback != null) {
            FxTestRunnerListener trl = new FxTestRunnerListener(callback);
            testng.addListener(trl);
        }

        testng.setThreadCount(4);
        testng.setVerbose(0);
        testng.setDefaultSuiteName("EARTestSuite");
        testng.setOutputDirectory(outputPath);
        if (callback != null)
            callback.resetTestInfo();
        try {
            testng.run();
        } catch (Exception e) {
            LOG.error(e);
            new FxFacesMsgErr("TestRunner.err.testNG", e.getMessage()).addToContext();
        }
        if (callback != null) {
            callback.setRunning(false);
            callback.setResultsAvailable(true);
        }
    } finally {
        synchronized (lock) {
            testInProgress = false;
        }
    }
}

From source file:spring.osgi.io.OsgiBundleResourcePatternResolver.java

/**
 * Checks the jar entries from the Bundle-Classpath for the given pattern.
 *
 * @param list    paths// w  w  w  .j ava2 s .c  o  m
 * @param url     url
 * @param pattern pattern
 */
private void findBundleClassPathMatchingJarEntries(List<String> list, URL url, String pattern)
        throws IOException {
    // get the stream to the resource and read it as a jar
    JarInputStream jis = new JarInputStream(url.openStream());
    Set<String> result = new LinkedHashSet<>(8);

    boolean patternWithFolderSlash = pattern.startsWith(FOLDER_SEPARATOR);

    // parse the jar and do pattern matching
    try {
        while (jis.available() > 0) {
            JarEntry jarEntry = jis.getNextJarEntry();
            // if the jar has ended, the entry can be null (on Sun JDK at least)
            if (jarEntry != null) {
                String entryPath = jarEntry.getName();

                // check if leading "/" is needed or not (it depends how the jar was created)
                if (entryPath.startsWith(FOLDER_SEPARATOR)) {
                    if (!patternWithFolderSlash) {
                        entryPath = entryPath.substring(FOLDER_SEPARATOR.length());
                    }
                } else {
                    if (patternWithFolderSlash) {
                        entryPath = FOLDER_SEPARATOR.concat(entryPath);
                    }
                }
                if (getPathMatcher().match(pattern, entryPath)) {
                    result.add(entryPath);
                }
            }
        }
    } finally {
        try {
            jis.close();
        } catch (IOException io) {
            // ignore it - nothing we can't do about it
        }
    }

    if (logger.isTraceEnabled())
        logger.trace("Found in nested jar [" + url + "] matching entries " + result);

    list.addAll(result);
}

From source file:org.artifactory.repo.db.DbStoringRepoMixin.java

private void validateArtifactIfRequired(MutableVfsFile mutableFile, RepoPath repoPath)
        throws RepoRejectException {
    String pathId = repoPath.getId();
    InputStream jarStream = mutableFile.getStream();
    try {/*from ww w .  j av a2 s.  com*/
        log.info("Validating the content of '{}'.", pathId);
        JarInputStream jarInputStream = new JarInputStream(jarStream, true);
        JarEntry entry = jarInputStream.getNextJarEntry();

        if (entry == null) {
            if (jarInputStream.getManifest() != null) {
                log.trace("Found manifest validating the content of '{}'.", pathId);
                return;
            }
            throw new IllegalStateException("Could not find entries within the archive.");
        }
        do {
            log.trace("Found the entry '{}' validating the content of '{}'.", entry.getName(), pathId);
        } while ((jarInputStream.available() == 1) && (entry = jarInputStream.getNextJarEntry()) != null);

        log.info("Finished validating the content of '{}'.", pathId);
    } catch (Exception e) {
        String message = String.format("Failed to validate the content of '%s': %s", pathId, e.getMessage());
        if (log.isDebugEnabled()) {
            log.debug(message, e);
        } else {
            log.error(message);
        }
        throw new RepoRejectException(message, HttpStatus.SC_CONFLICT);
    } finally {
        IOUtils.closeQuietly(jarStream);
    }
}

From source file:org.eclipse.gemini.blueprint.io.OsgiBundleResourcePatternResolver.java

/**
 * Checks the jar entries from the Bundle-Classpath for the given pattern.
 * /* w  w  w  .j a v  a 2 s .c  o  m*/
 * @param list
 * @param ur
 */
private void findBundleClassPathMatchingJarEntries(List<String> list, URL url, String pattern)
        throws IOException {
    // get the stream to the resource and read it as a jar
    JarInputStream jis = new JarInputStream(url.openStream());
    Set<String> result = new LinkedHashSet<String>(8);

    boolean patternWithFolderSlash = pattern.startsWith(FOLDER_SEPARATOR);

    // parse the jar and do pattern matching
    try {
        while (jis.available() > 0) {
            JarEntry jarEntry = jis.getNextJarEntry();
            // if the jar has ended, the entry can be null (on Sun JDK at least)
            if (jarEntry != null) {
                String entryPath = jarEntry.getName();

                // check if leading "/" is needed or not (it depends how the jar was created)
                if (entryPath.startsWith(FOLDER_SEPARATOR)) {
                    if (!patternWithFolderSlash) {
                        entryPath = entryPath.substring(FOLDER_SEPARATOR.length());
                    }
                } else {
                    if (patternWithFolderSlash) {
                        entryPath = FOLDER_SEPARATOR.concat(entryPath);
                    }
                }
                if (getPathMatcher().match(pattern, entryPath)) {
                    result.add(entryPath);
                }
            }
        }
    } finally {
        try {
            jis.close();
        } catch (IOException io) {
            // ignore it - nothing we can't do about it
        }
    }

    if (logger.isTraceEnabled())
        logger.trace("Found in nested jar [" + url + "] matching entries " + result);

    list.addAll(result);
}

From source file:org.n52.ifgicopter.spf.common.PluginRegistry.java

/**
 * @param jar/*from   w  w w  .  j  a  v a  2 s.  co  m*/
 *        the jar
 * @return list of fqcn
 */
private List<String> listClasses(File jar) throws IOException {
    ArrayList<String> result = new ArrayList<String>();

    JarInputStream jis = new JarInputStream(new FileInputStream(jar));
    JarEntry je;

    while (jis.available() > 0) {
        je = jis.getNextJarEntry();

        if (je != null) {
            if (je.getName().endsWith(".class")) {
                result.add(je.getName().replaceAll("/", "\\.").substring(0, je.getName().indexOf(".class")));
            }
        }
    }

    return result;
}