use of java.util.jar.JarEntry in project semantic-versioning by jeluard.
the class JarDiff method loadClasses.
/**
* Load all the classes from the specified URL and store information
* about them in the specified map.
* This currently only works for jar files, <b>not</b> directories
* which contain classes in subdirectories or in the current directory.
*
* @param infoMap the map to store the ClassInfo in.
* @param file the jarfile to load classes from.
* @throws IOException if there is an IOException reading info about a
* class.
*/
private void loadClasses(Map infoMap, File file) throws DiffException {
try {
JarFile jar = new JarFile(file);
Enumeration e = jar.entries();
while (e.hasMoreElements()) {
JarEntry entry = (JarEntry) e.nextElement();
String name = entry.getName();
if (!entry.isDirectory() && name.endsWith(".class")) {
ClassReader reader = new ClassReader(jar.getInputStream(entry));
ClassInfo ci = loadClassInfo(reader);
infoMap.put(ci.getName(), ci);
}
}
} catch (IOException ioe) {
throw new DiffException(ioe);
}
}
use of java.util.jar.JarEntry in project rest.li by linkedin.
the class TestUtil method createSchemaJar.
public static void createSchemaJar(String jarFileName, Map<String, String> fileToSchemaMap, boolean debug) throws IOException {
if (debug)
out.println("creating " + jarFileName);
FileOutputStream jarFileStream = new FileOutputStream(jarFileName);
JarOutputStream jarStream = new JarOutputStream(jarFileStream, new Manifest());
for (Map.Entry<String, String> entry : fileToSchemaMap.entrySet()) {
String key = entry.getKey();
// JARs use resource separator as the file separator
String filename = "pegasus" + key.replace(File.separatorChar, '/');
if (debug)
out.println(" adding " + filename);
JarEntry jarEntry = new JarEntry(filename);
jarStream.putNextEntry(jarEntry);
jarStream.write(entry.getValue().getBytes(Data.UTF_8_CHARSET));
}
jarStream.close();
jarFileStream.close();
}
use of java.util.jar.JarEntry in project rest.li by linkedin.
the class FileFormatDataSchemaParser method parseSources.
public DataSchemaParser.ParseResult parseSources(String[] sources) throws IOException {
final DataSchemaParser.ParseResult result = new DataSchemaParser.ParseResult();
try {
for (String source : sources) {
final File sourceFile = new File(source);
if (sourceFile.exists()) {
if (sourceFile.isDirectory()) {
final FileUtil.FileExtensionFilter filter = new FileUtil.FileExtensionFilter(_schemaParserFactory.getLanguageExtension());
final List<File> sourceFilesInDirectory = FileUtil.listFiles(sourceFile, filter);
for (File f : sourceFilesInDirectory) {
parseFile(f, result);
result.getSourceFiles().add(f);
}
} else {
if (sourceFile.getName().endsWith(".jar")) {
final JarFile jarFile = new JarFile(sourceFile);
final Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
final JarEntry entry = entries.nextElement();
if (!entry.isDirectory() && entry.getName().endsWith(_schemaParserFactory.getLanguageExtension())) {
parseJarEntry(jarFile, entry, result);
}
}
} else {
parseFile(sourceFile, result);
}
result.getSourceFiles().add(sourceFile);
}
} else {
final StringBuilder errorMessage = new StringBuilder();
final DataSchema schema = _schemaResolver.findDataSchema(source, errorMessage);
if (schema == null) {
result._messageBuilder.append("File cannot be opened or schema name cannot be resolved: ").append(source).append("\n");
}
if (errorMessage.length() > 0) {
result._messageBuilder.append(errorMessage.toString());
}
}
}
if (result._messageBuilder.length() > 0) {
throw new IOException(result.getMessage());
}
for (Map.Entry<String, DataSchemaLocation> entry : _schemaResolver.nameToDataSchemaLocations().entrySet()) {
final DataSchema schema = _schemaResolver.bindings().get(entry.getKey());
result.getSchemaAndLocations().put(schema, entry.getValue());
}
return result;
} catch (RuntimeException e) {
if (result._messageBuilder.length() > 0) {
e = new RuntimeException("Unexpected " + e.getClass().getSimpleName() + " encountered.\n" + "This may be caused by the following parsing or processing errors:\n" + result.getMessage(), e);
}
throw e;
}
}
use of java.util.jar.JarEntry in project Openfire by igniterealtime.
the class ModuleLoader method loadNonBridgeModule.
private void loadNonBridgeModule(String dirEntry) throws IOException {
JarFile jarFile = new JarFile(dirEntry);
Enumeration entries = jarFile.entries();
if (entries == null) {
Logger.println("No entries in jarFile: " + dirEntry);
return;
}
while (entries.hasMoreElements()) {
JarEntry jarEntry = (JarEntry) entries.nextElement();
String className = jarEntry.getName();
int ix;
if ((ix = className.indexOf(".class")) < 0) {
if (Logger.logLevel >= Logger.LOG_INFO) {
Logger.println("Skipping non-class entry in jarFile: " + className);
}
continue;
}
className = className.replaceAll(".class", "");
className = className.replaceAll("/", ".");
try {
if (Logger.logLevel >= Logger.LOG_INFO) {
Logger.println("Looking for class '" + className + "'");
}
// load the class
loadClass(className);
} catch (ClassNotFoundException e) {
Logger.println("ClassNotFoundException: '" + className + "'");
}
}
}
use of java.util.jar.JarEntry in project jersey by jersey.
the class JarUtils method createJarFile.
public static File createJarFile(final String name, final Suffix s, final String base, final Map<String, String> entries) throws IOException {
final File tempJar = File.createTempFile(name, "." + s);
tempJar.deleteOnExit();
final JarOutputStream jos = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tempJar)), new Manifest());
final Set<String> usedSegments = new HashSet<String>();
for (final Map.Entry<String, String> entry : entries.entrySet()) {
for (final String path : getPaths(entry.getValue())) {
if (usedSegments.contains(path)) {
continue;
}
usedSegments.add(path);
final JarEntry e = new JarEntry(path);
jos.putNextEntry(e);
jos.closeEntry();
}
final JarEntry e = new JarEntry(entry.getValue());
jos.putNextEntry(e);
final InputStream f = new BufferedInputStream(new FileInputStream(base + entry.getKey()));
final byte[] buf = new byte[1024];
int read = 1024;
while ((read = f.read(buf, 0, read)) != -1) {
jos.write(buf, 0, read);
}
jos.closeEntry();
}
jos.close();
return tempJar;
}
Aggregations