本文整理汇总了Java中java.util.jar.JarOutputStream类的典型用法代码示例。如果您正苦于以下问题:Java JarOutputStream类的具体用法?Java JarOutputStream怎么用?Java JarOutputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JarOutputStream类属于java.util.jar包,在下文中一共展示了JarOutputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeJarEntry
import java.util.jar.JarOutputStream; //导入依赖的package包/类
private static void writeJarEntry(JarOutputStream jos, String path, File f) throws IOException, FileNotFoundException {
JarEntry je = new JarEntry(path);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream is = new FileInputStream(f);
try {
copyStreams(is, baos);
} finally {
is.close();
}
byte[] data = baos.toByteArray();
je.setSize(data.length);
CRC32 crc = new CRC32();
crc.update(data);
je.setCrc(crc.getValue());
jos.putNextEntry(je);
jos.write(data);
}
示例2: dumpDir
import java.util.jar.JarOutputStream; //导入依赖的package包/类
private static void dumpDir(JarOutputStream jos, String path, File dir) throws IOException {
assertTrue("Dir is dir " + dir, dir.isDirectory());
for (File ch : dir.listFiles()) {
if (ch.isDirectory()) {
dumpDir(jos, path + ch.getName() + "/", ch);
continue;
}
jos.putNextEntry(new JarEntry(path + ch.getName()));
byte[] arr = new byte[4092];
FileInputStream is = new FileInputStream(ch);
for (;;) {
int len = is.read(arr);
if (len == -1) {
break;
}
jos.write(arr, 0, len);
}
jos.closeEntry();
is.close();
}
}
示例3: changeManifest
import java.util.jar.JarOutputStream; //导入依赖的package包/类
protected static File changeManifest(File dir, String newName, File orig, String manifest) throws IOException {
File f = new File(dir, newName);
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;
}
示例4: addJavaSource
import java.util.jar.JarOutputStream; //导入依赖的package包/类
private void addJavaSource( Set<String> resources, JarOutputStream jos, String name, InputStream is,
List<Relocator> relocators, boolean consistentDates )
throws IOException
{
JarEntry jarEntry = new ConsistentJarEntry( name, consistentDates );
jos.putNextEntry( jarEntry );
String sourceContent = IOUtil.toString( new InputStreamReader( is, "UTF-8" ) );
for ( Relocator relocator : relocators )
{
sourceContent = relocator.applyToSourceContent( sourceContent );
}
final Writer writer = new OutputStreamWriter( jos, "UTF-8" );
IOUtil.copy( sourceContent, writer );
writer.flush();
resources.add( name );
}
示例5: 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);
}
示例6: SignedJarBuilder
import java.util.jar.JarOutputStream; //导入依赖的package包/类
/**
* Creates a {@link SignedJarBuilder} with a given output stream, and signing information.
* <p/>If either <code>key</code> or <code>certificate</code> is <code>null</code> then
* the archive will not be signed.
* @param out the {@link OutputStream} where to write the Jar archive.
* @param key the {@link PrivateKey} used to sign the archive, or <code>null</code>.
* @param certificate the {@link X509Certificate} used to sign the archive, or
* <code>null</code>.
* @throws IOException
* @throws NoSuchAlgorithmException
*/
public SignedJarBuilder(OutputStream out, PrivateKey key, X509Certificate certificate)
throws IOException, NoSuchAlgorithmException {
mOutputJar = new JarOutputStream(new BufferedOutputStream(out));
mOutputJar.setLevel(9);
mKey = key;
mCertificate = certificate;
if (mKey != null && mCertificate != null) {
mManifest = new Manifest();
Attributes main = mManifest.getMainAttributes();
main.putValue("Manifest-Version", "1.0");
main.putValue("Created-By", "1.0 (Android)");
mBase64Encoder = new BASE64Encoder();
mMessageDigest = MessageDigest.getInstance(DIGEST_ALGORITHM);
}
}
示例7: 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;
}
示例8: createJarArchive
import java.util.jar.JarOutputStream; //导入依赖的package包/类
protected static void createJarArchive(File archiveFile, File zTobeJared) {
try {
// Open archive file
FileOutputStream stream = new FileOutputStream(archiveFile);
Manifest manifest = new Manifest();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
//Create the jar file
JarOutputStream out = new JarOutputStream(stream, manifest);
//Add the files..
//addFile(zTobeJared, out);
add(zTobeJared, out);
out.close();
stream.close();
System.out.println("Adding completed OK");
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("Error: " + ex.getMessage());
}
}
示例9: createJar
import java.util.jar.JarOutputStream; //导入依赖的package包/类
/**
* Create a fresh JAR file.
* @param jar the file to create
* @param contents keys are JAR entry paths, values are text contents (will be written in UTF-8)
* @param manifest a manifest to store (or null for none)
* @deprecated use {@link JarBuilder} instead
*/
@Deprecated
public static void createJar(File jar, Map<String,String> contents, Manifest manifest) throws IOException {
if (manifest != null) {
manifest.getMainAttributes().putValue("Manifest-Version", "1.0"); // workaround for JDK bug
}
jar.getParentFile().mkdirs();
OutputStream os = new FileOutputStream(jar);
try {
JarOutputStream jos = manifest != null ? new JarOutputStream(os, manifest) : new JarOutputStream(os);
for (Map.Entry<String,String> entry : contents.entrySet()) {
String path = entry.getKey();
byte[] data = entry.getValue().getBytes("UTF-8");
JarEntry je = new JarEntry(path);
je.setSize(data.length);
CRC32 crc = new CRC32();
crc.update(data);
je.setCrc(crc.getValue());
jos.putNextEntry(je);
jos.write(data);
}
jos.close();
} finally {
os.close();
}
}
示例10: addDirectory
import java.util.jar.JarOutputStream; //导入依赖的package包/类
private void addDirectory( Set<String> resources, JarOutputStream jos, String name, boolean consistentDates )
throws IOException
{
if ( name.lastIndexOf( '/' ) > 0 )
{
String parent = name.substring( 0, name.lastIndexOf( '/' ) );
if ( !resources.contains( parent ) )
{
addDirectory( resources, jos, parent, consistentDates );
}
}
// directory entries must end in "/"
JarEntry entry = new ConsistentJarEntry( name + "/", consistentDates );
jos.putNextEntry( entry );
resources.add( name );
}
示例11: generateJar
import java.util.jar.JarOutputStream; //导入依赖的package包/类
protected final File generateJar (String prefix, String[] content, Manifest manifest, Properties props) throws IOException {
File f = createNewJarFile (prefix);
if (props != null) {
manifest.getMainAttributes().putValue("OpenIDE-Module-Localizing-Bundle", "some/fake/prop/name/Bundle.properties");
}
try (JarOutputStream os = new JarOutputStream (new FileOutputStream (f), manifest)) {
if (props != null) {
os.putNextEntry(new JarEntry("some/fake/prop/name/Bundle.properties"));
props.store(os, "# properties for the module");
os.closeEntry();
}
for (int i = 0; i < content.length; i++) {
os.putNextEntry(new JarEntry (content[i]));
os.closeEntry();
}
os.closeEntry ();
}
return f;
}
示例12: unpack
import java.util.jar.JarOutputStream; //导入依赖的package包/类
/**
* Takes an input File containing the pack file, and generates a JarOutputStream.
* <p>
* Does not close its output. (The output can accumulate more elements.)
* @param in a File.
* @param out a JarOutputStream.
* @exception IOException if an error is encountered.
*/
public synchronized void unpack(File in, JarOutputStream out) throws IOException {
if (in == null) {
throw new NullPointerException("null input");
}
if (out == null) {
throw new NullPointerException("null output");
}
// Use the stream-based implementation.
// %%% Reconsider if native unpacker learns to memory-map the file.
try (FileInputStream instr = new FileInputStream(in)) {
unpack(instr, out);
}
if (props.getBoolean(Utils.UNPACK_REMOVE_PACKFILE)) {
in.delete();
}
}
示例13: 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);
}
}
示例14: 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();
}
}
示例15: 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();
}