本文整理汇总了Java中java.util.jar.JarOutputStream.flush方法的典型用法代码示例。如果您正苦于以下问题:Java JarOutputStream.flush方法的具体用法?Java JarOutputStream.flush怎么用?Java JarOutputStream.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.jar.JarOutputStream
的用法示例。
在下文中一共展示了JarOutputStream.flush方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPrescan
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
public void testPrescan() throws Exception {
File j = new File(getWorkDir(), "x.jar");
try (OutputStream os = new FileOutputStream(j)) {
JarOutputStream jos = new JarOutputStream(os, new Manifest(new ByteArrayInputStream("Manifest-Version: 1.0\nBundle-SymbolicName: org.eclipse.mylyn.bugzilla.core;singleton:=true\nExport-Package: org.eclipse.mylyn.internal.bugzilla.core;x-friends:=\"org.eclipse.mylyn.bugzilla.ide,org.eclipse.mylyn.bugzilla.ui\",org.eclipse.mylyn.internal.bugzilla.core.history;x-friends:=\"org.eclipse.mylyn.bugzilla.ide,org.eclipse.mylyn.bugzilla.ui\",org.eclipse.mylyn.internal.bugzilla.core.service;x-internal:=true\n".getBytes())));
jos.flush();
jos.close();
}
Info info = new MakeOSGi.Info();
JarFile jf = new JarFile(j);
try {
assertEquals("org.eclipse.mylyn.bugzilla.core", MakeOSGi.prescan(jf, info, new Task() {}));
} finally {
jf.close();
}
assertEquals("[org.eclipse.mylyn.internal.bugzilla.core, org.eclipse.mylyn.internal.bugzilla.core.history, org.eclipse.mylyn.internal.bugzilla.core.service]", info.exportedPackages.toString());
}
示例2: createRealJarFile
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
public void createRealJarFile(File f) throws Exception {
OutputStream os = new FileOutputStream(f);
try {
JarOutputStream jos = new JarOutputStream(os);
// jos.setMethod(ZipEntry.STORED);
JarEntry entry = new JarEntry("foo.txt");
// entry.setSize(0L);
// entry.setTime(System.currentTimeMillis());
// entry.setCrc(new CRC32().getValue());
jos.putNextEntry(entry);
jos.flush();
jos.close();
} finally {
os.close();
}
}
示例3: createTempJar
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
/**
* 创建临时文件*.jar
*
* @param root
* @return
* @throws IOException
*/
public static File createTempJar(String root) throws IOException {
if (!new File(root).exists()) {
return null;
}
final File jarFile = File.createTempFile("EJob-", ".jar", new File(System
.getProperty("java.io.tmpdir")));
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
jarFile.delete();
}
});
JarOutputStream out = new JarOutputStream(new FileOutputStream(jarFile));
createTempJarInner(out, new File(root), "");
out.flush();
out.close();
return jarFile;
}
示例4: testJarMapping
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
/**
* Check that jar: URLs are correctly mapped back into JarFileSystem resources.
* @see "#39190"
*/
public void testJarMapping() throws Exception {
clearWorkDir();
File workdir = getWorkDir();
File jar = new File(workdir, "test.jar");
String textPath = "x.txt";
OutputStream os = new FileOutputStream(jar);
try {
JarOutputStream jos = new JarOutputStream(os);
jos.setMethod(ZipEntry.STORED);
JarEntry entry = new JarEntry(textPath);
entry.setSize(0L);
entry.setTime(System.currentTimeMillis());
entry.setCrc(new CRC32().getValue());
jos.putNextEntry(entry);
jos.flush();
jos.close();
} finally {
os.close();
}
assertTrue("JAR was created", jar.isFile());
assertTrue("JAR is not empty", jar.length() > 0L);
JarFileSystem jfs = new JarFileSystem();
jfs.setJarFile(jar);
Repository.getDefault().addFileSystem(jfs);
FileObject rootFO = jfs.getRoot();
FileObject textFO = jfs.findResource(textPath);
assertNotNull("JAR contains a/b.txt", textFO);
String rootS = "jar:" + BaseUtilities.toURI(jar) + "!/";
URL rootU = new URL(rootS);
URL textU = new URL(rootS + textPath);
assertEquals("correct FO -> URL for root", rootU, URLMapper.findURL(rootFO, URLMapper.EXTERNAL));
assertEquals("correct FO -> URL for " + textPath, textU, URLMapper.findURL(textFO, URLMapper.EXTERNAL));
assertTrue("correct URL -> FO for root", Arrays.asList(URLMapper.findFileObjects(rootU)).contains(rootFO));
assertTrue("correct URL -> FO for " + textPath, Arrays.asList(URLMapper.findFileObjects(textU)).contains(textFO));
}
示例5: reconstructBootstrapJar
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private static void reconstructBootstrapJar() throws IOException {
final Manifest manifest = new Manifest();
final Attributes main_attributes = manifest.getMainAttributes();
main_attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
main_attributes.put(Attributes.Name.MAIN_CLASS, Bootstrap.class.getName());
main_attributes.put(Attributes.Name.CLASS_PATH, ".:*");
main_attributes.put(PREMAIN_CLASS, Bootstrap.class.getName());
FileUtils.forceMkdir(LOCAL_BOOTSTRAP_HOME);
final JarOutputStream jar_stream = new JarOutputStream(new FileOutputStream(BOOTSTRAP_JAR), manifest);
try {
addClassToJar(MavenDependencyResolver.class, jar_stream);
addClassToJar(MavenDependencyResolver.FileCollector.class, jar_stream);
addClassToJar(MavenDependencyResolver.DependencyNodeCollector.class, jar_stream);
addClassToJar(MavenDependencyResolver.ServiceLocatorErrorHandler.class, jar_stream);
addClassToJar(Bootstrap.class, jar_stream);
addClassToJar(BootstrapConfiguration.class, jar_stream);
addClassToJar(Duration.class, jar_stream);
addClassToJar(URLUtils.class, jar_stream);
addClassToJar(FileDeletionHook.class, jar_stream);
}
finally {
jar_stream.flush();
jar_stream.close();
}
}
示例6: 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();
}
示例7: 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;
}
示例8: createJar
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private void createJar(Manifest mf) throws Exception {
mf.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
JarOutputStream out = new JarOutputStream(storage.getOutputStream(), mf);
out.flush();
out.close();
}
示例9: 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;
}