本文整理了Java中java.util.jar.Manifest.<init>()
方法的一些代码示例,展示了Manifest.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Manifest.<init>()
方法的具体详情如下:
包路径:java.util.jar.Manifest
类名称:Manifest
方法名:<init>
[英]Creates a new Manifest instance.
[中]创建一个新的清单实例。
代码示例来源:origin: Netflix/eureka
private static Manifest loadManifest(String jarUrl) throws Exception {
InputStream is = new URL(jarUrl + "!/META-INF/MANIFEST.MF").openStream();
try {
return new Manifest(is);
} finally {
is.close();
}
}
代码示例来源:origin: skylot/jadx
public static String getVersion() {
try {
ClassLoader classLoader = Jadx.class.getClassLoader();
if (classLoader != null) {
Enumeration<URL> resources = classLoader.getResources("META-INF/MANIFEST.MF");
while (resources.hasMoreElements()) {
Manifest manifest = new Manifest(resources.nextElement().openStream());
String ver = manifest.getMainAttributes().getValue("jadx-version");
if (ver != null) {
return ver;
}
}
}
} catch (Exception e) {
LOG.error("Can't get manifest file", e);
}
return "dev";
}
}
代码示例来源:origin: redisson/redisson
/**
* {@inheritDoc}
*/
public Manifest getManifest() throws IOException {
File file = new File(folder, JarFile.MANIFEST_NAME);
if (file.exists()) {
InputStream inputStream = new FileInputStream(file);
try {
return new Manifest(inputStream);
} finally {
inputStream.close();
}
} else {
return NO_MANIFEST;
}
}
代码示例来源:origin: apache/hive
public static void jarDir(File dir, String relativePath, ZipOutputStream zos) throws IOException {
Preconditions.checkNotNull(relativePath, "relativePath");
Preconditions.checkNotNull(zos, "zos");
// by JAR spec, if there is a manifest, it must be the first entry in
// the
// ZIP.
File manifestFile = new File(dir, JarFile.MANIFEST_NAME);
ZipEntry manifestEntry = new ZipEntry(JarFile.MANIFEST_NAME);
if (!manifestFile.exists()) {
zos.putNextEntry(manifestEntry);
new Manifest().write(new BufferedOutputStream(zos));
zos.closeEntry();
} else {
InputStream is = new FileInputStream(manifestFile);
copyToZipStream(is, manifestEntry, zos);
}
zos.closeEntry();
zipDir(dir, relativePath, zos, true);
zos.close();
}
代码示例来源:origin: stackoverflow.com
Manifest manifest = new Manifest();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
JarOutputStream target = new JarOutputStream(new FileOutputStream("output.jar"), manifest);
add(new File("inputDirectory"), target);
target.close();
代码示例来源:origin: spotbugs/spotbugs
File f = new File(url.getPath());
jis = new JarInputStream(url.openStream());
mf = jis.getManifest();
} catch (IOException ioe) {
try {
is = new FileInputStream(manifest);
mf = new Manifest(is);
} catch (IOException e) {
throw new PluginException("Failed loading manifest for plugin jar: " + url, e);
代码示例来源:origin: robovm/robovm
manifest = new Manifest(is, verifier != null);
} finally {
is.close();
代码示例来源:origin: apache/hive
/**
* Loads the manifest attributes from the jar.
*
* @throws java.net.MalformedURLException
* @throws IOException
*/
private static synchronized void loadManifestAttributes() throws IOException {
if (manifestAttributes != null) {
return;
}
Class<?> clazz = HiveDriver.class;
String classContainer = clazz.getProtectionDomain().getCodeSource()
.getLocation().toString();
URL manifestUrl = new URL("jar:" + classContainer
+ "!/META-INF/MANIFEST.MF");
Manifest manifest = new Manifest(manifestUrl.openStream());
manifestAttributes = manifest.getMainAttributes();
}
代码示例来源:origin: stackoverflow.com
Enumeration<URL> resources = getClass().getClassLoader()
.getResources("META-INF/MANIFEST.MF");
while (resources.hasMoreElements()) {
try {
Manifest manifest = new Manifest(resources.nextElement().openStream());
// check that this is your manifest and do what you need or get the next one
...
} catch (IOException E) {
// handle
}
}
代码示例来源:origin: org.patterntesting/patterntesting-rt
private static Manifest getManifest(final URI uri) throws IOException {
String content = IOUtils.toString(uri, StandardCharsets.UTF_8);
InputStream istream = new ByteArrayInputStream(content.getBytes("UTF8"));
try {
Manifest manifest = new Manifest(istream);
manifest.read(istream);
manifest.getMainAttributes().putValue(MANIFEST_URI, uri.toString());
return manifest;
} finally {
istream.close();
}
}
代码示例来源:origin: scouter-project/scouter
public static void print() throws IOException {
InputStream manifestStream = Thread.currentThread().getContextClassLoader()
.getResourceAsStream("META-INF/MANIFEST.MF");
try {
Manifest manifest = new Manifest(manifestStream);
Attributes attributes = manifest.getMainAttributes();
String impVersion = attributes.getValue("Implementation-Version");
System.out.println(attributes);
} catch (IOException ex) {
ex.printStackTrace();
}
}
代码示例来源:origin: redisson/redisson
/**
* {@inheritDoc}
*/
public File toJar(File file) throws IOException {
Manifest manifest = new Manifest();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, MANIFEST_VERSION);
return toJar(file, manifest);
}
代码示例来源:origin: stackoverflow.com
Class clazz = MyClass.class;
String className = clazz.getSimpleName() + ".class";
String classPath = clazz.getResource(className).toString();
if (!classPath.startsWith("jar")) {
// Class not from JAR
return;
}
String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) +
"/META-INF/MANIFEST.MF";
Manifest manifest = new Manifest(new URL(manifestPath).openStream());
Attributes attr = manifest.getMainAttributes();
String value = attr.getValue("Manifest-Version");
代码示例来源:origin: jenkinsci/jenkins
try (JarFile jf = new JarFile(new File(new URI(loc)), false)) {
Manifest mf = jf.getManifest();
if (mf != null) {
File manifestFile = new File(new URI(m.group(1) + "META-INF/MANIFEST.MF"));
if (manifestFile.isFile()) {
try (InputStream is = new FileInputStream(manifestFile)) {
if (isPluginManifest(new Manifest(is))) {
LOGGER.log(Level.FINE, "{0} looks like a Jenkins plugin based on {1}, OK", new Object[] {loc, manifestFile});
return true;
代码示例来源:origin: apache/geode
Path locationPath = new File(location).getCanonicalFile().toPath();
Files.createDirectories(locationPath);
Manifest manifest = new Manifest();
Attributes global = manifest.getMainAttributes();
global.put(Attributes.Name.MANIFEST_VERSION, "1.0.0");
global.put(new Attributes.Name("Class-Path"), String.join(" ", manifestEntries));
代码示例来源:origin: org.apache.ant/ant
manifest = new Manifest(in);
} catch (IOException e) {
throw new BuildException("Unable to read manifest", e, getLocation());
} finally {
if (in != null) {
in.close();
entryFile = new File(config.srcDir, entryName);
代码示例来源:origin: org.avaje.ebean/querybean-agent
private void addResource(InputStream is) throws IOException {
try {
addManifest(new Manifest(is));
} finally {
try {
is.close();
} catch (IOException e) {
System.err.println("Error closing manifest resource");
e.printStackTrace();
}
}
}
代码示例来源:origin: com.netflix.eureka/eureka-client
private static Manifest loadManifest(String jarUrl) throws Exception {
InputStream is = new URL(jarUrl + "!/META-INF/MANIFEST.MF").openStream();
try {
return new Manifest(is);
} finally {
is.close();
}
}
代码示例来源:origin: chewiebug/GCViewer
/**
* Returns Manifest-Attributes for MANIFEST.MF, if running for a .jar file
*
* @return Manifest Attributes (may be empty but never null)
* @throws IOException If something went wrong finding the MANIFEST file
* @see <a href="http://stackoverflow.com/a/1273432">stackoverflow article</a>
*/
private static Attributes getAttributes() throws IOException {
Class clazz = BuildInfoReader.class;
String className = clazz.getSimpleName() + ".class";
String classPath = clazz.getResource(className).toString();
if (!classPath.startsWith("jar")) {
// Class not from JAR
return new Attributes(0);
}
String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + FILE_NAME;
Manifest manifest = new Manifest(new URL(manifestPath).openStream());
return manifest.getMainAttributes();
}
代码示例来源:origin: stackoverflow.com
URLClassLoader cl = (URLClassLoader) getClass().getClassLoader();
try {
URL url = cl.findResource("META-INF/MANIFEST.MF");
Manifest manifest = new Manifest(url.openStream());
// do stuff with it
...
} catch (IOException E) {
// handle
}
内容来源于网络,如有侵权,请联系作者删除!