You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by sj...@apache.org on 2009/01/20 14:24:23 UTC
svn commit: r736016 - in
/harmony/enhanced/classlib/trunk/modules/pack200/src:
main/java/org/apache/harmony/pack200/Archive.java
test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
Author: sjanuary
Date: Tue Jan 20 05:24:22 2009
New Revision: 736016
URL: http://svn.apache.org/viewvc?rev=736016&view=rev
Log:
Pack200 - test and bug fix for new segment limit option
Modified:
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java
harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java?rev=736016&r1=736015&r2=736016&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java Tue Jan 20 05:24:22 2009
@@ -82,10 +82,12 @@
files);
if (!added) { // not added because segment has reached
// maximum size
- new Segment().pack(classes, files, outputStream);
- classes = new ArrayList();
- files = new ArrayList();
- currentSegmentSize = 0;
+ if(classes.size() > 0 || files.size() > 0) {
+ new Segment().pack(classes, files, outputStream);
+ classes = new ArrayList();
+ files = new ArrayList();
+ currentSegmentSize = 0;
+ }
if (!addJarEntry(jarEntry, new BufferedInputStream(
inputStream), classes, files)) {
throw new Pack200Exception(
@@ -135,6 +137,8 @@
long size = jarEntry.getSize();
if (size > Integer.MAX_VALUE) {
throw new RuntimeException("Large Class!");
+ } else if (size < 0) {
+ throw new RuntimeException("Error: size for " + name + " is " + size);
}
if(segmentLimit != -1 && segmentLimit != 0) {
// -1 is a special case where only one segment is created and
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java?rev=736016&r1=736015&r2=736016&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java Tue Jan 20 05:24:22 2009
@@ -141,6 +141,57 @@
compareFiles(jarFile, jarFile2);
}
+ public void testSegmentLimits() throws IOException, Pack200Exception {
+ in = new JarInputStream(
+ Archive.class
+ .getResourceAsStream("/org/apache/harmony/pack200/tests/hw.jar"));
+ file = File.createTempFile("helloworld", ".pack.gz");
+ out = new FileOutputStream(file);
+ Archive archive = new Archive(in, out, true);
+ archive.setSegmentLimit(1);
+ try {
+ archive.pack();
+ fail("Should throw an execption with a 1-byte segment limit");
+ } catch (Pack200Exception pe) {
+ assertEquals("Expected limit too small message", "Segment limit is too small for the files you are trying to pack", pe.getMessage());
+ }
+ in.close();
+ out.close();
+
+ in = new JarInputStream(
+ Archive.class
+ .getResourceAsStream("/org/apache/harmony/pack200/tests/hw.jar"));
+ file = File.createTempFile("helloworld", ".pack.gz");
+ out = new FileOutputStream(file);
+ archive = new Archive(in, out, true);
+ archive.setSegmentLimit(0);
+ archive.pack();
+ in.close();
+ out.close();
+
+ in = new JarInputStream(
+ Archive.class
+ .getResourceAsStream("/org/apache/harmony/pack200/tests/hw.jar"));
+ file = File.createTempFile("helloworld", ".pack.gz");
+ out = new FileOutputStream(file);
+ archive = new Archive(in, out, true);
+ archive.setSegmentLimit(-1);
+ archive.pack();
+ in.close();
+ out.close();
+
+ in = new JarInputStream(
+ Archive.class
+ .getResourceAsStream("/org/apache/harmony/pack200/tests/hw.jar"));
+ file = File.createTempFile("helloworld", ".pack.gz");
+ out = new FileOutputStream(file);
+ archive = new Archive(in, out, true);
+ archive.setSegmentLimit(5000);
+ archive.pack();
+ in.close();
+ out.close();
+ }
+
private void compareFiles(JarFile jarFile, JarFile jarFile2)
throws IOException {
Enumeration entries = jarFile.entries();