本文整理匯總了Java中java.util.jar.JarInputStream.close方法的典型用法代碼示例。如果您正苦於以下問題:Java JarInputStream.close方法的具體用法?Java JarInputStream.close怎麽用?Java JarInputStream.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.jar.JarInputStream
的用法示例。
在下文中一共展示了JarInputStream.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testNoManifest
import java.util.jar.JarInputStream; //導入方法依賴的package包/類
@Test
public void testNoManifest() throws Exception {
File dir = new File(System.getProperty("test.build.dir", "target/test-dir"),
TestJarFinder.class.getName() + "-testNoManifest");
delete(dir);
dir.mkdirs();
File propsFile = new File(dir, "props.properties");
Writer writer = new FileWriter(propsFile);
new Properties().store(writer, "");
writer.close();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JarOutputStream zos = new JarOutputStream(baos);
JarFinder.jarDir(dir, "", zos);
JarInputStream jis =
new JarInputStream(new ByteArrayInputStream(baos.toByteArray()));
Assert.assertNotNull(jis.getManifest());
jis.close();
}
示例2: readManifest
import java.util.jar.JarInputStream; //導入方法依賴的package包/類
@SuppressWarnings("PMD.EmptyCatchBlock")
private InputStream readManifest(InputStream binaryExtension) throws IOException {
JarInputStream jar = new JarInputStream(binaryExtension);
try {
JarEntry entry;
do {
entry = jar.getNextJarEntry();
if (entry != null && MANIFEST_LOCATION.equals(entry.getName())) {
return jar;
}
} while (entry != null);
jar.close();
return null;
} catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception e) {
try {
jar.close();
} catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception ex2) {
// ignore
}
throw SyndesisServerException.launderThrowable(e);
}
}
示例3: scanJar
import java.util.jar.JarInputStream; //導入方法依賴的package包/類
protected void scanJar(URL jarUrl, Map<String, ResourceInfo> resInfos) throws IOException {
JarInputStream jarInput = new JarInputStream(jarUrl.openStream(), false);
JarEntry entry = null;
while((entry = jarInput.getNextJarEntry()) != null) {
String entryName = entry.getName();
if(entryName != null && entryName.endsWith(".class")) {
final String className = entryName.substring(0,
entryName.length() - 6).replace('/', '.');
if(!resInfos.containsKey(className)) {
ClassReader classReader = new ClassReader(jarInput);
ResourceInfo resInfo = new ResourceInfo(null, className, null);
ResourceInfoVisitor visitor = new ResourceInfoVisitor(resInfo);
classReader.accept(visitor, ClassReader.SKIP_CODE |
ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
if(visitor.isCreoleResource()) {
resInfos.put(className, resInfo);
}
}
}
}
jarInput.close();
}
示例4: tstConnectionToJarOnClassPath
import java.util.jar.JarInputStream; //導入方法依賴的package包/類
public void tstConnectionToJarOnClassPath() throws Exception {
URL url = bundle.getEntry("bundleclasspath/simple.jar");
System.out.println("jar url is " + url);
URLConnection con = url.openConnection();
System.out.println(con);
System.out.println(con.getContentType());
InputStream stream = con.getInputStream();
JarInputStream jis = new JarInputStream(stream);
System.out.println(jis);
System.out.println(jis.available());
System.out.println(jis.getNextJarEntry());
System.out.println(jis.getNextJarEntry());
System.out.println(jis.getNextJarEntry());
System.out.println(jis.available());
System.out.println(jis.getNextJarEntry());
System.out.println(jis.available());
jis.close();
}
示例5: pack
import java.util.jar.JarInputStream; //導入方法依賴的package包/類
/**
* Takes a JarInputStream and converts into a pack-stream.
* <p>
* Closes its input but not its output. (Pack200 archives are appendable.)
* <p>
* The modification time and deflation hint attributes are not available,
* for the jar-manifest file and the directory containing the file.
*
* @see #MODIFICATION_TIME
* @see #DEFLATION_HINT
* @param in a JarInputStream
* @param out an OutputStream
* @exception IOException if an error is encountered.
*/
public synchronized void pack(JarInputStream in, OutputStream out) throws IOException {
assert(Utils.currentInstance.get() == null);
TimeZone tz = (props.getBoolean(Utils.PACK_DEFAULT_TIMEZONE)) ? null :
TimeZone.getDefault();
try {
Utils.currentInstance.set(this);
if (tz != null) TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
if ("0".equals(props.getProperty(Pack200.Packer.EFFORT))) {
Utils.copyJarFile(in, out);
} else {
(new DoPack()).run(in, out);
}
} finally {
Utils.currentInstance.set(null);
if (tz != null) TimeZone.setDefault(tz);
in.close();
}
}
示例6: 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
}
示例7: pack
import java.util.jar.JarInputStream; //導入方法依賴的package包/類
/**
* Takes a JarInputStream and converts into a pack-stream.
* <p>
* Closes its input but not its output. (Pack200 archives are appendable.)
* <p>
* The modification time and deflation hint attributes are not available,
* for the jar-manifest file and the directory containing the file.
*
* @see #MODIFICATION_TIME
* @see #DEFLATION_HINT
* @param in a JarInputStream
* @param out an OutputStream
* @exception IOException if an error is encountered.
*/
public synchronized void pack(JarInputStream in, OutputStream out) throws IOException {
assert (Utils.currentInstance.get() == null);
boolean needUTC = !props.getBoolean(Utils.PACK_DEFAULT_TIMEZONE);
try {
Utils.currentInstance.set(this);
if (needUTC) {
Utils.changeDefaultTimeZoneToUtc();
}
if ("0".equals(props.getProperty(Pack200.Packer.EFFORT))) {
Utils.copyJarFile(in, out);
} else {
(new DoPack()).run(in, out);
}
} finally {
Utils.currentInstance.set(null);
if (needUTC) {
Utils.restoreDefaultTimeZone();
}
in.close();
}
}
示例8: 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;
}
示例9: 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]);
}
示例10: getFromJARFile
import java.util.jar.JarInputStream; //導入方法依賴的package包/類
/**
* 從jar包中加載class
* @param loader
* @param jar
* @param packageName
* @return
* @throws IOException
* @throws ClassNotFoundException
*/
private static Set<Class<?>> getFromJARFile(final ClassLoader loader, final String jar, final String packageName)
throws IOException, ClassNotFoundException {
final Set<Class<?>> classes = new HashSet<Class<?>>();
final JarInputStream jarFile = new JarInputStream(new FileInputStream(jar));
try {
JarEntry jarEntry;
do {
jarEntry = jarFile.getNextJarEntry();
if (jarEntry != null) {
String className = jarEntry.getName();
if (className.endsWith(".class") && getPackageName(className).equals(packageName)) {
className = stripFilenameExtension(className);
classes.add(Class.forName(className.replace('/', '.'), true, loader));
}
}
} while (jarEntry != null);
} finally {
jarFile.close();
}
return classes;
}
示例11: main
import java.util.jar.JarInputStream; //導入方法依賴的package包/類
public static final void main( String[] args ) {
if ( args.length != 1 ) {
System.out.println( "usage: TestReadJarEntries file.jar" );
System.exit( 1 );
}
try {
String jarFileName = args[0];
InputStream inputStream = new FileInputStream( jarFileName );
JarInputStream jarInputStream = new JarInputStream( inputStream );
JarEntry jarEntry = jarInputStream.getNextJarEntry();
while ( jarEntry != null ) {
System.out.println( jarEntry.getName() );
jarEntry = jarInputStream.getNextJarEntry();
}
jarInputStream.close();
}
catch ( IOException e ) {
e.printStackTrace();
System.exit( 1 );
}
}
示例12: 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();
}
示例13: testExistingManifest
import java.util.jar.JarInputStream; //導入方法依賴的package包/類
@Test
public void testExistingManifest() throws Exception {
File dir = new File(System.getProperty("test.build.dir", "target/test-dir"),
TestJarFinder.class.getName() + "-testExistingManifest");
delete(dir);
dir.mkdirs();
File metaInfDir = new File(dir, "META-INF");
metaInfDir.mkdirs();
File manifestFile = new File(metaInfDir, "MANIFEST.MF");
Manifest manifest = new Manifest();
OutputStream os = new FileOutputStream(manifestFile);
manifest.write(os);
os.close();
File propsFile = new File(dir, "props.properties");
Writer writer = new FileWriter(propsFile);
new Properties().store(writer, "");
writer.close();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JarOutputStream zos = new JarOutputStream(baos);
JarFinder.jarDir(dir, "", zos);
JarInputStream jis =
new JarInputStream(new ByteArrayInputStream(baos.toByteArray()));
Assert.assertNotNull(jis.getManifest());
jis.close();
}
示例14: extractClassesFromJAR
import java.util.jar.JarInputStream; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private static List<Class<Class>> extractClassesFromJAR(File jar, ClassLoader cl) throws IOException {
List<Class<Class>> classes = new ArrayList<Class<Class>>();
JarInputStream jaris = new JarInputStream(new FileInputStream(jar));
JarEntry ent = null;
while ((ent = jaris.getNextJarEntry()) != null) {
if (ent.getName().toLowerCase().endsWith(".class")) {
try {
Class<Class> cls = (Class<Class>) cl.loadClass(ent.getName().substring(0, ent.getName().length() - 6).replace('/', '.'));
if (JPluginLoader.isPluggableClass(cls)) {
classes.add((Class<Class>)cls);
}
} catch (ClassNotFoundException e) {
String msg = "";
if(lang != null) {
msg = String.format(lang.getProperty("cant_load_class", "Could not load Class \"%s\""), ent.getName());
} else {
msg = "Can't load Class " + ent.getName();
}
if(logger != null) {
logger.logErr(msg, false);
} else {
System.err.println(msg);
}
e.printStackTrace();
}
}
}
jaris.close();
return classes;
}
示例15: 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;
}