本文整理汇总了Java中java.util.jar.JarOutputStream.finish方法的典型用法代码示例。如果您正苦于以下问题:Java JarOutputStream.finish方法的具体用法?Java JarOutputStream.finish怎么用?Java JarOutputStream.finish使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.jar.JarOutputStream
的用法示例。
在下文中一共展示了JarOutputStream.finish方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildFakePluginJar
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
/**
* The minimum requirement to have a "valid" archive plugin is to include
* findbugs.xml, messages.xml and MANIFEST.MF files. The rest of the
* resources are load using the parent ClassLoader (Not requires to be in
* the jar).
* <p>
* Instead of building a file on disk, the result of the stream is kept in
* memory and return as a byte array.
*
* @return
* @throws IOException
* @throws URISyntaxException
*/
private byte[] buildFakePluginJar() throws IOException, URISyntaxException {
ClassLoader cl = getClass().getClassLoader();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
JarOutputStream jar = new JarOutputStream(buffer);
final URL metadata = cl.getResource("metadata");
if (metadata != null) {
final File dir = new File(metadata.toURI());
//Add files to the jar stream
addFilesToStream(cl, jar, dir, "");
}
jar.finish();
jar.close();
return buffer.toByteArray();
}
示例2: toJar
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
public static void toJar(File directory, File jar, Manifest manifest) throws IOException {
if (!directory.isDirectory()) { throw new IllegalArgumentException("expected directory"); }
final JarOutputStream jar_out = new JarOutputStream(new FileOutputStream(jar), manifest);
copyDirectory(directory, directory, jar_out);
jar_out.finish();
jar_out.flush();
jar_out.close();
}
示例3: createJar
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
/**
* Creates a jar file from the resources (including dex file arrays).
*
* @param fileName {@code non-null;} name of the file
* @return whether the creation was successful
*/
private boolean createJar(String fileName) {
/*
* Make or modify the manifest (as appropriate), put the dex
* array into the resources map, and then process the entire
* resources map in a uniform manner.
*/
try {
Manifest manifest = makeManifest();
OutputStream out = openOutput(fileName);
JarOutputStream jarOut = new JarOutputStream(out, manifest);
try {
for (Map.Entry<String, byte[]> e :
outputResources.entrySet()) {
String name = e.getKey();
byte[] contents = e.getValue();
JarEntry entry = new JarEntry(name);
int length = contents.length;
if (args.verbose) {
DxConsole.out.println("writing " + name + "; size " + length + "...");
}
entry.setSize(length);
jarOut.putNextEntry(entry);
jarOut.write(contents);
jarOut.closeEntry();
}
} finally {
jarOut.finish();
jarOut.flush();
closeOutput(out);
}
} catch (Exception ex) {
if (args.debug) {
DxConsole.err.println("\ntrouble writing output:");
ex.printStackTrace(DxConsole.err);
} else {
DxConsole.err.println("\ntrouble writing output: " +
ex.getMessage());
}
return false;
}
return true;
}
示例4: createJar
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
/**
* Creates a jar file from the resources (including dex file arrays).
*
* @param fileName {@code non-null;} name of the file
* @return whether the creation was successful
*/
private static boolean createJar(String fileName) {
/*
* Make or modify the manifest (as appropriate), put the dex
* array into the resources map, and then process the entire
* resources map in a uniform manner.
*/
try {
Manifest manifest = makeManifest();
OutputStream out = openOutput(fileName);
JarOutputStream jarOut = new JarOutputStream(out, manifest);
try {
for (Map.Entry<String, byte[]> e :
outputResources.entrySet()) {
String name = e.getKey();
byte[] contents = e.getValue();
JarEntry entry = new JarEntry(name);
int length = contents.length;
if (args.verbose) {
DxConsole.out.println("writing " + name + "; size " + length + "...");
}
entry.setSize(length);
jarOut.putNextEntry(entry);
jarOut.write(contents);
jarOut.closeEntry();
}
} finally {
jarOut.finish();
jarOut.flush();
closeOutput(out);
}
} catch (Exception ex) {
if (args.debug) {
DxConsole.err.println("\ntrouble writing output:");
ex.printStackTrace(DxConsole.err);
} else {
DxConsole.err.println("\ntrouble writing output: " +
ex.getMessage());
}
return false;
}
return true;
}