本文整理汇总了Java中java.util.jar.JarEntry.isDirectory方法的典型用法代码示例。如果您正苦于以下问题:Java JarEntry.isDirectory方法的具体用法?Java JarEntry.isDirectory怎么用?Java JarEntry.isDirectory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.jar.JarEntry
的用法示例。
在下文中一共展示了JarEntry.isDirectory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unzip
import java.util.jar.JarEntry; //导入方法依赖的package包/类
private void unzip(File what, File where) throws IOException {
JarFile jf = new JarFile(what);
Enumeration<JarEntry> en = jf.entries();
while (en.hasMoreElements()) {
JarEntry current = en.nextElement();
if (current.isDirectory()) continue;
File target = new File(where, current.getName());
target.getParentFile().mkdirs();
assertTrue(target.getParentFile().isDirectory());
InputStream in = jf.getInputStream(current);
OutputStream out = new BufferedOutputStream(new FileOutputStream(target));
FileUtil.copy(in, out);
in.close();
out.close();
}
}
示例2: findJarNativeEntry
import java.util.jar.JarEntry; //导入方法依赖的package包/类
/**
* Finds native library entry.
*
* @param sLib Library name. For example for the library name "Native"
* - Windows returns entry "Native.dll"
* - Linux returns entry "libNative.so"
* - Mac returns entry "libNative.jnilib" or "libNative.dylib"
* (depending on Apple or Oracle JDK and/or JDK version)
* @return Native library entry.
*/
private JarEntryInfo findJarNativeEntry(String sLib) {
String sName = System.mapLibraryName(sLib);
for (JarFileInfo jarFileInfo : lstJarFile) {
JarFile jarFile = jarFileInfo.jarFile;
Enumeration<JarEntry> en = jarFile.entries();
while (en.hasMoreElements()) {
JarEntry je = en.nextElement();
if (je.isDirectory()) {
continue;
}
// Example: sName is "Native.dll"
String sEntry = je.getName(); // "Native.dll" or "abc/xyz/Native.dll"
// sName "Native.dll" could be found, for example
// - in the path: abc/Native.dll/xyz/my.dll <-- do not load this one!
// - in the partial name: abc/aNative.dll <-- do not load this one!
String[] token = sEntry.split("/"); // the last token is library name
if (token.length > 0 && token[token.length - 1].equals(sName)) {
logInfo(LogArea.NATIVE, "Loading native library '%s' found as '%s' in JAR %s",
sLib, sEntry, jarFileInfo.simpleName);
return new JarEntryInfo(jarFileInfo, je);
}
}
}
return null;
}
示例3: findClassByJar
import java.util.jar.JarEntry; //导入方法依赖的package包/类
/**
* 搜索jar里面的class
* 注意jar的open和close
* 返回类名和类的map集合
* @throws IOException
* */
public static final Map<String,JarEntry> findClassByJar(JarFile jarFile) throws IOException {
Map<String,JarEntry> map=new HashMap<String,JarEntry>();
if(jarFile==null)
{
throw new RuntimeException("jarFile is Null");
}
String Suffix=".class";
Enumeration<JarEntry> jarEntries = jarFile.entries();
while (jarEntries.hasMoreElements())
{//遍历jar的实体对象
JarEntry jarEntry = jarEntries.nextElement();
if(jarEntry.isDirectory() || !jarEntry.getName().endsWith(Suffix))
{
continue;
}
String jarEntryName = jarEntry.getName(); // 类似:sun/security/internal/interfaces/TlsMasterSecret.class
String className = jarEntryName.substring(0, jarEntryName.length() - Suffix.length());//sun/security/internal/interfaces/TlsMasterSecret
//注意,jar文件里面的只能是/不能是\
className = className.replace("/", ".");//sun.security.internal.interfaces.TlsMasterSecret
map.put(className,jarEntry);
}
return map;
}
示例4: copyAssets
import java.util.jar.JarEntry; //导入方法依赖的package包/类
private static void copyAssets(final String appJarPath, final String assetsDir, final String toDirectory) throws IOException {
final JarFile jarFile = new JarFile(appJarPath);
final int prefixLength = assetsDir.length();
final Enumeration<JarEntry> filesEnumeration = jarFile.entries();
while (filesEnumeration.hasMoreElements()) {
final JarEntry fileJarEntry = filesEnumeration.nextElement();
final String name = fileJarEntry.getName();
if (!fileJarEntry.isDirectory() && name.startsWith(assetsDir)) {
final String destinationFileAbsolutePath = Paths.get(toDirectory, name.substring(prefixLength));
copyFile(jarFile.getInputStream(fileJarEntry), destinationFileAbsolutePath);
}
}
}
示例5: reloadJar
import java.util.jar.JarEntry; //导入方法依赖的package包/类
public void reloadJar(String fileName) throws IOException {
JarFile jarFile = new JarFile(path + File.separator + fileName);
Enumeration<JarEntry> entries = jarFile.entries();
InputStream input = null;
BufferedInputStream fileInputStream = null;
while (entries.hasMoreElements()) {
try {
JarEntry jarEntry = (JarEntry) entries.nextElement();
if (jarEntry.isDirectory()) {
continue;
}
if (jarEntry.getName().endsWith("package-info.class")) {
continue;
}
if (!jarEntry.getName().endsWith(".class")) {
continue;
}
input = jarFile.getInputStream(jarEntry);
long size = jarEntry.getSize();
byte[] bs = new byte[(int) size];
fileInputStream = new BufferedInputStream(input);
fileInputStream.read(bs);
String clazzName = jarEntry.getName().replaceAll("/", ".");
// System.out.println(clazzName + " " + bs.length);
hotSwapper.reload(clazzName, bs);
} catch (Exception e) {
logger.error("reloadJar error", e);
} finally {
input.close();
fileInputStream.close();
}
}
}
示例6: getEntriesWithoutInnerClasses
import java.util.jar.JarEntry; //导入方法依赖的package包/类
public List<String> getEntriesWithoutInnerClasses() {
List<String> mass = new ArrayList<>();
Enumeration<JarEntry> entries = jfile.entries();
Set<String> possibleInnerClasses = new HashSet<String>();
Set<String> baseClasses = new HashSet<String>();
while (entries.hasMoreElements()) {
JarEntry e = entries.nextElement();
if (!e.isDirectory()) {
String entryName = e.getName();
if (entryName != null && entryName.trim().length() > 0) {
entryName = entryName.trim();
if (!entryName.endsWith(".class")) {
mass.add(entryName);
// com/acme/Model$16.class
} else if (entryName.matches(".*[^(/|\\\\)]+\\$[^(/|\\\\)]+$")) {
possibleInnerClasses.add(entryName);
} else {
baseClasses.add(entryName);
mass.add(entryName);
}
}
}
}
// keep Badly$Named but not inner classes
for (String inner : possibleInnerClasses) {
// com/acme/Connection$Conn$1.class -> com/acme/Connection
String innerWithoutTail = inner.replaceAll("\\$[^(/|\\\\)]+\\.class$", "");
if (!baseClasses.contains(innerWithoutTail + ".class")) {
mass.add(inner);
}
}
return mass;
}
示例7: implFind
import java.util.jar.JarEntry; //导入方法依赖的package包/类
@Override
Optional<URI> implFind(String name) throws IOException {
JarEntry je = getEntry(name);
if (je != null) {
if (jf.isMultiRelease())
name = SharedSecrets.javaUtilJarAccess().getRealName(jf, je);
if (je.isDirectory() && !name.endsWith("/"))
name += "/";
String encodedPath = ParseUtil.encodePath(name, false);
String uris = "jar:" + uri + "!/" + encodedPath;
return Optional.of(URI.create(uris));
} else {
return Optional.empty();
}
}
示例8: testInappropraiteEntries
import java.util.jar.JarEntry; //导入方法依赖的package包/类
/** Scan for accidentally commited files that get into product
*/
public void testInappropraiteEntries() throws Exception {
SortedSet<Violation> violations = new TreeSet<Violation>();
for (File f: org.netbeans.core.startup.Main.getModuleSystem().getModuleJars()) {
// check JAR files only
if (!f.getName().endsWith(".jar"))
continue;
if (!f.getName().endsWith("cssparser-0-9-4-fs.jar")) // #108644
continue;
JarFile jar = new JarFile(f);
Enumeration<JarEntry> entries = jar.entries();
JarEntry entry;
BufferedImage img;
while (entries.hasMoreElements()) {
entry = entries.nextElement();
if (entry.isDirectory())
continue;
if (entry.getName().endsWith("Thumbs.db")) {
violations.add(new Violation(entry.getName(), jar.getName(), " should not be in module JAR"));
}
if (entry.getName().contains("nbproject/private")) {
violations.add(new Violation(entry.getName(), jar.getName(), " should not be in module JAR"));
}
}
}
if (!violations.isEmpty()) {
StringBuilder msg = new StringBuilder();
msg.append("Some files does not belong to module JARs ("+violations.size()+"):\n");
for (Violation viol: violations) {
msg.append(viol).append('\n');
}
fail(msg.toString());
}
}
示例9: extractJar
import java.util.jar.JarEntry; //导入方法依赖的package包/类
public static void extractJar(JarFile jf, File where) throws Exception {
for (JarEntry file : Collections.list(jf.entries())) {
File out = new File(where, file.getName());
if (file.isDirectory()) {
out.mkdirs();
continue;
}
File parent = out.getParentFile();
if (parent != null && !parent.exists()) {
parent.mkdirs();
}
InputStream is = null;
OutputStream os = null;
try {
is = jf.getInputStream(file);
os = new FileOutputStream(out);
while (is.available() > 0) {
os.write(is.read());
}
} finally {
if (is != null) {
is.close();
}
if (os != null) {
os.close();
}
}
}
}
示例10: getClassNames
import java.util.jar.JarEntry; //导入方法依赖的package包/类
@Override
public List<String> getClassNames() throws IOException {
Enumeration<JarEntry> e = jarFile.entries();
List<String> classNames = new ArrayList<>(jarFile.size());
while (e.hasMoreElements()) {
JarEntry je = e.nextElement();
if (je.isDirectory() || !je.getName().endsWith(".class")) {
continue;
}
String className = je.getName().substring(0, je.getName().length() - ".class".length());
classNames.add(className.replace('/', '.'));
}
return classNames;
}
示例11: unJar
import java.util.jar.JarEntry; //导入方法依赖的package包/类
/**
* Unpack matching files from a jar. Entries inside the jar that do
* not match the given pattern will be skipped.
*
* @param jarFile the .jar file to unpack
* @param toDir the destination directory into which to unpack the jar
* @param unpackRegex the pattern to match jar entries against
*/
public static void unJar(File jarFile, File toDir, Pattern unpackRegex)
throws IOException {
JarFile jar = new JarFile(jarFile);
try {
Enumeration<JarEntry> entries = jar.entries();
while (entries.hasMoreElements()) {
final JarEntry entry = entries.nextElement();
if (!entry.isDirectory() &&
unpackRegex.matcher(entry.getName()).matches()) {
InputStream in = jar.getInputStream(entry);
try {
File file = new File(toDir, entry.getName());
ensureDirectory(file.getParentFile());
OutputStream out = new FileOutputStream(file);
try {
IOUtils.copyBytes(in, out, 8192);
} finally {
out.close();
}
} finally {
in.close();
}
}
}
} finally {
jar.close();
}
}
示例12: getEntriesWithoutInnerClasses
import java.util.jar.JarEntry; //导入方法依赖的package包/类
public List<String> getEntriesWithoutInnerClasses() {
List<String> mass = new ArrayList<>();
Enumeration<JarEntry> entries = jfile.entries();
Set<String> possibleInnerClasses = new HashSet<String>();
Set<String> baseClasses = new HashSet<String>();
while (entries.hasMoreElements()) {
JarEntry e = entries.nextElement();
if (!e.isDirectory()) {
String entryName = e.getName();
if (entryName != null && entryName.trim().length() > 0) {
entryName = entryName.trim();
if (!entryName.endsWith(".class")) {
mass.add(entryName);
// com/acme/Model$16.class
} else if (entryName.matches(".*[^(/|\\\\)]+\\$[^(/|\\\\)]+$")) {
possibleInnerClasses.add(entryName);
} else {
baseClasses.add(entryName);
mass.add(entryName);
}
}
}
}
// keep Badly$Named but not inner classes
for (String inner : possibleInnerClasses) {
// com/acme/Connection$Conn$1.class -> com/acme/Connection
String innerWithoutTail = inner.replaceAll("\\$[^(/|\\\\)]+\\.class$", "");
if (!baseClasses.contains(innerWithoutTail + ".class")) {
mass.add(inner);
}
}
return mass;
}
示例13: getAllEntriesFromJar
import java.util.jar.JarEntry; //导入方法依赖的package包/类
public List<String> getAllEntriesFromJar() {
List<String> mass = new ArrayList<>();
Enumeration<JarEntry> entries = jfile.entries();
while (entries.hasMoreElements()) {
JarEntry e = entries.nextElement();
if (!e.isDirectory()) {
mass.add(e.getName());
}
}
return mass;
}
示例14: loadJar
import java.util.jar.JarEntry; //导入方法依赖的package包/类
/**
* Loads specified JAR.
*
* @param jarFileInfo
* @throws IOException
*/
private void loadJar(JarFileInfo jarFileInfo) throws IOException {
lstJarFile.add(jarFileInfo);
try {
Enumeration<JarEntry> en = jarFileInfo.jarFile.entries();
final String EXT_JAR = ".jar";
while (en.hasMoreElements()) {
JarEntry je = en.nextElement();
if (je.isDirectory()) {
continue;
}
String s = je.getName().toLowerCase(); // JarEntry name
if (s.lastIndexOf(EXT_JAR) == s.length() - EXT_JAR.length()) {
JarEntryInfo inf = new JarEntryInfo(jarFileInfo, je);
File fileTemp = createTempFile(inf);
logInfo(LogArea.JAR, "Loading inner JAR %s from temp file %s",
inf.jarEntry, getFilename4Log(fileTemp));
// Construct ProtectionDomain for this inner JAR:
URL url = fileTemp.toURI().toURL();
ProtectionDomain pdParent = jarFileInfo.pd;
// 'csParent' is never null: top JAR has it, JCL creates it for child JAR:
CodeSource csParent = pdParent.getCodeSource();
Certificate[] certParent = csParent.getCertificates();
CodeSource csChild = (certParent == null ? new CodeSource(url, csParent.getCodeSigners())
: new CodeSource(url, certParent));
ProtectionDomain pdChild = new ProtectionDomain(csChild,
pdParent.getPermissions(), pdParent.getClassLoader(), pdParent.getPrincipals());
loadJar(new JarFileInfo(
new JarFile(fileTemp), inf.getName(), jarFileInfo, pdChild, fileTemp));
}
}
} catch (JarClassLoaderException e) {
throw new RuntimeException(
"ERROR on loading inner JAR: " + e.getMessageAll());
}
}
示例15: filterEntriesByPackage
import java.util.jar.JarEntry; //导入方法依赖的package包/类
private static Stream<String> filterEntriesByPackage( JarFile jarFile, String packageName ) {
logger.debug( "Searching jar {} for package {}", jarFile.getName(), packageName );
Enumeration<JarEntry> entries = jarFile.entries();
List<String> result = new ArrayList<>( 4 );
while ( entries.hasMoreElements() ) {
JarEntry entry = entries.nextElement();
if ( entry.isDirectory() ) {
continue;
}
String entryName = entry.getName();
if ( entryName.endsWith( ".class" ) ) {
int lastPartIndex = entryName.lastIndexOf( '/' );
String entryPackage = lastPartIndex > 0 ?
entryName.substring( 0, lastPartIndex ).replace( "/", "." ) :
"";
if ( entryPackage.equals( packageName ) ) {
result.add( entryName );
}
}
}
return result.stream();
}