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/15 17:33:29 UTC
svn commit: r734747 -
/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java
Author: sjanuary
Date: Thu Jan 15 08:33:28 2009
New Revision: 734747
URL: http://svn.apache.org/viewvc?rev=734747&view=rev
Log:
Pack200 - support for special cases for segment limit option
Modified:
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.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=734747&r1=734746&r2=734747&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 Thu Jan 15 08:33:28 2009
@@ -41,7 +41,7 @@
private final JarInputStream inputStream;
private final OutputStream outputStream;
private JarFile jarFile;
- private final long segmentLimit = 1000000;
+ private long segmentLimit = 1000000;
private long currentSegmentSize;
public Archive(JarInputStream inputStream, OutputStream outputStream,
@@ -59,6 +59,10 @@
inputStream = null;
}
+ public void setSegmentLimit(int limit) {
+ segmentLimit = limit;
+ }
+
public void pack() throws Pack200Exception, IOException {
List classes = new ArrayList();
List files = new ArrayList();
@@ -85,8 +89,13 @@
if (!addJarEntry(jarEntry, new BufferedInputStream(
inputStream), classes, files)) {
throw new Pack200Exception(
- "Segment limit is too small");
+ "Segment limit is too small for the files you are trying to pack");
}
+ } else if (segmentLimit == 0) {
+ // create a new segment for each class
+ new Segment().pack(classes, files, outputStream);
+ classes = new ArrayList();
+ files = new ArrayList();
}
}
}
@@ -106,6 +115,11 @@
.getInputStream(jarEntry)), classes, files)) {
throw new Pack200Exception("Segment limit is too small");
}
+ } else if (segmentLimit == 0) {
+ // create a new segment for each class
+ new Segment().pack(classes, files, outputStream);
+ classes = new ArrayList();
+ files = new ArrayList();
}
}
}
@@ -122,12 +136,16 @@
if (size > Integer.MAX_VALUE) {
throw new RuntimeException("Large Class!");
}
- int packedSize = name.endsWith(".class") ? estimatePackedSize(size)
- : (int) size;
- if (packedSize + currentSegmentSize > segmentLimit) {
- return false;
- } else {
- currentSegmentSize += packedSize;
+ if(segmentLimit != -1 && segmentLimit != 0) {
+ // -1 is a special case where only one segment is created and
+ // 0 is a special case where one segment is created for each file
+ int packedSize = name.endsWith(".class") ? estimatePackedSize(size)
+ : (int) size;
+ if (packedSize + currentSegmentSize > segmentLimit) {
+ return false;
+ } else {
+ currentSegmentSize += packedSize;
+ }
}
byte[] bytes = new byte[(int) size];
int read = stream.read(bytes);