harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r702856 [3/3] - in /harmony/enhanced/classlib/trunk: ./ depends/files/ depends/manifests/asm-3.1/ make/ modules/pack200/META-INF/ modules/pack200/src/main/java/org/apache/harmony/pack200/ modules/pack200/src/test/java/org/apache/harmony/pac...
Date Wed, 08 Oct 2008 13:05:44 GMT
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=702856&r1=702855&r2=702856&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 Oct  8 06:05:43 2008
@@ -46,7 +46,7 @@
     private int attribute_definition_count;
     private final byte[] band_headers = new byte[0];
 
-    private boolean have_all_code_flags;
+    private boolean have_all_code_flags = true; // true by default
 
     private int archive_size_hi;
     private int archive_size_lo;
@@ -56,16 +56,15 @@
 
     private boolean deflate_hint;
     private boolean have_file_modtime;
-    private boolean  have_file_options;
-    private boolean  have_file_size_hi;
-    private boolean  have_class_flags_hi;
-    private boolean  have_field_flags_hi;
-    private boolean  have_method_flags_hi;
-    private boolean  have_code_flags_hi;
+    private boolean have_file_options = true;
+    private boolean have_file_size_hi;
+    private boolean have_class_flags_hi;
+    private boolean have_field_flags_hi;
+    private boolean have_method_flags_hi;
+    private boolean have_code_flags_hi;
 
     private int ic_count;
     private int class_count;
-    private final Counter minverCounter = new Counter();
     private final Counter majverCounter = new Counter();
 
     /**
@@ -87,40 +86,41 @@
     }
 
     private void calculateArchiveOptions() {
-        if(attribute_definition_count > 0 || band_headers.length > 0) {
+        if (attribute_definition_count > 0 || band_headers.length > 0) {
             archive_options |= 1;
         }
-        if(cp_Int_count > 0 || cp_Float_count > 0 || cp_Long_count > 0 || cp_Double_count
> 0) {
+        if (cp_Int_count > 0 || cp_Float_count > 0 || cp_Long_count > 0
+                || cp_Double_count > 0) {
             archive_options |= (1 << 1);
         }
-        if(have_all_code_flags) {
+        if (have_all_code_flags) {
             archive_options |= (1 << 2);
         }
-        if(file_count > 0) {
+        if (file_count > 0) {
             archive_options |= (1 << 4);
         }
-        if(deflate_hint) {
+        if (deflate_hint) {
             archive_options |= (1 << 5);
         }
-        if(have_file_modtime) {
+        if (have_file_modtime) {
             archive_options |= (1 << 6);
         }
-        if(have_file_options) {
+        if (have_file_options) {
             archive_options |= (1 << 7);
         }
-        if(have_file_size_hi) {
+        if (have_file_size_hi) {
             archive_options |= (1 << 8);
         }
-        if(have_class_flags_hi) {
+        if (have_class_flags_hi) {
             archive_options |= (1 << 9);
         }
-        if(have_field_flags_hi) {
+        if (have_field_flags_hi) {
             archive_options |= (1 << 10);
         }
-        if(have_method_flags_hi) {
+        if (have_method_flags_hi) {
             archive_options |= (1 << 11);
         }
-        if(have_code_flags_hi) {
+        if (have_code_flags_hi) {
             archive_options |= (1 << 12);
         }
     }
@@ -177,97 +177,78 @@
         this.attribute_definition_count = attribute_definition_count;
     }
 
-
     public void setHave_all_code_flags(boolean have_all_code_flags) {
         this.have_all_code_flags = have_all_code_flags;
     }
 
-
     public void setArchive_size_hi(int archive_size_hi) {
         this.archive_size_hi = archive_size_hi;
     }
 
-
     public void setArchive_size_lo(int archive_size_lo) {
         this.archive_size_lo = archive_size_lo;
     }
 
-
     public void setArchive_next_count(int archive_next_count) {
         this.archive_next_count = archive_next_count;
     }
 
-
     public void setArchive_modtime(int archive_modtime) {
         this.archive_modtime = archive_modtime;
     }
 
-
     public void setFile_count(int file_count) {
         this.file_count = file_count;
     }
 
-
     public void setDeflate_hint(boolean deflate_hint) {
         this.deflate_hint = deflate_hint;
     }
 
-
     public void setHave_file_modtime(boolean have_file_modtime) {
         this.have_file_modtime = have_file_modtime;
     }
 
-
     public void setHave_file_options(boolean have_file_options) {
         this.have_file_options = have_file_options;
     }
 
-
     public void setHave_file_size_hi(boolean have_file_size_hi) {
         this.have_file_size_hi = have_file_size_hi;
     }
 
-
     public void setHave_class_flags_hi(boolean have_class_flags_hi) {
         this.have_class_flags_hi = have_class_flags_hi;
     }
 
-
     public void setHave_field_flags_hi(boolean have_field_flags_hi) {
         this.have_field_flags_hi = have_field_flags_hi;
     }
 
-
     public void setHave_method_flags_hi(boolean have_method_flags_hi) {
         this.have_method_flags_hi = have_method_flags_hi;
     }
 
-
     public void setHave_code_flags_hi(boolean have_code_flags_hi) {
         this.have_code_flags_hi = have_code_flags_hi;
     }
 
-
     public boolean have_class_flags_hi() {
         return have_class_flags_hi;
     }
 
-
     public boolean have_field_flags_hi() {
         return have_field_flags_hi;
     }
 
-
     public boolean have_method_flags_hi() {
         return have_method_flags_hi;
     }
 
-
     public boolean have_code_flags_hi() {
         return have_code_flags_hi;
     }
 
-
     public void setIc_count(int ic_count) {
         this.ic_count = ic_count;
     }
@@ -276,9 +257,10 @@
         this.class_count = class_count;
     }
 
-    private void writeCpCounts(OutputStream out) throws IOException, Pack200Exception {
+    private void writeCpCounts(OutputStream out) throws IOException,
+            Pack200Exception {
         out.write(encodeScalar(cp_Utf8_count, Codec.UNSIGNED5));
-        if((archive_options & (1 << 1)) != 0) { // have_cp_numbers
+        if ((archive_options & (1 << 1)) != 0) { // have_cp_numbers
             out.write(encodeScalar(cp_Int_count, Codec.UNSIGNED5));
             out.write(encodeScalar(cp_Float_count, Codec.UNSIGNED5));
             out.write(encodeScalar(cp_Long_count, Codec.UNSIGNED5));
@@ -293,8 +275,9 @@
         out.write(encodeScalar(cp_Imethod_count, Codec.UNSIGNED5));
     }
 
-    private void writeClassCounts(OutputStream out) throws IOException, Pack200Exception
{
-        int default_class_minver = minverCounter.getMostCommon();
+    private void writeClassCounts(OutputStream out) throws IOException,
+            Pack200Exception {
+        int default_class_minver = 0;
         int default_class_majver = majverCounter.getMostCommon();
         out.write(encodeScalar(ic_count, Codec.UNSIGNED5));
         out.write(encodeScalar(default_class_minver, Codec.UNSIGNED5));
@@ -302,15 +285,19 @@
         out.write(encodeScalar(class_count, Codec.UNSIGNED5));
     }
 
-    private void writeArchiveSpecialCounts(OutputStream out) throws IOException, Pack200Exception
{
-        if((archive_options & 1) > 0) { // have_special_formats
+    private void writeArchiveSpecialCounts(OutputStream out)
+            throws IOException, Pack200Exception {
+        if ((archive_options & 1) > 0) { // have_special_formats
             out.write(encodeScalar(band_headers.length, Codec.UNSIGNED5));
-            out.write(encodeScalar(attribute_definition_count, Codec.UNSIGNED5));
+            out
+                    .write(encodeScalar(attribute_definition_count,
+                            Codec.UNSIGNED5));
         }
     }
 
-    private void writeArchiveFileCounts(OutputStream out) throws IOException, Pack200Exception
{
-        if((archive_options & (1 << 4)) > 0) { // have_file_headers
+    private void writeArchiveFileCounts(OutputStream out) throws IOException,
+            Pack200Exception {
+        if ((archive_options & (1 << 4)) > 0) { // have_file_headers
             out.write(encodeScalar(archive_size_hi, Codec.UNSIGNED5));
             out.write(encodeScalar(archive_size_lo, Codec.UNSIGNED5));
             out.write(encodeScalar(archive_next_count, Codec.UNSIGNED5));
@@ -319,10 +306,6 @@
         }
     }
 
-    public void addMinorVersion(int minor) {
-        minverCounter.add(minor);
-    }
-
     public void addMajorVersion(int major) {
         majverCounter.add(major);
     }
@@ -339,16 +322,16 @@
         public void add(int obj) {
             boolean found = false;
             for (int i = 0; i < length; i++) {
-                if(objs[i] == obj) {
+                if (objs[i] == obj) {
                     counts[i]++;
                     found = true;
                 }
             }
-            if(!found) {
+            if (!found) {
                 objs[length] = obj;
                 counts[length] = 1;
-                length ++;
-                if(length > objs.length - 1) {
+                length++;
+                if (length > objs.length - 1) {
                     Object[] newArray = new Object[objs.length + 8];
                     System.arraycopy(objs, 0, newArray, 0, length);
                 }
@@ -358,7 +341,7 @@
         public int getMostCommon() {
             int returnIndex = 0;
             for (int i = 0; i < length; i++) {
-                if(counts[i] > counts[returnIndex]) {
+                if (counts[i] > counts[returnIndex]) {
                     returnIndex = i;
                 }
             }
@@ -367,11 +350,23 @@
     }
 
     public int getDefaultMinorVersion() {
-        return minverCounter.getMostCommon();
+        return 0;
     }
 
     public int getDefaultMajorVersion() {
         return majverCounter.getMostCommon();
     }
 
+    public boolean have_file_size_hi() {
+        return have_file_size_hi;
+    }
+
+    public boolean have_file_modtime() {
+        return have_file_modtime;
+    }
+
+    public boolean have_file_options() {
+        return have_file_options;
+    }
+
 }
\ No newline at end of file

Added: 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=702856&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
Wed Oct  8 06:05:43 2008
@@ -0,0 +1,98 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.harmony.pack200.tests;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.URISyntaxException;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.JarInputStream;
+import java.util.jar.JarOutputStream;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.pack200.Archive;
+import org.apache.harmony.pack200.Pack200Exception;
+import org.apache.harmony.unpack200.Segment;
+
+
+public class ArchiveTest extends TestCase {
+
+    JarInputStream in;
+    OutputStream out;
+    File file;
+
+    public void testHelloWorld() throws IOException, Pack200Exception, URISyntaxException
{
+        in = new JarInputStream(
+                Archive.class
+                        .getResourceAsStream("/org/apache/harmony/pack200/tests/hw.jar"));
+        file = File.createTempFile("helloworld", ".pack");
+        out = new FileOutputStream(file);
+        new Archive(in, out).pack();
+        in.close();
+        out.close();
+
+        // now unpack
+        InputStream in2 = new FileInputStream(file);
+        File file2 = File.createTempFile("helloworld", ".jar");
+        JarOutputStream out2 = new JarOutputStream(new FileOutputStream(file2));
+        org.apache.harmony.unpack200.Archive archive = new org.apache.harmony.unpack200.Archive(
+                in2, out2);
+        archive.unpack();
+        out2.close();
+        in2.close();
+
+        JarFile jarFile = new JarFile(file2);
+        file2.deleteOnExit();
+        JarEntry entry = jarFile
+                .getJarEntry("org/apache/harmony/archive/tests/internal/pack200/HelloWorld.class");
+        assertNotNull(entry);
+        InputStream ours = jarFile.getInputStream(entry);
+
+        JarFile jarFile2 = new JarFile(new File(Segment.class.getResource(
+                "/org/apache/harmony/pack200/tests/hw.jar").toURI()));
+        JarEntry entry2 = jarFile2
+                .getJarEntry("org/apache/harmony/archive/tests/internal/pack200/HelloWorld.class");
+        assertNotNull(entry2);
+
+        InputStream expected = jarFile2.getInputStream(entry2);
+
+        BufferedReader reader1 = new BufferedReader(new InputStreamReader(ours));
+        BufferedReader reader2 = new BufferedReader(new InputStreamReader(
+                expected));
+        String line1 = reader1.readLine();
+        String line2 = reader2.readLine();
+        int i = 1;
+        while (line1 != null || line2 != null) {
+            assertEquals("Unpacked class files differ", line2, line1);
+            line1 = reader1.readLine();
+            line2 = reader2.readLine();
+            i++;
+        }
+        reader1.close();
+        reader2.close();
+
+    }
+
+}

Propchange: harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message