本文整理匯總了Java中java.util.jar.JarInputStream.getManifest方法的典型用法代碼示例。如果您正苦於以下問題:Java JarInputStream.getManifest方法的具體用法?Java JarInputStream.getManifest怎麽用?Java JarInputStream.getManifest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.jar.JarInputStream
的用法示例。
在下文中一共展示了JarInputStream.getManifest方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: copyJarFile
import java.util.jar.JarInputStream; //導入方法依賴的package包/類
static void copyJarFile(JarInputStream in, JarOutputStream out) throws IOException {
if (in.getManifest() != null) {
ZipEntry me = new ZipEntry(JarFile.MANIFEST_NAME);
out.putNextEntry(me);
in.getManifest().write(out);
out.closeEntry();
}
byte[] buffer = new byte[1 << 14];
for (JarEntry je; (je = in.getNextJarEntry()) != null; ) {
out.putNextEntry(je);
for (int nr; 0 < (nr = in.read(buffer)); ) {
out.write(buffer, 0, nr);
}
}
in.close();
markJarFile(out); // add PACK200 comment
}
示例2: extract
import java.util.jar.JarInputStream; //導入方法依賴的package包/類
/**Find the jar I was loaded from and extract all entries except my own
* class file.
*@throws Exception if anything doesn't work, punt
*/
public void extract() throws Exception {
URL jarURL =
this.getClass().getProtectionDomain().getCodeSource().getLocation();
InputStream is = jarURL.openStream();
JarInputStream jis = new JarInputStream( is);
Manifest mf = null;
for ( JarEntry je;; ) {
je = jis.getNextJarEntry();
if ( je == null )
break;
if ( null == mf ) {
mf = jis.getManifest();
if ( null != mf )
setDefaults( mf.getMainAttributes());
}
if ( ! je.getName().equals( me) )
extract( je, jis);
jis.closeEntry();
}
jis.close();
}
示例3: loadMainClassFromClasspathJar
import java.util.jar.JarInputStream; //導入方法依賴的package包/類
private static MainPair loadMainClassFromClasspathJar(File jarFile, String[] args) throws Exception {
final JarInputStream inputStream = new JarInputStream(new FileInputStream(jarFile));
try {
final Manifest manifest = inputStream.getManifest();
final String vmParams = manifest.getMainAttributes().getValue("VM-Options");
if (vmParams != null) {
final HashMap vmOptions = new HashMap();
parseVmOptions(vmParams, vmOptions);
for (Iterator iterator = vmOptions.keySet().iterator(); iterator.hasNext(); ) {
String optionName = (String)iterator.next();
System.setProperty(optionName, (String)vmOptions.get(optionName));
}
}
}
finally {
if (inputStream != null) {
inputStream.close();
}
jarFile.deleteOnExit();
}
return new MainPair(Class.forName(args[1]), new String[args.length - 2]);
}
示例4: loadManifestClasspath
import java.util.jar.JarInputStream; //導入方法依賴的package包/類
public static String[] loadManifestClasspath(File file) {
try {
JarInputStream inputStream = new JarInputStream(new FileInputStream(file));
try {
final Manifest manifest = inputStream.getManifest();
if (manifest != null) {
final String classPath = manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
if (classPath != null) {
return classPath.split(" ");
}
}
}
finally {
inputStream.close();
}
}
catch (Exception ignore) { }
return null;
}
示例5: testManifestWithJarsAndDirectories
import java.util.jar.JarInputStream; //導入方法依賴的package包/類
@Test
public void testManifestWithJarsAndDirectories() throws Exception {
final File tempDirectory = FileUtil.createTempDirectory("dirWithClasses", "suffix");
File jarFile = null;
try {
final List<String> paths = Arrays.asList(tempDirectory.getAbsolutePath(), tempDirectory.getAbsolutePath() + "/directory with spaces/some.jar");
jarFile = CommandLineWrapperUtil.createClasspathJarFile(new Manifest(), paths);
final JarInputStream inputStream = new JarInputStream(new FileInputStream(jarFile));
final Manifest manifest = inputStream.getManifest();
final String classPath = manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
final String tempDirectoryUrl = tempDirectory.toURI().toURL().toString();
assertTrue(tempDirectoryUrl, tempDirectoryUrl.endsWith("/"));
assertEquals(tempDirectoryUrl + " " + tempDirectoryUrl +"directory%20with%20spaces/some.jar", classPath);
}
finally {
FileUtil.delete(tempDirectory);
if (jarFile != null) {
FileUtil.delete(jarFile);
}
}
}
示例6: getBundleSymbolicName
import java.util.jar.JarInputStream; //導入方法依賴的package包/類
/**
* Get the symbolic name from a bundle file by looking at the manifest
* @param bundleFile bundle file
* @return the name extracted from the manifest
* @throws IOException if reading the jar failed
*/
public static String getBundleSymbolicName(File bundleFile) throws IOException {
String name = null;
final JarInputStream jis = new JarInputStream(new FileInputStream(bundleFile));
try {
final Manifest m = jis.getManifest();
if (m == null) {
throw new IOException("Manifest is null in " + bundleFile.getAbsolutePath());
}
name = m.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
} finally {
jis.close();
}
return name;
}
示例7: getBundleVersionFromFile
import java.util.jar.JarInputStream; //導入方法依賴的package包/類
/**
* Get the version form a bundle file by looking at the manifest
* @param bundleFile bundle file
* @return the version
* @throws IOException if reading the bundle jar failed
*/
public static String getBundleVersionFromFile(File bundleFile) throws IOException {
String version = null;
final JarInputStream jis = new JarInputStream(new FileInputStream(bundleFile));
try {
final Manifest m = jis.getManifest();
if(m == null) {
throw new IOException("Manifest is null in " + bundleFile.getAbsolutePath());
}
version = m.getMainAttributes().getValue(Constants.BUNDLE_VERSION);
} finally {
jis.close();
}
return version;
}
示例8: getJarManifest
import java.util.jar.JarInputStream; //導入方法依賴的package包/類
/**
* 提取jar包的Manifest
*
* @param jarFilePath
* @return
*/
public static Manifest getJarManifest(String jarFilePath) {
try {
@SuppressWarnings("resource")
JarInputStream jis = new JarInputStream(new FileInputStream(jarFilePath));
return jis.getManifest();
}
catch (IOException e) {
// ignore
}
return null;
}
示例9: getManifest
import java.util.jar.JarInputStream; //導入方法依賴的package包/類
private Manifest getManifest() throws IOException {
File mainJar = new File(outputDirectory, mainJarFilename + ".jar");
JarInputStream in =
new JarInputStream(new FileInputStream(mainJar));
Manifest mf = in.getManifest();
if (mf != null) {
Manifest copy = new Manifest(mf);
in.close();
return copy;
}
in.close();
return null;
}
示例10: JarLoader
import java.util.jar.JarInputStream; //導入方法依賴的package包/類
/**
* Creates a loader to load a specified JAR file.
*
* We place no restrictions on what the <code>URL</code> points to here.
* instead any access restrictions (from trusted java) are enforced by
* the <code>Security Manager</code> defined in <code>Backend.java</code>.
*
* @param url : The URL to load
* @return JarLoader : Classloader for a specified JAR
* @throws IOException : when the Jar cannot be read
*
*/
JarLoader(ClassLoader parent, URL url) throws IOException
{
super(parent);
m_url = url;
m_entries = new HashMap();
m_images = new HashMap();
// Just having a JAR in your CLASSPATH will cause us to load it,
// which means you need security access to it.
JarInputStream jis = new JarInputStream(url.openStream());
ByteArrayOutputStream img = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
JarEntry je;
for (je = jis.getNextJarEntry();
je != null;
je = jis.getNextJarEntry())
{
if (je.isDirectory())
continue;
String entryName = je.getName();
Attributes attr = je.getAttributes();
int nBytes;
img.reset();
while ((nBytes = jis.read(buf)) > 0)
img.write(buf, 0, nBytes);
jis.closeEntry();
m_entries.put(entryName, img.toByteArray());
}
m_manifest = jis.getManifest();
}
示例11: createBundleVersion
import java.util.jar.JarInputStream; //導入方法依賴的package包/類
/**
* creates a bundle version object for a local jar file
* uses symbolic name, name and version in the manifest
*/
private BundleVersion createBundleVersion(File file, String type) throws FileNotFoundException, IOException {
JarInputStream jarStream = new JarInputStream(new FileInputStream(file));
Manifest mf = jarStream.getManifest();
Attributes attr = mf.getMainAttributes();
String symName = attr.getValue("Bundle-SymbolicName");
String version = attr.getValue("Bundle-Version");
version = Utils.formatVersion(version);
String name = attr.getValue("Bundle-Name");
if(name.contains("%")) {
name = symName;
}
jarStream.close();
if(!localHandler.getLocalRepository().containsBundle(symName) || (localHandler.getLocalRepository().getBundle(symName, version) == null)) {
PVBundle bundle = new PVBundle();
bundle.setName(name);
bundle.setSymbolicName(symName);
bundle.setType(type);
bundle.setSource("local installation");
BundleVersion bVer = new BundleVersion();
bVer.setBundle(bundle);
bVer.setVersion(version);
File destFile = new File(localHandler.getLocalRepository().getUrl(), symName + "-" + version + ".jar");
Utils.copyFile(file, destFile);
bVer.setJarFile(destFile.getAbsolutePath());
return bVer;
}
return null;
}
示例12: rewrite
import java.util.jar.JarInputStream; //導入方法依賴的package包/類
private static File rewrite(File jar, String[] mavenCP, String classpath) throws IOException { // #190992
String[] classpathEntries = tokenizePath(classpath);
StringBuilder classPathHeader = new StringBuilder();
for (String artifact : mavenCP) {
String[] grpArtVers = artifact.split(":");
String partOfPath = File.separatorChar + grpArtVers[0].replace('.', File.separatorChar) + File.separatorChar + grpArtVers[1] + File.separatorChar + grpArtVers[2] + File.separatorChar + grpArtVers[1] + '-' + grpArtVers[2];
File dep = null;
for (String classpathEntry : classpathEntries) {
if (classpathEntry.endsWith(".jar") && classpathEntry.contains(partOfPath)) {
dep = new File(classpathEntry);
break;
}
}
if (dep == null) {
throw new IOException("no match for " + artifact + " found in " + classpath);
}
File depCopy = File.createTempFile(artifact.replace(':', '-') + '-', ".jar");
depCopy.deleteOnExit();
NbTestCase.copytree(dep, depCopy);
if (classPathHeader.length() > 0) {
classPathHeader.append(' ');
}
classPathHeader.append(depCopy.getName());
}
String n = jar.getName();
int dot = n.lastIndexOf('.');
File jarCopy = File.createTempFile(n.substring(0, dot) + '-', n.substring(dot));
jarCopy.deleteOnExit();
InputStream is = new FileInputStream(jar);
try {
OutputStream os = new FileOutputStream(jarCopy);
try {
JarInputStream jis = new JarInputStream(is);
Manifest mani = new Manifest(jis.getManifest());
mani.getMainAttributes().putValue("Class-Path", classPathHeader.toString());
JarOutputStream jos = new JarOutputStream(os, mani);
JarEntry entry;
while ((entry = jis.getNextJarEntry()) != null) {
if (entry.getName().matches("META-INF/.+[.]SF")) {
throw new IOException("cannot handle signed JARs");
}
jos.putNextEntry(entry);
byte[] buf = new byte[4092];
for (;;) {
int more = jis.read(buf, 0, buf.length);
if (more == -1) {
break;
}
jos.write(buf, 0, more);
}
}
jis.close();
jos.close();
} finally {
os.close();
}
} finally {
is.close();
}
return jarCopy;
}
示例13: run
import java.util.jar.JarInputStream; //導入方法依賴的package包/類
void run(JarInputStream in, OutputStream out) throws IOException {
// First thing we do is get the manifest, as JIS does
// not provide the Manifest as an entry.
if (in.getManifest() != null) {
ByteArrayOutputStream tmp = new ByteArrayOutputStream();
in.getManifest().write(tmp);
InputStream tmpIn = new ByteArrayInputStream(tmp.toByteArray());
pkg.addFile(readFile(JarFile.MANIFEST_NAME, tmpIn));
}
for (JarEntry je; (je = in.getNextJarEntry()) != null; ) {
InFile inFile = new InFile(je);
String name = inFile.name;
Package.File bits = readFile(name, in);
Package.File file = null;
// (5078608) : discount the resource files in META-INF
// from segment computation.
long inflen = (isMetaInfFile(name))
? 0L
: inFile.getInputLength();
if ((segmentSize += inflen) > segmentLimit) {
segmentSize -= inflen;
int nextCount = -1; // don't know; it's a stream
flushPartial(out, nextCount);
}
if (verbose > 1) {
Utils.log.fine("Reading " + name);
}
assert(je.isDirectory() == name.endsWith("/"));
if (isClassFile(name)) {
file = readClass(name, bits.getInputStream());
}
if (file == null) {
file = bits;
pkg.addFile(file);
}
inFile.copyTo(file);
noteRead(inFile);
}
flushAll(out);
}
示例14: run
import java.util.jar.JarInputStream; //導入方法依賴的package包/類
void run(JarInputStream in, OutputStream out) throws IOException {
// First thing we do is get the manifest, as JIS does
// not provide the Manifest as an entry.
if (in.getManifest() != null) {
ByteArrayOutputStream tmp = new ByteArrayOutputStream();
in.getManifest().write(tmp);
InputStream tmpIn = new ByteArrayInputStream(tmp.toByteArray());
pkg.addFile(readFile(JarFile.MANIFEST_NAME, tmpIn));
}
for (JarEntry je; (je = in.getNextJarEntry()) != null; ) {
InFile inFile = new InFile(je);
String name = inFile.name;
Package.File bits = readFile(name, in);
Package.File file = null;
// (5078608) : discount the resource files in META-INF
// from segment computation.
long inflen = (inFile.isMetaInfFile())
? 0L
: inFile.getInputLength();
if ((segmentSize += inflen) > segmentLimit) {
segmentSize -= inflen;
int nextCount = -1; // don't know; it's a stream
flushPartial(out, nextCount);
}
if (verbose > 1) {
Utils.log.fine("Reading " + name);
}
assert(je.isDirectory() == name.endsWith("/"));
if (inFile.mustProcess()) {
file = readClass(name, bits.getInputStream());
}
if (file == null) {
file = bits;
pkg.addFile(file);
}
inFile.copyTo(file);
noteRead(inFile);
}
flushAll(out);
}
示例15: main
import java.util.jar.JarInputStream; //導入方法依賴的package包/類
public static final void main( String[] args ) throws IOException {
if ( args.length != 2 ) {
System.out.println( "usage: TestJarInsert jarFile insertFile" );
System.exit( 1 );
}
String jarFileName = args[0];
String insertFileName = args[1];
// the file to insert
File insertFile = new File( insertFileName );
InputStream insertStream = new FileInputStream( insertFile );
// the original JAR file
File jarFile = new File( jarFileName );
JarInputStream jarStream = new JarInputStream( new FileInputStream( jarFile ) );
Manifest manifest = jarStream.getManifest();
if ( manifest == null ) {
System.out.println( "JAR file is missing manifest" );
System.exit( 1 );
}
// output goes to a temp JAR file
String tmpFileName = jarFileName + ".tmp";
File tmpFile = new File( tmpFileName );
JarOutputStream tmpStream = new JarOutputStream( new FileOutputStream( tmpFile ), manifest );
byte[] buffer = new byte[1024];
int bytesRead;
// copy all entries from input to output, skipping the insert file if it already exists
JarEntry jarEntry = jarStream.getNextJarEntry();
while ( jarEntry != null ) {
if ( !jarEntry.getName().equals( insertFileName ) ) {
tmpStream.putNextEntry( jarEntry );
while ( ( bytesRead = jarStream.read( buffer ) ) > 0 ) {
tmpStream.write( buffer, 0, bytesRead );
}
}
jarEntry = jarStream.getNextJarEntry();
}
// add properties file to output
jarEntry = new JarEntry( insertFileName );
tmpStream.putNextEntry( jarEntry );
while ( ( bytesRead = insertStream.read( buffer ) ) != -1 ) {
tmpStream.write( buffer, 0, bytesRead );
}
// close the streams
insertStream.close();
jarStream.close();
tmpStream.close();
// if everything went OK, move tmp file to JAR file
boolean renameSuccess = tmpFile.renameTo( jarFile );
if ( !renameSuccess ) {
System.err.println( "failed to rename " + tmpFileName + " to " + jarFileName );
System.exit( 1 );
}
}