本文整理汇总了Java中java.util.jar.JarOutputStream.write方法的典型用法代码示例。如果您正苦于以下问题:Java JarOutputStream.write方法的具体用法?Java JarOutputStream.write怎么用?Java JarOutputStream.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.jar.JarOutputStream
的用法示例。
在下文中一共展示了JarOutputStream.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeClassLoaderTestJar
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private File makeClassLoaderTestJar(String... clsNames) throws IOException {
File jarFile = new File(TEST_ROOT_DIR, TEST_JAR_2_NAME);
JarOutputStream jstream =
new JarOutputStream(new FileOutputStream(jarFile));
for (String clsName: clsNames) {
String name = clsName.replace('.', '/') + ".class";
InputStream entryInputStream = this.getClass().getResourceAsStream(
"/" + name);
ZipEntry entry = new ZipEntry(name);
jstream.putNextEntry(entry);
BufferedInputStream bufInputStream = new BufferedInputStream(
entryInputStream, 2048);
int count;
byte[] data = new byte[2048];
while ((count = bufInputStream.read(data, 0, 2048)) != -1) {
jstream.write(data, 0, count);
}
jstream.closeEntry();
}
jstream.close();
return jarFile;
}
示例2: 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;
}
示例3: writeEntry
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private static void
writeEntry(
JarOutputStream jos,
JarEntry entry,
InputStream data )
throws IOException
{
jos.putNextEntry(entry);
byte[] newBytes = new byte[4096];
int size = data.read(newBytes);
while (size != -1){
jos.write(newBytes, 0, size);
size = data.read(newBytes);
}
}
示例4: testHandleSpaceInPathAsProducedByEclipse
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
public void testHandleSpaceInPathAsProducedByEclipse() throws Exception {
File d = new File(getWorkDir(), "space in path");
d.mkdirs();
File f = new File(d, "x.jar");
JarOutputStream os = new JarOutputStream(new FileOutputStream(f));
os.putNextEntry(new JarEntry("test.txt"));
os.write(10);
os.close();
URL u = new URL("jar:" + f.toURL() + "!/test.txt");
DataInputStream is = new DataInputStream(u.openStream());
byte[] arr = new byte[100];
is.readFully(arr, 0, 1);
assertEquals("One byte", 10, arr[0]);
is.close();
}
示例5: 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
}
示例6: processEntry
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private static void processEntry(JobManager jobManager, JarFile jarFile, JarEntry jarEntry, JarOutputStream jarOutputStream, Map<String, String> replacements) {
if (jarEntry.getName().equals("META-INF/MANIFEST.MF"))
return;
try (DataInputStream inputStream = new DataInputStream(new BufferedInputStream(jarFile.getInputStream(jarEntry)))) {
if (!jarEntry.getName().endsWith(".class")) {
jarOutputStream.putNextEntry(jarEntry);
int count;
byte[] buffer = new byte[1024];
while ((count = inputStream.read(buffer)) > 0)
jarOutputStream.write(buffer, 0, count);
jarOutputStream.closeEntry();
} else
jobManager.scheduleJob(new InjectionJob(jarEntry.getName(), inputStream, replacements));
} catch (IOException e) {
e.printStackTrace();
}
}
示例7: 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
示例8: 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;
}
示例9: addDirectory
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
protected void addDirectory(JarOutputStream jos, File directory, String prefix) throws PatchException {
if (directory != null && directory.exists()) {
Collection files = FileUtils.listFiles(directory, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
byte[] buf = new byte[8064];
Iterator var6 = files.iterator();
while (true) {
File file;
do {
if (!var6.hasNext()) {
return;
}
file = (File) var6.next();
} while (file.isDirectory());
String path = prefix + File.separator + PathUtils.toRelative(directory, file.getAbsolutePath());
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 var12) {
throw new PatchException(var12.getMessage(), var12);
}
}
}
}
示例10: add
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
/**
* Adds the class file bytes for a given class to a JAR stream.
*/
static void add(JarOutputStream jar, Class<?> c) throws IOException {
String name = c.getName();
String classAsPath = name.replace('.', '/') + ".class";
jar.putNextEntry(new JarEntry(classAsPath));
InputStream stream = c.getClassLoader().getResourceAsStream(classAsPath);
int nRead;
byte[] buf = new byte[1024];
while ((nRead = stream.read(buf, 0, buf.length)) != -1) {
jar.write(buf, 0, nRead);
}
jar.closeEntry();
}
示例11: loadInstrumentationAgent
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private static void loadInstrumentationAgent(String myName, byte[] buf) throws Exception {
// Create agent jar file on the fly
Manifest m = new Manifest();
m.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
m.getMainAttributes().put(new Attributes.Name("Agent-Class"), myName);
m.getMainAttributes().put(new Attributes.Name("Can-Redefine-Classes"), "true");
File jarFile = File.createTempFile("agent", ".jar");
jarFile.deleteOnExit();
JarOutputStream jar = new JarOutputStream(new FileOutputStream(jarFile), m);
jar.putNextEntry(new JarEntry(myName.replace('.', '/') + ".class"));
jar.write(buf);
jar.close();
String pid = Long.toString(ProcessTools.getProcessId());
System.out.println("Our pid is = " + pid);
VirtualMachine vm = VirtualMachine.attach(pid);
vm.loadAgent(jarFile.getAbsolutePath());
}
示例12: addFilesToStream
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private void addFilesToStream(final ClassLoader cl, final JarOutputStream jar, final File dir,
final String path) throws IOException {
for (final File nextFile : dir.listFiles()) {
if (nextFile.isFile()) {
final String resource = path + nextFile.getName();
jar.putNextEntry(new ZipEntry(resource));
jar.write(IOUtils.toByteArray(cl.getResourceAsStream("metadata/" + resource)));
} else {
addFilesToStream(cl, jar, nextFile, path + nextFile.getName() + "/");
}
}
}
示例13: 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;
}
示例14: createJarFile
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private URL createJarFile () throws IOException {
File workDir = FileUtil.normalizeFile(this.getWorkDir());
File jarFile = new File(workDir,JAR_FILE);
JarOutputStream out = new JarOutputStream ( new FileOutputStream (jarFile));
ZipEntry entry = new ZipEntry (RESOURCE);
out.putNextEntry(entry);
out.write (RESOURCE.getBytes());
out.close();
return Utilities.toURI(jarFile).toURL();
}
示例15: write
import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private void write(JarOutputStream jarOut, String entry) throws IOException {
jarOut.putNextEntry(new ZipEntry(entry));
if (getClass().getResource(entry) != null) {
jarOut.write(toByteArray(getClass().getResourceAsStream(entry)));
}
jarOut.closeEntry();
}