本文整理汇总了Java中java.util.jar.Pack200.newPacker方法的典型用法代码示例。如果您正苦于以下问题:Java Pack200.newPacker方法的具体用法?Java Pack200.newPacker怎么用?Java Pack200.newPacker使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.jar.Pack200
的用法示例。
在下文中一共展示了Pack200.newPacker方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.util.jar.Pack200; //导入方法依赖的package包/类
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
if (args.length != 2) {
System.err.println("command unput-directory output-directory");
System.exit(1);
}
Packer packer = Pack200.newPacker();
Map p = packer.properties();
p.put(Packer.EFFORT, "9");
p.put(Packer.SEGMENT_LIMIT, "-1");
p.put(Packer.KEEP_FILE_ORDER, Packer.FALSE);
p.put(Packer.MODIFICATION_TIME, Packer.LATEST);
p.put(Packer.DEFLATE_HINT, Packer.FALSE);
p.put(Packer.CODE_ATTRIBUTE_PFX + "LineNumberTable", Packer.STRIP);
p.put(Packer.UNKNOWN_ATTRIBUTE, Packer.ERROR);
File inputDirectory = new File(args[0]);
File outputDirectory = new File(args[1]);
pack(packer, inputDirectory, outputDirectory);
}
示例2: pack
import java.util.jar.Pack200; //导入方法依赖的package包/类
static void pack(JarFile jarFile, File packFile) throws IOException {
Pack200.Packer packer = Pack200.newPacker();
Map<String, String> p = packer.properties();
// Take the time optimization vs. space
p.put(packer.EFFORT, "1"); // CAUTION: do not use 0.
// Make the memory consumption as effective as possible
p.put(packer.SEGMENT_LIMIT, "10000");
// ignore all JAR deflation requests to save time
p.put(packer.DEFLATE_HINT, packer.FALSE);
// save the file ordering of the original JAR
p.put(packer.KEEP_FILE_ORDER, packer.TRUE);
FileOutputStream fos = null;
try {
// Write out to a jtreg scratch area
fos = new FileOutputStream(packFile);
// Call the packer
packer.pack(jarFile, fos);
} finally {
close(fos);
}
}
示例3: properties
import java.util.jar.Pack200; //导入方法依赖的package包/类
private Map<String, String> properties() {
// Create the Packer object
Pack200.Packer packer = Pack200.newPacker();
Map<String, String> p = packer.properties();
p.put(Pack200.Packer.EFFORT, "9"); // default is "5"
p.put(Pack200.Packer.SEGMENT_LIMIT, "-1");
p.put(Pack200.Packer.KEEP_FILE_ORDER, Pack200.Packer.FALSE);
p.put(Pack200.Packer.MODIFICATION_TIME, Pack200.Packer.LATEST);
p.put(Pack200.Packer.DEFLATE_HINT, Pack200.Packer.TRUE); // compression enabled
// p.put("com.sun.java.util.jar.pack.verbose", Pack200.Packer.FALSE);
// p.put("com.sun.java.util.jar.pack.nolog", Pack200.Packer.TRUE);
String[] attributes = { UNKNOWN_ATTRIBUTE, CLASS_ATTRIBUTE_PFX, FIELD_ATTRIBUTE_PFX, METHOD_ATTRIBUTE_PFX,
CODE_ATTRIBUTE_PFX, };
String[] stripCodeAttributes = { "SourceFile", "LineNumberTable", "LocalVariableTable", "Deprecated" };
for (String attribute : attributes) {
for (String attributeName : stripCodeAttributes) {
p.put(attribute + attributeName, Pack200.Packer.STRIP);
}
}
p.put(Pack200.Packer.UNKNOWN_ATTRIBUTE, Pack200.Packer.STRIP);
return p;
}
示例4: main
import java.util.jar.Pack200; //导入方法依赖的package包/类
public static void main(String... args) throws IOException {
File sdkHome = Utils.JavaSDK;
File testJar = new File("test.jar");
Utils.jar("cvf", testJar.getName(), Utils.TEST_CLS_DIR.getAbsolutePath());
JarFile jarFile = new JarFile(testJar);
File packFile = new File("foo.pack");
Pack200.Packer packer = Pack200.newPacker();
Map<String, String> p = packer.properties();
// Take the time optimization vs. space
p.put(packer.EFFORT, "1"); // CAUTION: do not use 0.
// Make the memory consumption as effective as possible
p.put(packer.SEGMENT_LIMIT, "10000");
// ignore all JAR deflation requests to save time
p.put(packer.DEFLATE_HINT, packer.FALSE);
// save the file ordering of the original JAR
p.put(packer.KEEP_FILE_ORDER, packer.TRUE);
// strip the StackMapTables
p.put(packer.CODE_ATTRIBUTE_PFX + "StackMapTable", packer.STRIP);
FileOutputStream fos = null;
try {
// Write out to a jtreg scratch area
fos = new FileOutputStream(packFile);
// Call the packer
packer.pack(jarFile, fos);
} finally {
Utils.close(fos);
Utils.close(jarFile);
}
Utils.cleanup();
}
示例5: verifyPack
import java.util.jar.Pack200; //导入方法依赖的package包/类
static void verifyPack(String filename, int expected_major, int expected_minor) {
File jarFileName = new File("test.jar");
jarFileName.delete();
String jargs[] = {
"cvf",
jarFileName.getName(),
filename
};
Utils.jar(jargs);
JarFile jfin = null;
try {
jfin = new JarFile(jarFileName);
Packer packer = Pack200.newPacker();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
packer.pack(jfin, baos);
baos.flush();
baos.close();
byte[] buf = baos.toByteArray();
int minor = buf[4] & 0x000000ff;
int major = buf[5] & 0x000000ff;
if (major != expected_major || minor != expected_minor) {
String msg =
String.format("test fails: expected:%d.%d but got %d.%d\n",
expected_major, expected_minor,
major, minor);
throw new Error(msg);
}
System.out.println(filename + ": OK");
} catch (IOException ioe) {
throw new RuntimeException(ioe.getMessage());
} finally {
Utils.close((Closeable) jfin);
}
}
示例6: main
import java.util.jar.Pack200; //导入方法依赖的package包/类
public static void main(String... args) throws IOException {
File sdkHome = Utils.JavaSDK;
File testJar = new File(new File(sdkHome, "lib"), "tools.jar");
JarFile jarFile = new JarFile(testJar);
File packFile = new File("foo.pack");
Pack200.Packer packer = Pack200.newPacker();
Map<String, String> p = packer.properties();
// Take the time optimization vs. space
p.put(packer.EFFORT, "1"); // CAUTION: do not use 0.
// Make the memory consumption as effective as possible
p.put(packer.SEGMENT_LIMIT, "10000");
// ignore all JAR deflation requests to save time
p.put(packer.DEFLATE_HINT, packer.FALSE);
// save the file ordering of the original JAR
p.put(packer.KEEP_FILE_ORDER, packer.TRUE);
// strip the StackMapTables
p.put(packer.CODE_ATTRIBUTE_PFX + "StackMapTable", packer.STRIP);
FileOutputStream fos = null;
try {
// Write out to a jtreg scratch area
fos = new FileOutputStream(packFile);
// Call the packer
packer.pack(jarFile, fos);
} finally {
Utils.close(fos);
Utils.close(jarFile);
}
Utils.cleanup();
}
示例7: setupPackGzFile
import java.util.jar.Pack200; //导入方法依赖的package包/类
private void setupPackGzFile(String fileName, String version) throws IOException {
File downloadDir = downloadServer.getDir();
File orig = new File(downloadDir, fileName + ".jar");
orig.deleteOnExit();
Manifest manifest = new Manifest();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, version);
JarOutputStream target = new JarOutputStream(new FileOutputStream(orig), manifest);
target.close();
File pack = new File(downloadDir, fileName + ".jar.pack");
pack.deleteOnExit();
JarFile jarFile = new JarFile(orig.getAbsolutePath());
FileOutputStream fos = new FileOutputStream(pack);
Pack200.Packer p = Pack200.newPacker();
p.pack(jarFile, fos);
fos.close();
File packgz = new File(downloadDir, fileName + ".jar.pack.gz");
packgz.deleteOnExit();
FileOutputStream gzfos = new FileOutputStream(packgz);
GZIPOutputStream gos = new GZIPOutputStream(gzfos);
gos.write(Files.readAllBytes(pack.toPath()));
gos.finish();
gos.close();
}
示例8: pack
import java.util.jar.Pack200; //导入方法依赖的package包/类
@Override
public void pack( File source, File destination, Map<String, String> props, boolean gzip )
throws IOException
{
JarFile jar = null;
OutputStream out = null;
try
{
out = new FileOutputStream( destination );
if ( gzip )
{
out = new GZIPOutputStream( out )
{
{
def.setLevel( Deflater.BEST_COMPRESSION );
}
};
}
out = new BufferedOutputStream( out );
jar = new JarFile( source, false );
Pack200.Packer packer = Pack200.newPacker();
packer.properties().putAll( props );
packer.pack( jar, out );
}
finally
{
IOUtil.close( out );
if ( jar != null )
{
jar.close();
}
}
}
示例9: jar2pack
import java.util.jar.Pack200; //导入方法依赖的package包/类
public static void jar2pack(InputStream is,OutputStream os, boolean closeIS, boolean closeOS) throws IOException {
// Create the Packer object
Packer packer = Pack200.newPacker();
// Initialize the state by setting the desired properties
Map p = packer.properties();
// take more time choosing codings for better compression
p.put(Packer.EFFORT, "7"); // default is "5"
// use largest-possible archive segments (>10% better compression).
p.put(Packer.SEGMENT_LIMIT, "-1");
// reorder files for better compression.
p.put(Packer.KEEP_FILE_ORDER, Packer.FALSE);
// smear modification times to a single value.
p.put(Packer.MODIFICATION_TIME, Packer.LATEST);
// ignore all JAR deflation requests,
// transmitting a single request to use "store" mode.
p.put(Packer.DEFLATE_HINT, Packer.FALSE);
// discard debug attributes
p.put(Packer.CODE_ATTRIBUTE_PFX+"LineNumberTable", Packer.STRIP);
// throw an error if an attribute is unrecognized
p.put(Packer.UNKNOWN_ATTRIBUTE, Packer.ERROR);
JarInputStream jis=null;
os=new GZIPOutputStream(os);
PrintStream err = System.err;
try{
System.setErr(new PrintStream(new DevNullOutputStream()));
jis = new JarInputStream(is);
packer.pack(jis, os);
}
finally{
System.setErr(err);
if(closeIS)Util.closeEL(jis);
if(closeOS)Util.closeEL(os);
}
}
示例10: jar2pack
import java.util.jar.Pack200; //导入方法依赖的package包/类
public static void jar2pack(InputStream is,OutputStream os, boolean closeIS, boolean closeOS) throws IOException {
// Create the Packer object
Packer packer = Pack200.newPacker();
// Initialize the state by setting the desired properties
Map p = packer.properties();
// take more time choosing codings for better compression
p.put(Packer.EFFORT, "7"); // default is "5"
// use largest-possible archive segments (>10% better compression).
p.put(Packer.SEGMENT_LIMIT, "-1");
// reorder files for better compression.
p.put(Packer.KEEP_FILE_ORDER, Packer.FALSE);
// smear modification times to a single value.
p.put(Packer.MODIFICATION_TIME, Packer.LATEST);
// ignore all JAR deflation requests,
// transmitting a single request to use "store" mode.
p.put(Packer.DEFLATE_HINT, Packer.FALSE);
// discard debug attributes
p.put(Packer.CODE_ATTRIBUTE_PFX+"LineNumberTable", Packer.STRIP);
// throw an error if an attribute is unrecognized
p.put(Packer.UNKNOWN_ATTRIBUTE, Packer.ERROR);
JarInputStream jis=null;
os=new GZIPOutputStream(os);
PrintStream err = System.err;
try{
System.setErr(new PrintStream(DevNullOutputStream.DEV_NULL_OUTPUT_STREAM));
jis = new JarInputStream(is);
packer.pack(jis, os);
}
finally{
System.setErr(err);
if(closeIS)IOUtil.closeEL(jis);
if(closeOS)IOUtil.closeEL(os);
}
}
示例11: main
import java.util.jar.Pack200; //导入方法依赖的package包/类
public static void main(String... args) throws IOException {
File sdkHome = Utils.JavaSDK;
File testJar = new File(new File(sdkHome, "lib"), "tools.jar");
JarFile jarFile = new JarFile(testJar);
File packFile = new File("foo.pack");
Pack200.Packer packer = Pack200.newPacker();
Map<String, String> p = packer.properties();
// Take the time optimization vs. space
p.put(packer.EFFORT, "1"); // CAUTION: do not use 0.
// Make the memory consumption as effective as possible
p.put(packer.SEGMENT_LIMIT, "10000");
// ignore all JAR deflation requests to save time
p.put(packer.DEFLATE_HINT, packer.FALSE);
// save the file ordering of the original JAR
p.put(packer.KEEP_FILE_ORDER, packer.TRUE);
// strip the StackMapTables
p.put(packer.CODE_ATTRIBUTE_PFX + "StackMapTable", packer.STRIP);
FileOutputStream fos = null;
try {
// Write out to a jtreg scratch area
fos = new FileOutputStream(packFile);
// Call the packer
packer.pack(jarFile, fos);
} finally {
Utils.close(fos);
Utils.close(jarFile);
}
}
示例12: compressJar
import java.util.jar.Pack200; //导入方法依赖的package包/类
public static final void compressJar(InputStream is, JarEntry entry, String output) throws IOException {
JarInputStream jis = new JarInputStream(new NoCloseInputStream(is), true);
if ( containsSha1(jis.getManifest()) ) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
System.out.println("Stripping signature on " + entry.getName());
JarOutputStream jos = new JarOutputStream(baos);
jos.setLevel(0);
try {
JarEntry jarEntry = null;
while ( ( jarEntry = jis.getNextJarEntry() ) != null ) {
jos.putNextEntry(new JarEntry(jarEntry.getName()));
IOUtils.copy(jis, jos);
jos.closeEntry();
}
} finally {
IOUtils.closeQuietly(jos);
}
jis = new JarInputStream(new ByteArrayInputStream(baos.toByteArray()));
}
File outputFile = new File(output, entry.getName() + ".pack");
FileUtils.forceMkdir(outputFile.getParentFile());
System.out.println("Compressing " + entry.getName() + " to " + outputFile);
FileOutputStream fos = new FileOutputStream(outputFile);
try {
Packer packer = Pack200.newPacker();
packer.properties().put(Packer.DEFLATE_HINT, Packer.FALSE);
packer.properties().put(Packer.EFFORT, "9");
packer.pack(jis, fos);
} finally {
IOUtils.closeQuietly(fos);
}
}
示例13: normalize
import java.util.jar.Pack200; //导入方法依赖的package包/类
public static void normalize(File from, File to, Map<String, String> props) throws IOException {
if (props == null) {
props = new HashMap();
}
((Map) props).put("pack.segment.limit", "-1");
File f = File.createTempFile("commons-compress", "pack200normalize");
f.deleteOnExit();
try {
Object os = new FileOutputStream(f);
Object j = null;
try {
Pack200.Packer p = Pack200.newPacker();
p.properties().putAll((Map) props);
p.pack(new JarFile(from), (OutputStream) os);
j = null;
((OutputStream) os).close();
os = null;
Pack200.Unpacker u = Pack200.newUnpacker();
os = new JarOutputStream(new FileOutputStream(to));
u.unpack(f, (JarOutputStream) os);
} finally {
if (j != null) {
((JarFile) j).close();
}
if (os != null) {
((OutputStream) os).close();
}
}
} finally {
f.delete();
}
}
示例14: createAgressivePack200Packer
import java.util.jar.Pack200; //导入方法依赖的package包/类
private Pack200.Packer createAgressivePack200Packer()
{
Pack200.Packer packer = Pack200.newPacker();
Map<String, String> m = packer.properties();
m.put(Pack200.Packer.EFFORT, "9");
m.put(Pack200.Packer.SEGMENT_LIMIT, "-1");
m.put(Pack200.Packer.KEEP_FILE_ORDER, Pack200.Packer.FALSE);
m.put(Pack200.Packer.DEFLATE_HINT, Pack200.Packer.FALSE);
m.put(Pack200.Packer.MODIFICATION_TIME, Pack200.Packer.LATEST);
m.put(Pack200.Packer.CODE_ATTRIBUTE_PFX +"LineNumberTable", Pack200.Packer.STRIP);
m.put(Pack200.Packer.CODE_ATTRIBUTE_PFX + "LocalVariableTable", Pack200.Packer.STRIP);
m.put(Pack200.Packer.CODE_ATTRIBUTE_PFX + "SourceFile", Pack200.Packer.STRIP);
return packer;
}
示例15: verifyDefaults
import java.util.jar.Pack200; //导入方法依赖的package包/类
private static void verifyDefaults() {
Map<String, String> expectedDefaults = new HashMap<>();
Packer p = Pack200.newPacker();
expectedDefaults.put("com.sun.java.util.jar.pack.default.timezone",
p.FALSE);
expectedDefaults.put("com.sun.java.util.jar.pack.disable.native",
p.FALSE);
expectedDefaults.put("com.sun.java.util.jar.pack.verbose", "0");
expectedDefaults.put(p.CLASS_ATTRIBUTE_PFX + "CompilationID", "RUH");
expectedDefaults.put(p.CLASS_ATTRIBUTE_PFX + "SourceID", "RUH");
expectedDefaults.put(p.CODE_ATTRIBUTE_PFX + "CharacterRangeTable",
"NH[PHPOHIIH]");
expectedDefaults.put(p.CODE_ATTRIBUTE_PFX + "CoverageTable",
"NH[PHHII]");
expectedDefaults.put(p.DEFLATE_HINT, p.KEEP);
expectedDefaults.put(p.EFFORT, "5");
expectedDefaults.put(p.KEEP_FILE_ORDER, p.TRUE);
expectedDefaults.put(p.MODIFICATION_TIME, p.KEEP);
expectedDefaults.put(p.SEGMENT_LIMIT, "-1");
expectedDefaults.put(p.UNKNOWN_ATTRIBUTE, p.PASS);
Map<String, String> props = p.properties();
int errors = 0;
for (String key : expectedDefaults.keySet()) {
String def = expectedDefaults.get(key);
String x = props.get(key);
if (x == null) {
System.out.println("Error: key not found:" + key);
errors++;
} else {
if (!def.equals(x)) {
System.out.println("Error: key " + key
+ "\n value expected: " + def
+ "\n value obtained: " + x);
errors++;
}
}
}
if (errors > 0) {
throw new RuntimeException(errors +
" error(s) encountered in default properties verification");
}
}