use of java.util.jar.JarFile in project enumerable by hraberg.
the class LambdaCompiler method unjar.
File unjar(JarFile jarFile) throws IOException {
InputStream in = null;
OutputStream out = null;
File tempDir = new File(getProperty("java.io.tmpdir"), new File(jarFile.getName()).getName() + "-" + currentTimeMillis());
ensureDirCreated(tempDir);
try {
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry jarEntry = entries.nextElement();
File file = new File(tempDir, jarEntry.getName());
if (jarEntry.isDirectory()) {
file.mkdir();
} else {
file.getParentFile().mkdirs();
in = jarFile.getInputStream(jarEntry);
out = new FileOutputStream(file);
int read;
while ((read = in.read(buffer)) != -1) out.write(buffer, 0, read);
out.flush();
}
}
return tempDir;
} finally {
if (out != null)
out.close();
if (in != null)
in.close();
jarFile.close();
}
}
use of java.util.jar.JarFile 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.JarFile 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.JarFile in project Openfire by igniterealtime.
the class BookmarksPlugin method getPluginJar.
/**
* Returns the plugin JAR for the plugin of the provided name.
*
* @param pluginName the name of the plugin (cannot be null or empty).
* @return The plugin JAR file, or null when not found.
*/
private static JarFile getPluginJar(final String pluginName) throws IOException {
File pluginDir = new File(JiveGlobals.getHomeDirectory(), "plugins");
File[] jars = pluginDir.listFiles(new FileFilter() {
public boolean accept(File pathname) {
return pathname.getName().equalsIgnoreCase(pluginName + ".jar");
}
});
final File jar;
if (jars.length > 0) {
return new JarFile(jars[0]);
} else {
return null;
}
}
use of java.util.jar.JarFile in project flink by apache.
the class JarListHandler method handleJsonRequest.
@Override
public String handleJsonRequest(Map<String, String> pathParams, Map<String, String> queryParams, ActorGateway jobManager) throws Exception {
try {
StringWriter writer = new StringWriter();
JsonGenerator gen = JsonFactory.jacksonFactory.createGenerator(writer);
gen.writeStartObject();
gen.writeStringField("address", queryParams.get(RuntimeMonitorHandler.WEB_MONITOR_ADDRESS_KEY));
gen.writeArrayFieldStart("files");
File[] list = jarDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(".jar");
}
});
for (File f : list) {
// separate the uuid and the name parts.
String id = f.getName();
int startIndex = id.indexOf("_");
if (startIndex < 0) {
continue;
}
String name = id.substring(startIndex + 1);
if (name.length() < 5 || !name.endsWith(".jar")) {
continue;
}
gen.writeStartObject();
gen.writeStringField("id", id);
gen.writeStringField("name", name);
gen.writeNumberField("uploaded", f.lastModified());
gen.writeArrayFieldStart("entry");
String[] classes = new String[0];
try {
JarFile jar = new JarFile(f);
Manifest manifest = jar.getManifest();
String assemblerClass = null;
if (manifest != null) {
assemblerClass = manifest.getMainAttributes().getValue(PackagedProgram.MANIFEST_ATTRIBUTE_ASSEMBLER_CLASS);
if (assemblerClass == null) {
assemblerClass = manifest.getMainAttributes().getValue(PackagedProgram.MANIFEST_ATTRIBUTE_MAIN_CLASS);
}
}
if (assemblerClass != null) {
classes = assemblerClass.split(",");
}
} catch (IOException ignored) {
// we simply show no entries here
}
// show every entry class that can be loaded later on.
for (String clazz : classes) {
clazz = clazz.trim();
PackagedProgram program = null;
try {
program = new PackagedProgram(f, clazz, new String[0]);
} catch (Exception ignored) {
// ignore jar files which throw an error upon creating a PackagedProgram
}
if (program != null) {
gen.writeStartObject();
gen.writeStringField("name", clazz);
String desc = program.getDescription();
gen.writeStringField("description", desc == null ? "No description provided" : desc);
gen.writeEndObject();
}
}
gen.writeEndArray();
gen.writeEndObject();
}
gen.writeEndArray();
gen.writeEndObject();
gen.close();
return writer.toString();
} catch (Exception e) {
throw new RuntimeException("Failed to fetch jar list: " + e.getMessage(), e);
}
}
Aggregations