本文整理汇总了Java中org.apache.commons.compress.archivers.jar.JarArchiveEntry类的典型用法代码示例。如果您正苦于以下问题:Java JarArchiveEntry类的具体用法?Java JarArchiveEntry怎么用?Java JarArchiveEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JarArchiveEntry类属于org.apache.commons.compress.archivers.jar包,在下文中一共展示了JarArchiveEntry类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getAllClassesInJar
import org.apache.commons.compress.archivers.jar.JarArchiveEntry; //导入依赖的package包/类
/**
* Obtain a list of all classes in a jar file corresponding to a referenced
* class.
*
* @param classInJarFile
* @return list of all the commons-math3 classes in the referenced
* commons-math3 jar file
* @throws IOException
* if an IOException occurs
* @throws ClassNotFoundException
* if a ClassNotFoundException occurs
*/
private static List<String> getAllClassesInJar(Class<?> classInJarFile) throws IOException, ClassNotFoundException {
List<String> classPathNames = new ArrayList<>();
String jarLocation = classInJarFile.getProtectionDomain().getCodeSource().getLocation().getPath();
File f = new File(jarLocation);
try (FileInputStream fis = new FileInputStream(f);
JarArchiveInputStream jais = new JarArchiveInputStream(fis)) {
while (true) {
JarArchiveEntry jae = jais.getNextJarEntry();
if (jae == null) {
break;
}
String name = jae.getName();
if (name.endsWith(".class")) {
classPathNames.add(name);
}
}
}
String jarName = jarLocation.substring(jarLocation.lastIndexOf("/") + 1);
addClassPathNamesToJarsAndClasses(jarName, classPathNames);
return classPathNames;
}
开发者ID:apache,项目名称:systemml,代码行数:36,代码来源:BuildLite.java
示例2: copyFiles
import org.apache.commons.compress.archivers.jar.JarArchiveEntry; //导入依赖的package包/类
/** Copy all the files in a manifest from input to output. */
private static void copyFiles(Manifest manifest, JarFile in, JarArchiveOutputStream out, long timestamp)
throws IOException {
final byte[] buffer = new byte[4096];
int num;
final Map<String, Attributes> entries = manifest.getEntries();
final List<String> names = new ArrayList<>(entries.keySet());
Collections.sort(names);
for (final String name : names) {
final JarEntry inEntry = in.getJarEntry(name);
if (inEntry.getMethod() == JarArchiveEntry.STORED) {
// Preserve the STORED method of the input entry.
out.putArchiveEntry(new JarArchiveEntry(inEntry));
} else {
// Create a new entry so that the compressed len is recomputed.
final JarArchiveEntry je = new JarArchiveEntry(name);
je.setTime(timestamp);
out.putArchiveEntry(je);
}
final InputStream data = in.getInputStream(inEntry);
while ((num = data.read(buffer)) > 0) {
out.write(buffer, 0, num);
}
out.flush();
out.closeArchiveEntry();
}
}
开发者ID:jrummyapps,项目名称:BusyBox,代码行数:30,代码来源:ZipSigner.java
示例3: createJar
import org.apache.commons.compress.archivers.jar.JarArchiveEntry; //导入依赖的package包/类
/**
* Recursively create JAR archive from directory
*/
public static void createJar(File path, String root, OutputStream os) throws IOException {
log.debug("createJar({}, {}, {})", new Object[]{path, root, os});
if (path.exists() && path.canRead()) {
JarArchiveOutputStream jaos = new JarArchiveOutputStream(os);
jaos.setComment("Generated by OpenKM");
jaos.setCreateUnicodeExtraFields(UnicodeExtraFieldPolicy.ALWAYS);
jaos.setUseLanguageEncodingFlag(true);
jaos.setFallbackToUTF8(true);
jaos.setEncoding("UTF-8");
// Prevents java.util.jar.JarException: JAR file must have at least one entry
JarArchiveEntry jae = new JarArchiveEntry(root + "/");
jaos.putArchiveEntry(jae);
jaos.closeArchiveEntry();
createJarHelper(path, jaos, root);
jaos.flush();
jaos.finish();
jaos.close();
} else {
throw new IOException("Can't access " + path);
}
log.debug("createJar: void");
}
开发者ID:openkm,项目名称:document-management-system,代码行数:31,代码来源:ArchiveUtils.java
示例4: createEntry
import org.apache.commons.compress.archivers.jar.JarArchiveEntry; //导入依赖的package包/类
ArchiveEntry createEntry(long size) throws IOException {
// TODO: How to set entry name and indexes.
String name = String.format(entryNamePrefix, baseNum, count++);
switch (format) {
case CPIO:
CpioArchiveEntry cpioEntry = new CpioArchiveEntry(name);
cpioEntry.setSize(size);
cpioEntry.setTime(System.currentTimeMillis());
return cpioEntry;
case JAR:
JarArchiveEntry jarEntry = new JarArchiveEntry(name);
jarEntry.setSize(size);
jarEntry.setTime(System.currentTimeMillis());
return jarEntry;
case TAR:
TarArchiveEntry tarEntry = new TarArchiveEntry(name);
tarEntry.setSize(size);
tarEntry.setModTime(System.currentTimeMillis());
return tarEntry;
case ZIP:
ZipArchiveEntry zipEntry = new ZipArchiveEntry(name);
zipEntry.setSize(size);
zipEntry.setTime(System.currentTimeMillis());
return zipEntry;
}
// Normally, this code is not called because of the above switch.
throw new IOException("Format is configured.");
}
开发者ID:hata,项目名称:embulk-encoder-commons-compress,代码行数:31,代码来源:CommonsCompressArchiveProvider.java
示例5: visitFile
import org.apache.commons.compress.archivers.jar.JarArchiveEntry; //导入依赖的package包/类
private void visitFile(@Nonnull FileCopyDetails fileDetails) {
try {
JarArchiveEntry archiveEntry = new JarArchiveEntry(fileDetails.getRelativePath().getPathString());
archiveEntry.setTime(fileDetails.getLastModified());
archiveEntry.setUnixMode(UnixStat.FILE_FLAG | fileDetails.getMode());
zipOutStr.putArchiveEntry(archiveEntry);
fileDetails.copyTo(zipOutStr);
zipOutStr.closeArchiveEntry();
} catch (Exception e) {
throw new GradleException(String.format("Could not add %s to ZIP '%s'.", fileDetails, zipFile), e);
}
}
开发者ID:shevek,项目名称:jarjar,代码行数:13,代码来源:JarjarCopyAction.java
示例6: visitDir
import org.apache.commons.compress.archivers.jar.JarArchiveEntry; //导入依赖的package包/类
private void visitDir(@Nonnull FileCopyDetails dirDetails) {
try {
// Trailing slash in name indicates that entry is a directory
JarArchiveEntry archiveEntry = new JarArchiveEntry(dirDetails.getRelativePath().getPathString() + '/');
archiveEntry.setTime(dirDetails.getLastModified());
archiveEntry.setUnixMode(UnixStat.DIR_FLAG | dirDetails.getMode());
zipOutStr.putArchiveEntry(archiveEntry);
zipOutStr.closeArchiveEntry();
} catch (Exception e) {
throw new GradleException(String.format("Could not add %s to ZIP '%s'.", dirDetails, zipFile), e);
}
}
开发者ID:shevek,项目名称:jarjar,代码行数:13,代码来源:JarjarCopyAction.java
示例7: addJar
import org.apache.commons.compress.archivers.jar.JarArchiveEntry; //导入依赖的package包/类
private void addJar(File file) throws IOException {
Validate.notNull(file);
Validate.isTrue(file.isFile());
try (FileInputStream fis = new FileInputStream(file);
JarArchiveInputStream jais = new JarArchiveInputStream(fis)) {
JarArchiveEntry entry;
while ((entry = jais.getNextJarEntry()) != null) {
if (!entry.getName().endsWith(".class") || entry.isDirectory()) {
continue;
}
populateSuperClassMapping(jais);
}
}
}
开发者ID:offbynull,项目名称:coroutines,代码行数:16,代码来源:FileSystemClassInformationRepository.java
示例8: writeJarEntry
import org.apache.commons.compress.archivers.jar.JarArchiveEntry; //导入依赖的package包/类
private static void writeJarEntry(JarArchiveOutputStream jaos, String name, byte[] data) throws IOException {
ZipArchiveEntry entry = new JarArchiveEntry(name);
entry.setSize(data.length);
jaos.putArchiveEntry(entry);
jaos.write(data);
jaos.closeArchiveEntry();
}
开发者ID:offbynull,项目名称:coroutines,代码行数:8,代码来源:TestUtils.java
示例9: addToJar
import org.apache.commons.compress.archivers.jar.JarArchiveEntry; //导入依赖的package包/类
private void addToJar(final ArchiveOutputStream os, final Class<?> clazz) throws IOException {
final String name = clazz.getName().replace('.', '/') + ".class";
os.putArchiveEntry(new JarArchiveEntry(name));
IOUtils.copy(getClass().getResourceAsStream('/' + name), os);
os.closeArchiveEntry();
}
开发者ID:apache,项目名称:tomee,代码行数:7,代码来源:ExecMojo.java
注:本文中的org.apache.commons.compress.archivers.jar.JarArchiveEntry类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论