Example usage for java.util.jar JarEntry getName

List of usage examples for java.util.jar JarEntry getName

Introduction

In this page you can find the example usage for java.util.jar JarEntry getName.

Prototype

public String getName() 

Source Link

Document

Returns the name of the entry.

Usage

From source file:org.ebayopensource.turmeric.eclipse.typelibrary.ui.TypeLibraryUtil.java

/**
 * Gets the project name from wtp base location.
 *
 * @param baseLocationStr the base location str
 * @return the project name from wtp base location
 * @throws ParserConfigurationException the parser configuration exception
 * @throws SAXException the sAX exception
 * @throws IOException Signals that an I/O exception has occurred.
 *///ww w  . j  ava2 s  .  c  o m
public static String getProjectNameFromWTPBaseLocation(String baseLocationStr)
        throws ParserConfigurationException, SAXException, IOException {
    IPath path = new Path(baseLocationStr);
    // this is a jar location if base location starts with jar for eg:
    // "jar:file:/D:/Views/soapost22/v3jars/services/MarketPlaceServiceCommonTypeLibrary/3.0.0/java50/MarketPlaceServiceCommonTypeLibrary.jar!/types/BaseServiceResponse.xsd"
    if (baseLocationStr.toLowerCase().startsWith("jar:file:/")) {
        JarFile jarFile = new JarFile(getJarFile(baseLocationStr.substring(10, baseLocationStr.length())));
        Enumeration<JarEntry> entries = jarFile.entries();
        while (entries.hasMoreElements()) {
            JarEntry entry = entries.nextElement();
            if (entry.getName().startsWith(SOATypeLibraryConstants.INFO_DEP_XML_PATH_IN_JAR)
                    && entry.getName().endsWith(SOATypeLibraryConstants.FILE_TYPE_INFO_XML)) {
                return getTypeLibName(entry, jarFile);
            }
        }
    } else {
        // New style has the type library name also. So removing an
        // additional segment at the end.
        if (isNewStyleBaseLocation(baseLocationStr)) {
            path = path.removeLastSegments(4);
        } else {
            // removing meta-src/types/abcd.xsd
            path = path.removeLastSegments(3);
        }
    }
    return path.lastSegment();
}

From source file:gemlite.core.internal.support.hotdeploy.scanner.ScannerIteratorItem.java

private byte[] readContent(ClassLoader loader, JarEntry entry) throws IOException {
    URL url = loader.getResource(entry.getName());
    URLConnection ulc = url.openConnection();
    InputStream in3 = ulc.getInputStream();
    InputStream in2 = url.openStream();

    InputStream in = loader.getResourceAsStream(entry.getName());
    if (in == null) {
        LogUtil.getCoreLog().trace("ReadContent inputStream is null entry.name={} , loader={}", entry.getName(),
                loader);//from   w  w w .  j  av a  2 s  .co  m
    }

    BufferedInputStream bi = new BufferedInputStream(in);
    byte[] bt = new byte[in.available()];
    bi.read(bt);
    bi.close();
    in.close();
    return bt;
}

From source file:org.artifactory.maven.MavenModelUtils.java

/**
 * Gathers maven artifact information which was (or was not) managed to gather from the given Jar file
 *
 * @param file Jar file to gather info from
 *///from ww w . ja v a 2s .  c  om

private static MavenArtifactInfo gatherInfoFromJarFile(File file) {
    MavenArtifactInfo artifactInfo = null;
    JarInputStream jis = null;
    JarEntry entry;
    try {
        //Create a stream and try to find the pom file within the jar
        jis = new JarInputStream(new FileInputStream(file));
        entry = getPomFile(jis);

        //If a valid pom file was found
        if (entry != null) {
            try {
                //Read the uncompressed content
                artifactInfo = mavenModelToArtifactInfo(jis);
                artifactInfo.setType(PathUtils.getExtension(file.getPath()));
            } catch (Exception e) {
                log.warn("Failed to read maven model from '" + entry.getName() + "'. Cause: " + e.getMessage()
                        + ".", e);
                artifactInfo = null;
            }
        }
    } catch (IOException e) {
        log.warn("Failed to read maven model from '" + file + "'. Cause: " + e.getMessage() + ".", e);
    } finally {
        IOUtils.closeQuietly(jis);
    }
    return artifactInfo;
}

From source file:org.apache.bcel.BCELBenchmark.java

private Iterable<JarEntry> getClasses(JarFile jar) {
    return new IteratorIterable<>(
            new FilterIterator<>(new EnumerationIterator<>(jar.entries()), new Predicate<JarEntry>() {
                @Override//  w  w  w .  j  a va 2s  .c o m
                public boolean evaluate(JarEntry entry) {
                    return entry.getName().endsWith(".class");
                }
            }));
}

From source file:com.fengduo.bee.commons.core.utilities.ClassPathScanner.java

void findInJar(List<Class<?>> results, File file, String packageName) {
    JarFile jarFile = null;//from  ww w . java 2 s  .c om
    String packagePath = dotToPath(packageName) + "/";
    try {
        jarFile = new JarFile(file);
        Enumeration<JarEntry> en = jarFile.entries();
        while (en.hasMoreElements()) {
            JarEntry je = en.nextElement();
            String name = je.getName();
            if (name.startsWith(packagePath) && name.endsWith(CLASS_FILE)) {
                String className = name.substring(0, name.length() - CLASS_FILE.length());
                add(results, pathToDot(className));
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (jarFile != null) {
            try {
                jarFile.close();
            } catch (IOException e) {
            }
        }
    }
}

From source file:org.eclipse.licensing.eclipse_licensing_plugin.InjectLicensingMojo.java

private void extractLicensingBaseFiles() throws IOException {
    JarFile jar = new JarFile(getLicensingBasePlugin());
    Enumeration<JarEntry> entries = jar.entries();
    while (entries.hasMoreElements()) {
        JarEntry entry = entries.nextElement();
        String entryName = entry.getName();
        if (entryName.startsWith("org")) {
            File file = new File(classesDirectory, entryName);
            if (entry.isDirectory()) {
                file.mkdir();/* w w  w .  ja v  a 2s . c o m*/
            } else {
                InputStream is = jar.getInputStream(entry);
                FileOutputStream fos = new FileOutputStream(file);
                while (is.available() > 0) {
                    fos.write(is.read());
                }
                fos.close();
                is.close();
            }
        }
    }
    jar.close();
}

From source file:org.commonjava.indy.ftest.core.content.StoreAndVerifyJarViaDirectDownloadTest.java

@Test
public void storeFileThenDownloadAndVerifyContentViaDirectDownload() throws Exception {
    final String content = "This is a test: " + System.nanoTime();
    String entryName = "org/something/foo.class";

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    JarOutputStream jarOut = new JarOutputStream(out);
    jarOut.putNextEntry(new JarEntry(entryName));
    jarOut.write(content.getBytes());/*from  w  w  w.  ja v a  2 s. c o m*/
    jarOut.close();

    // Used to visually inspect the jars moving up...
    //        String userDir = System.getProperty( "user.home" );
    //        File dir = new File( userDir, "temp" );
    //        dir.mkdirs();
    //
    //        FileUtils.writeByteArrayToFile( new File( dir, name.getMethodName() + "-in.jar" ), out.toByteArray() );

    final InputStream stream = new ByteArrayInputStream(out.toByteArray());

    final String path = "/path/to/" + getClass().getSimpleName() + "-" + name.getMethodName() + ".jar";

    assertThat(client.content().exists(hosted, STORE, path), equalTo(false));

    client.content().store(hosted, STORE, path, stream);

    assertThat(client.content().exists(hosted, STORE, path), equalTo(true));

    final URL url = new URL(client.content().contentUrl(hosted, STORE, path));

    final InputStream is = url.openStream();

    byte[] result = IOUtils.toByteArray(is);
    is.close();

    assertThat(result, equalTo(out.toByteArray()));

    // ...and down
    //        FileUtils.writeByteArrayToFile( new File( dir, name.getMethodName() + "-out.jar" ), result );

    JarInputStream jarIn = new JarInputStream(new ByteArrayInputStream(result));
    JarEntry jarEntry = jarIn.getNextJarEntry();

    assertThat(jarEntry.getName(), equalTo(entryName));
    String contentResult = IOUtils.toString(jarIn);

    assertThat(contentResult, equalTo(content));
}

From source file:com.jayway.maven.plugins.android.standalonemojos.UnpackMojo.java

boolean isIncluded(JarEntry jarEntry) {
    String entName = jarEntry.getName();

    if (entName.endsWith(".class")) {
        return true;
    }//from w  w w .  jav a  2s.c  om

    return this.unpackMetaInf != null && this.unpackMetaInf.isIncluded(entName);
}

From source file:i18nplugin.TranslationNode.java

/**
 * Add a Property-File// ww  w.ja  va  2s  .  com
 * @param jarfile Main-Jar
 * @param entry Property-File
 */
private void addEntry(JarFile jarfile, JarEntry entry) {
    String name = entry.getName();
    DefaultMutableTreeNode path = getPath(name.substring(0, name.lastIndexOf('/')));
    path.add(new PropertiesNode(jarfile, entry));
}

From source file:org.junit.extensions.dynamicsuite.engine.ClassPathScanner.java

private void loadJarEntries(JarFile jar) {
    Enumeration<JarEntry> entries = jar.entries();
    while (entries.hasMoreElements()) {

        JarEntry element = entries.nextElement();
        String name = element.getName();
        if (name.toLowerCase().endsWith(".class")) {
            String className = StringUtils.replace(name, "/", ".");
            className = StringUtils.removeEnd(className, ".class");
            foundClasses.add(className);
        }//from w  w w.  j  a  v  a2  s. c  o  m
    }
}