本文整理汇总了Java中java.util.jar.JarOutputStream.putNextEntry方法的典型用法代码示例。如果您正苦于以下问题:Java JarOutputStream.putNextEntry方法的具体用法?Java JarOutputStream.putNextEntry怎么用?Java JarOutputStream.putNextEntry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.jar.JarOutputStream
的用法示例。
在下文中一共展示了JarOutputStream.putNextEntry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeIndexJar
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
public void writeIndexJar() throws IOException, XmlPullParserException, LocalRepoKeyStore.InitException {
BufferedOutputStream bo = new BufferedOutputStream(new FileOutputStream(xmlIndexJarUnsigned));
JarOutputStream jo = new JarOutputStream(bo);
JarEntry je = new JarEntry("index.xml");
jo.putNextEntry(je);
new IndexXmlBuilder().build(context, apps, jo);
jo.close();
bo.close();
try {
LocalRepoKeyStore.get(context).signZip(xmlIndexJarUnsigned, xmlIndexJar);
} catch (LocalRepoKeyStore.InitException e) {
throw new IOException("Could not sign index - keystore failed to initialize");
} finally {
attemptToDelete(xmlIndexJarUnsigned);
}
}
示例2: copyJar
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private File copyJar(File file, String manifest) throws IOException {
File ret = File.createTempFile(file.getName(), "2ndcopy", file.getParentFile());
JarFile jar = new JarFile(file);
JarOutputStream os = new JarOutputStream(new FileOutputStream(ret), new Manifest(
new ByteArrayInputStream(manifest.getBytes())
));
Enumeration<JarEntry> en = jar.entries();
while (en.hasMoreElements()) {
JarEntry elem = en.nextElement();
if (elem.getName().equals("META-INF/MANIFEST.MF")) {
continue;
}
os.putNextEntry(elem);
InputStream is = jar.getInputStream(elem);
copyStreams(is, os);
is.close();
}
os.close();
return ret;
}
示例3: writeToJar
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
/**
*
* Writes a resource content to a jar.
*
* @param res
* @param entryName
* @param jarStream
* @param bufferSize
* @return the number of bytes written to the jar file
* @throws Exception
*/
public static int writeToJar(Resource res, String entryName, JarOutputStream jarStream, int bufferSize)
throws IOException {
byte[] readWriteJarBuffer = new byte[bufferSize];
// remove leading / if present.
if (entryName.charAt(0) == '/')
entryName = entryName.substring(1);
jarStream.putNextEntry(new ZipEntry(entryName));
InputStream entryStream = res.getInputStream();
int numberOfBytes;
// read data into the buffer which is later on written to the jar.
while ((numberOfBytes = entryStream.read(readWriteJarBuffer)) != -1) {
jarStream.write(readWriteJarBuffer, 0, numberOfBytes);
}
return numberOfBytes;
}
示例4: updateWebXML
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
/**
* Given the web.xml 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 updateWebXML(JarOutputStream newWarOutputStream, ZipInputStream warInputStream, ZipEntry entry)
throws IOException {
ZipEntry newEntry = new ZipEntry(WEBXML_PATH);
newWarOutputStream.putNextEntry(newEntry);
// can't just pass the stream to the parser, as the parser will close the stream.
InputStream copyInputStream = copyToByteArrayInputStream(warInputStream);
Document doc = parseWebXml(copyInputStream);
updateWebXml(doc);
writeWebXml(doc, newWarOutputStream);
newWarOutputStream.closeEntry();
}
示例5: addFile
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private void addFile(JarOutputStream jos, File file) throws PatchException {
byte[] buf = new byte[8064];
String path = file.getName();
FileInputStream in = null;
try {
in = new FileInputStream(file);
ZipEntry e = new ZipEntry(path);
jos.putNextEntry(e);
int len;
while ((len = in.read(buf)) > 0) {
jos.write(buf, 0, len);
}
jos.closeEntry();
in.close();
} catch (IOException var8) {
throw new PatchException(var8.getMessage(), var8);
}
}
示例6: writeSelfReferencingJarFile
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private static void writeSelfReferencingJarFile(File jarFile, String... entries)
throws IOException {
Manifest manifest = new Manifest();
// Without version, the manifest is silently ignored. Ugh!
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
manifest.getMainAttributes().put(Attributes.Name.CLASS_PATH, jarFile.getName());
Closer closer = Closer.create();
try {
FileOutputStream fileOut = closer.register(new FileOutputStream(jarFile));
JarOutputStream jarOut = closer.register(new JarOutputStream(fileOut));
for (String entry : entries) {
jarOut.putNextEntry(new ZipEntry(entry));
Resources.copy(ClassPathTest.class.getResource(entry), jarOut);
jarOut.closeEntry();
}
} catch (Throwable e) {
throw closer.rethrow(e);
} finally {
closer.close();
}
}
示例7: createAgent
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
public static File createAgent(Class<?> agent, Class<?>... resources) throws IOException {
File jarFile = File.createTempFile("agent", ".jar");
jarFile.deleteOnExit();
Manifest manifest = new Manifest();
Attributes mainAttributes = manifest.getMainAttributes();
mainAttributes.put(Name.MANIFEST_VERSION, "1.0");
mainAttributes.put(new Name("Agent-Class"), agent.getName());
mainAttributes.put(new Name("Can-Retransform-Classes"), "true");
mainAttributes.put(new Name("Can-Redefine-Classes"), "true");
JarOutputStream jos = new JarOutputStream(new FileOutputStream(jarFile), manifest);
jos.putNextEntry(new JarEntry(agent.getName().replace('.', '/') + ".class"));
jos.write(getBytesFromStream(agent.getClassLoader().getResourceAsStream(unqualify(agent))));
jos.closeEntry();
for (Class<?> clazz : resources) {
String name = unqualify(clazz);
jos.putNextEntry(new JarEntry(name));
jos.write(getBytesFromStream(clazz.getClassLoader().getResourceAsStream(name)));
jos.closeEntry();
}
jos.close();
return jarFile;
}
示例8: modifyOutputStream
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
public void modifyOutputStream( JarOutputStream jos, boolean consistentDates )
throws IOException
{
JarEntry entry = new ConsistentJarEntry( resource, consistentDates );
jos.putNextEntry( entry );
IOUtil.copy( new ByteArrayInputStream( data.toByteArray() ), jos );
data.reset();
}
示例9: 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);
}
}
示例10: 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));
}
示例11: 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();
}
示例12: makeJar
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private Path makeJar(Path p) throws IOException {
FileOutputStream fos = new FileOutputStream(new File(p.toString()));
JarOutputStream jos = new JarOutputStream(fos);
ZipEntry ze = new ZipEntry("test.jar.inside");
jos.putNextEntry(ze);
jos.write(("inside the jar!").getBytes());
jos.closeEntry();
jos.close();
return p;
}
示例13: createJAR
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
static File createJAR(File cluster, String moduleName, Class metaInfHandler)
throws IOException {
File xml = new File(new File(new File(cluster, "config"), "Modules"), moduleName + ".xml");
File jar = new File(new File(cluster, "modules"), moduleName + ".jar");
xml.getParentFile().mkdirs();
jar.getParentFile().mkdirs();
Manifest mf = new Manifest();
mf.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
mf.getMainAttributes().putValue("OpenIDE-Module", moduleName.replace('-', '.'));
mf.getMainAttributes().putValue("OpenIDE-Module-Public-Packages", "-");
JarOutputStream os = new JarOutputStream(new FileOutputStream(jar), mf);
if (metaInfHandler != null) {
os.putNextEntry(new JarEntry("META-INF/services/org.netbeans.CLIHandler"));
os.write(metaInfHandler.getName().getBytes());
}
os.close();
FileWriter w = new FileWriter(xml);
w.write(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<!DOCTYPE module PUBLIC \"-//NetBeans//DTD Module Status 1.0//EN\"\n" +
" \"http://www.netbeans.org/dtds/module-status-1_0.dtd\">\n" +
"<module name=\"" + moduleName.replace('-', '.') + "\">\n" +
" <param name=\"autoload\">false</param>\n" +
" <param name=\"eager\">false</param>\n" +
" <param name=\"enabled\">true</param>\n" +
" <param name=\"jar\">modules/" + moduleName + ".jar</param>\n" +
" <param name=\"release\">2</param>\n" +
" <param name=\"reloadable\">false</param>\n" +
" <param name=\"specversion\">3.4.0.1</param>\n" +
"</module>\n");
w.close();
return jar;
}
示例14: modifyOutputStream
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
public void modifyOutputStream( JarOutputStream jos, boolean consistentDates )
throws IOException
{
byte[] data = getTransformedResource();
JarEntry entry = new ConsistentJarEntry( PLUGIN_XML_PATH, consistentDates );
jos.putNextEntry( entry );
IOUtil.copy( data, jos );
mojos.clear();
}
示例15: addClassToJar
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private static void addClassToJar(final Class<?> type, final JarOutputStream jar) throws URISyntaxException, IOException {
final URL resource_url = type.getResource(getResourceName(type));
final File source = new File(resource_url.toURI());
final String entry_name = type.getPackage().getName().replaceAll("\\.", "/") + "/" + source.getName();
final JarEntry entry = new JarEntry(entry_name);
entry.setTime(source.lastModified());
jar.putNextEntry(entry);
FileUtils.copyFile(source, jar);
jar.closeEntry();
}