本文整理汇总了Java中java.util.jar.JarOutputStream.closeEntry方法的典型用法代码示例。如果您正苦于以下问题:Java JarOutputStream.closeEntry方法的具体用法?Java JarOutputStream.closeEntry怎么用?Java JarOutputStream.closeEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.jar.JarOutputStream
的用法示例。
在下文中一共展示了JarOutputStream.closeEntry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copyJarFile
import java.util.jar.JarOutputStream; //导入方法依赖的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: setUp
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
clearWorkDir();
jar = new File(getWorkDir(), "x.jar");
JarOutputStream os = new JarOutputStream(
new FileOutputStream(jar)
);
os.putNextEntry(new ZipEntry("fldr/plain.txt"));
os.write("Ahoj\n".getBytes());
os.closeEntry();
os.close();
JarClassLoader registerJarSource = new JarClassLoader(
Collections.nCopies(1, jar),
new ClassLoader[] { getClass().getClassLoader() }
);
assertNotNull("Registered", registerJarSource);
}
示例3: pack
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private static void pack(
JarOutputStream out,
FileObject f,
FileObject root) throws IOException {
if (f.isFolder()) {
for (FileObject c : f.getChildren()) {
pack(out, c, root);
}
} else {
String path = FileUtil.getRelativePath(root, f);
if (path.isEmpty()) {
path = f.getNameExt();
}
out.putNextEntry(new ZipEntry(path));
FileUtil.copy(f.getInputStream(), out);
out.closeEntry();
}
}
示例4: createJarFile
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
static LocalResource createJarFile(FileContext files, Path p, int len,
Random r, LocalResourceVisibility vis) throws IOException,
URISyntaxException {
byte[] bytes = new byte[len];
r.nextBytes(bytes);
File archiveFile = new File(p.toUri().getPath() + ".jar");
archiveFile.createNewFile();
JarOutputStream out = new JarOutputStream(
new FileOutputStream(archiveFile));
out.putNextEntry(new JarEntry(p.getName()));
out.write(bytes);
out.closeEntry();
out.close();
LocalResource ret = recordFactory.newRecordInstance(LocalResource.class);
ret.setResource(ConverterUtils.getYarnUrlFromPath(new Path(p.toString()
+ ".jar")));
ret.setSize(len);
ret.setType(LocalResourceType.ARCHIVE);
ret.setVisibility(vis);
ret.setTimestamp(files.getFileStatus(new Path(p.toString() + ".jar"))
.getModificationTime());
return ret;
}
示例5: setUp
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
clearWorkDir();
f = new File(getWorkDir(), "m.jar");
Manifest man = new Manifest();
Attributes attr = man.getMainAttributes();
attr.putValue("OpenIDE-Module", "m.test");
attr.putValue("OpenIDE-Module-Public-Packages", "-");
attr.putValue("Manifest-Version", "1.0");
JarOutputStream os = new JarOutputStream(new FileOutputStream(f), man);
os.putNextEntry(new JarEntry("META-INF/namedservices/ui/javax.swing.JComponent"));
os.write("javax.swing.JButton\n".getBytes("UTF-8"));
os.closeEntry();
os.close();
FileObject fo = FileUtil.createData(FileUtil.getConfigRoot(), "ui/ch/my/javax-swing-JPanel.instance");
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:RecognizeInstanceObjectsOnModuleEnablementTest.java
示例6: writeJarFile
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private File writeJarFile(String name, JEntry... entries) throws IOException {
File f = new File(getWorkDir(), name);
JarOutputStream jarOut = new JarOutputStream(new FileOutputStream(f));
try {
for (JEntry entry : entries) {
JarEntry jarEntry = new JarEntry(entry.name);
jarOut.putNextEntry(jarEntry);
jarOut.write(entry.content.getBytes("UTF-8"));
jarOut.closeEntry();
}
}
finally {
jarOut.close();
}
return f;
}
示例7: changeManifest
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private File changeManifest(File orig, String manifest) throws IOException {
File f = new File(getWorkDir(), orig.getName());
Manifest mf = new Manifest(new ByteArrayInputStream(manifest.getBytes("utf-8")));
mf.getMainAttributes().putValue("Manifest-Version", "1.0");
JarOutputStream os = new JarOutputStream(new FileOutputStream(f), mf);
JarFile jf = new JarFile(orig);
Enumeration<JarEntry> en = jf.entries();
InputStream is;
while (en.hasMoreElements()) {
JarEntry e = en.nextElement();
if (e.getName().equals("META-INF/MANIFEST.MF")) {
continue;
}
os.putNextEntry(e);
is = jf.getInputStream(e);
FileUtil.copy(is, os);
is.close();
os.closeEntry();
}
os.close();
return f;
}
示例8: makeTestJar
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
/**
* Construct a jar with two files in it in our
* test dir.
*/
private void makeTestJar() throws IOException {
File jarFile = new File(TEST_ROOT_DIR, TEST_JAR_NAME);
JarOutputStream jstream =
new JarOutputStream(new FileOutputStream(jarFile));
jstream.putNextEntry(new ZipEntry("foobar.txt"));
jstream.closeEntry();
jstream.putNextEntry(new ZipEntry("foobaz.txt"));
jstream.closeEntry();
jstream.close();
}
示例9: updateManifest
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
/**
* Given the MANIFEST.MF from the war file, update the file and write it to the new war file.
*
* @param newWarOutputStream
* new war file
* @param warInputStream
* existing war file
* @param entry
* web.xml entry
* @throws IOException
*/
protected void updateManifest(JarOutputStream newWarOutputStream, ZipInputStream warInputStream, ZipEntry entry)
throws IOException {
ZipEntry newEntry = new ZipEntry(MANIFEST_PATH);
newWarOutputStream.putNextEntry(newEntry);
Manifest manifest = new Manifest(warInputStream);
updateClasspath(manifest);
manifest.write(newWarOutputStream);
newWarOutputStream.closeEntry();
}
示例10: makeTestJar
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private File makeTestJar() throws IOException {
File jarFile = new File(testDir, "test.jar");
JarOutputStream out = new JarOutputStream(new FileOutputStream(jarFile));
ZipEntry entry = new ZipEntry("resource.txt");
out.putNextEntry(entry);
out.write("hello".getBytes());
out.closeEntry();
out.close();
return jarFile;
}
示例11: add
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private static void add(Path path, Path source, JarOutputStream target) {
try {
String name = path.toString().replace(File.separatorChar, '/');
JarEntry entry = new JarEntry(name);
entry.setTime(source.toFile().lastModified());
target.putNextEntry(entry);
Files.copy(source, target);
target.closeEntry();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例12: writeJarredFile
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private static void writeJarredFile(JarOutputStream jos, String file, String suffix, byte[] bytes) {
String fileName = file.replace(".", "/") + "." + suffix;
JarEntry ze = new JarEntry(fileName);
try {
ze.setSize(bytes.length);
jos.putNextEntry(ze);
jos.write(bytes);
jos.closeEntry();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例13: addClassToJar
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
protected static void addClassToJar(final Class<?> type, final JarOutputStream jar) throws IOException {
final String resource_path = getResourcePath(type);
final JarEntry entry = new JarEntry(resource_path);
final InputStream resource_stream = getResurceInputStream(type, resource_path);
jar.putNextEntry(entry);
IOUtils.copy(resource_stream, jar);
jar.closeEntry();
}
示例14: copyFile
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private static void copyFile(File base, final String file, final JarOutputStream jar) throws IOException {
System.out.println(file);
final JarEntry entry = new JarEntry(file);
jar.putNextEntry(entry);
IOUtils.copy(new BufferedInputStream(new FileInputStream(new File(base, file))), jar);
jar.closeEntry();
}
示例15: addClassFilesFromDir
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
/**
* Searches through a directory and its children for .class
* files to add to a jar.
*
* @param dir - The root directory to scan with this algorithm.
* @param jstream - The JarOutputStream to write .class files to.
*/
private void addClassFilesFromDir(File dir, JarOutputStream jstream)
throws IOException {
LOG.debug("Scanning for .class files in directory: " + dir);
List<File> dirEntries = FileListing.getFileListing(dir);
String baseDirName = dir.getAbsolutePath();
if (!baseDirName.endsWith(File.separator)) {
baseDirName = baseDirName + File.separator;
}
// For each input class file, create a zipfile entry for it,
// read the file into a buffer, and write it to the jar file.
for (File entry : dirEntries) {
if (!entry.isDirectory()) {
// Chomp off the portion of the full path that is shared
// with the base directory where class files were put;
// we only record the subdir parts in the zip entry.
String fullPath = entry.getAbsolutePath();
String chompedPath = fullPath.substring(baseDirName.length());
boolean include = chompedPath.endsWith(".class")
&& sources.contains(
chompedPath.substring(0, chompedPath.length() - ".class".length())
+ ".java");
if (include) {
// include this file.
if (Shell.WINDOWS) {
// In Windows OS, elements in jar files still need to have a path
// separator of '/' rather than the default File.separator which is '\'
chompedPath = chompedPath.replace(File.separator, "/");
}
LOG.debug("Got classfile: " + entry.getPath() + " -> " + chompedPath);
ZipEntry ze = new ZipEntry(chompedPath);
jstream.putNextEntry(ze);
copyFileToStream(entry, jstream);
jstream.closeEntry();
}
}
}
}