You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by hi...@apache.org on 2008/01/09 14:41:00 UTC
svn commit: r610385 - in
/harmony/enhanced/classlib/trunk/modules/pack200/src:
main/java/org/apache/harmony/pack200/
main/java5/org/apache/harmony/pack200/ test/java/
test/java/org/apache/harmony/pack200/tests/
Author: hindessm
Date: Wed Jan 9 05:40:30 2008
New Revision: 610385
URL: http://svn.apache.org/viewvc?rev=610385&view=rev
Log:
Applying patches from "[#HARMONY-5375] [classlib] [pack200] Files not read
completely when a gzipped archive is used".
Modified:
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java5/org/apache/harmony/pack200/Pack200UnpackerAdapter.java
harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/Unpack.java
harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentTest.java
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java?rev=610385&r1=610384&r2=610385&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java Wed Jan 9 05:40:30 2008
@@ -40,6 +40,8 @@
private long[] fileSize;
private String[] cpUTF8;
+
+ private InputStream in;
/**
* @param header
@@ -73,10 +75,11 @@
} else {
fileOptions = new long[numberOfFiles];
}
+ this.in = in; // store for use by processFileBits(), which is called later
}
-
- public void processFileBits(InputStream in) throws IOException,
+ // TODO: stream the file bits directly somehow
+ public void processFileBits() throws IOException,
Pack200Exception {
// now read in the bytes
int numberOfFiles = header.getNumberOfFiles();
@@ -86,8 +89,9 @@
// TODO This breaks if file_size > 2^32. Probably an array is
// not the right choice, and we should just serialize it here?
fileBits[i] = new byte[size];
- for (int j = 0; j < size; j++) {
- fileBits[i][j] = (byte) Codec.BYTE1.decode(in);
+ int read = in.read(fileBits[i]);
+ if(read < size) {
+ throw new Pack200Exception("Expected to read " + size +" bytes but read " + read);
}
}
}
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java?rev=610385&r1=610384&r2=610385&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java Wed Jan 9 05:40:30 2008
@@ -97,7 +97,7 @@
} else {
in.reset();
}
- segment.parseSegment(in);
+ segment.parseSegment(in);
return segment;
}
@@ -268,9 +268,9 @@
* @throws Pack200Exception
* if an error occurs whilst unpacking data
*/
- public void writeJar(JarOutputStream out, InputStream in)
+ public void writeJar(JarOutputStream out)
throws IOException, Pack200Exception {
- fileBands.processFileBits(in);
+ fileBands.processFileBits();
DataOutputStream dos = new DataOutputStream(out);
String[] fileName = fileBands.getFileName();
long[] fileModtime = fileBands.getFileModtime();
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java?rev=610385&r1=610384&r2=610385&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java Wed Jan 9 05:40:30 2008
@@ -329,7 +329,7 @@
private long[] decodeScalar(String name, InputStream in, BHSDCodec codec,
int n) throws IOException, Pack200Exception {
// TODO Remove debugging code
-// debug("Parsed #" + name + " (" + n + ")");
+ debug("Parsed #" + name + " (" + n + ")");
return codec.decode(n, in);
}
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java5/org/apache/harmony/pack200/Pack200UnpackerAdapter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java5/org/apache/harmony/pack200/Pack200UnpackerAdapter.java?rev=610385&r1=610384&r2=610385&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java5/org/apache/harmony/pack200/Pack200UnpackerAdapter.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java5/org/apache/harmony/pack200/Pack200UnpackerAdapter.java Wed Jan 9 05:40:30 2008
@@ -48,7 +48,7 @@
try {
while (in.available() > 0) {
Segment s = Segment.parse(in);
- s.writeJar(out, in);
+ s.writeJar(out);
out.flush();
}
} catch (Pack200Exception e) {
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/Unpack.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/Unpack.java?rev=610385&r1=610384&r2=610385&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/Unpack.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/Unpack.java Wed Jan 9 05:40:30 2008
@@ -33,6 +33,6 @@
JarOutputStream out = new JarOutputStream(
args.length > 1 ? (OutputStream) new FileOutputStream(args[1])
: (OutputStream) new BufferedOutputStream(System.out));
- Segment.parse(in).writeJar(out, in);
+ Segment.parse(in).writeJar(out);
}
}
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentTest.java?rev=610385&r1=610384&r2=610385&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentTest.java Wed Jan 9 05:40:30 2008
@@ -29,40 +29,50 @@
* Tests for org.apache.harmony.pack200.Segment, which is the main class for pack200.
*/
public class SegmentTest extends TestCase {
+
+ InputStream in;
+ JarOutputStream out;
boolean handlingInnerClasses = false;
public void testHelloWorld() throws Exception {
- InputStream in = Segment.class
- .getResourceAsStream("/org/apache/harmony/pack200/tests/HelloWorld.pack");
+ in = Segment.class
+ .getResourceAsStream("/org/apache/harmony/pack200/tests/HelloWorld.pack");
Segment segment = Segment.parse(in);
assertNotNull(segment);
- segment.writeJar(new JarOutputStream(new FileOutputStream(File.createTempFile("Hello", "World.jar"))), in);
- }
+ out = new JarOutputStream(new FileOutputStream(File.createTempFile("hello", "world.jar")));
+ segment.writeJar(out);
+ }
public void testJustResources() throws Exception {
- InputStream in = Segment.class
- .getResourceAsStream("/org/apache/harmony/pack200/tests/JustResources.pack");
+ in = Segment.class
+ .getResourceAsStream("/org/apache/harmony/pack200/tests/JustResources.pack");
Segment segment = Segment.parse(in);
- assertNotNull(segment);
- segment.writeJar(new JarOutputStream(new FileOutputStream(File.createTempFile("just", "Resources.jar"))), in);
+ assertNotNull(segment);
+ out = new JarOutputStream(new FileOutputStream(File.createTempFile("just", "resources.jar")));
+ segment.writeJar(out);
}
public void testJustResourcesGZip() throws Exception {
- assertNotNull(Segment
- .parse(Segment.class
- .getResourceAsStream("/org/apache/harmony/pack200/tests/JustResources.pack.gz")));
- }
+ in = Segment.class
+ .getResourceAsStream("/org/apache/harmony/pack200/tests/JustResources.pack.gz");
+ Segment segment = Segment.parse(in);
+ assertNotNull(segment);
+ out = new JarOutputStream(new FileOutputStream(File.createTempFile("Just", "ResourcesGz.jar")));
+ segment.writeJar(out);
+ }
// Test with an archive containing Harmony's SQL module, packed with -E1
public void testWithSqlE1() throws Exception {
// This test will not pass until we handle inner classes
// correctly.
if(!handlingInnerClasses) return;
- assertNotNull(Segment
- .parse(Segment.class
- .getResourceAsStream("/org/apache/harmony/pack200/tests/sql-e1.pack.gz")));
-
+ in = Segment.class
+ .getResourceAsStream("/org/apache/harmony/pack200/tests/sql-e1.pack.gz");
+ Segment segment = Segment.parse(in);
+ assertNotNull(segment);
+ out = new JarOutputStream(new FileOutputStream(File.createTempFile("s", "ql-e1.jar")));
+ segment.writeJar(out);
}
// Test with an archive containing Harmony's SQL module
@@ -70,49 +80,77 @@
// This test will not pass until we handle inner classes
// correctly.
if(!handlingInnerClasses) return;
- assertNotNull(Segment
- .parse(Segment.class
- .getResourceAsStream("/org/apache/harmony/pack200/tests/sql.pack.gz")));
-
+ in = Segment.class
+ .getResourceAsStream("/org/apache/harmony/pack200/tests/sql.pack.gz");
+ Segment segment = Segment.parse(in);
+ assertNotNull(segment);
+ out = new JarOutputStream(new FileOutputStream(File.createTempFile("s", "ql.jar")));
+ segment.writeJar(out);
}
// Test with an archive containing Harmony's Pack200 module, packed with -E1
public void testWithPack200E1() throws Exception {
- assertNotNull(Segment
- .parse(Segment.class
- .getResourceAsStream("/org/apache/harmony/pack200/tests/pack200-e1.pack.gz")));
-
+ in = Segment.class
+ .getResourceAsStream("/org/apache/harmony/pack200/tests/pack200-e1.pack.gz");
+ Segment segment = Segment.parse(in);
+ assertNotNull(segment);
+ out = new JarOutputStream(new FileOutputStream(File.createTempFile("pack", "200-e1.jar")));
+ segment.writeJar(out);
}
// Test with an archive containing Harmony's Pack200 module
public void testWithPack200() throws Exception {
- assertNotNull(Segment
- .parse(Segment.class
- .getResourceAsStream("/org/apache/harmony/pack200/tests/pack200.pack.gz")));
-
+ in = Segment.class
+ .getResourceAsStream("/org/apache/harmony/pack200/tests/pack200.pack.gz");
+ Segment segment = Segment.parse(in);
+ assertNotNull(segment);
+ out = new JarOutputStream(new FileOutputStream(File.createTempFile("pack", "200.jar")));
+ segment.writeJar(out);
}
// Test with an archive containing Harmony's JNDI module
public void testWithJNDIE1() throws Exception {
if(!handlingInnerClasses) return;
- assertNotNull(Segment
- .parse(Segment.class
- .getResourceAsStream("/org/apache/harmony/pack200/tests/jndi-e1.pack.gz")));
-
+ in = Segment.class
+ .getResourceAsStream("/org/apache/harmony/pack200/tests/jndi-e1.pack.gz");
+ Segment segment = Segment.parse(in);
+ assertNotNull(segment);
+ out = new JarOutputStream(new FileOutputStream(File.createTempFile("jn", "di-e1.jar")));
+ segment.writeJar(out);
}
// Test with an archive containing Annotations
public void testWithAnnotations() throws Exception {
- assertNotNull(Segment
- .parse(Segment.class
- .getResourceAsStream("/org/apache/harmony/pack200/tests/annotations.pack.gz")));
+
+ in = Segment.class
+ .getResourceAsStream("/org/apache/harmony/pack200/tests/annotations.pack.gz");
+ Segment segment = Segment.parse(in);
+ assertNotNull(segment);
+ out = new JarOutputStream(new FileOutputStream(File.createTempFile("ann", "otations.jar")));
+ segment.writeJar(out);
}
public void testInterfaceOnly() throws Exception {
- assertNotNull(Segment
- .parse(Segment.class
- .getResourceAsStream("/org/apache/harmony/pack200/tests/InterfaceOnly.pack")));
+ in = Segment.class
+ .getResourceAsStream("/org/apache/harmony/pack200/tests/InterfaceOnly.pack");
+ Segment segment = Segment.parse(in);
+ assertNotNull(segment);
+ out = new JarOutputStream(new FileOutputStream(File.createTempFile("Interface", "Only.jar")));
+ segment.writeJar(out);
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ try {
+ if (in != null) {
+ in.close();
+ }
+ } finally {
+ if (out != null) {
+ out.close();
+ }
+ }
}
}