harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r641848 - /harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/RunCodec.java
Date Thu, 27 Mar 2008 15:28:58 GMT
Author: sjanuary
Date: Thu Mar 27 08:28:56 2008
New Revision: 641848

URL: http://svn.apache.org/viewvc?rev=641848&view=rev
Log:
Partial fix for HARMONY-5645 ([classlib][pack200] Pack200 - still some issues with maximal
encoding (non -E1))

Modified:
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/RunCodec.java

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/RunCodec.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/RunCodec.java?rev=641848&r1=641847&r2=641848&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/RunCodec.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/RunCodec.java
Thu Mar 27 08:28:56 2008
@@ -28,8 +28,8 @@
  */
 public class RunCodec extends Codec {
 	private int k;
-	private Codec aCodec;
-	private Codec bCodec;
+	private final Codec aCodec;
+	private final Codec bCodec;
 	private long last;
 
 	public RunCodec(int k, Codec aCodec, Codec bCodec) throws Pack200Exception {
@@ -47,16 +47,30 @@
 
 	public long decode(InputStream in, long last) throws IOException, Pack200Exception {
 		if(--k>=0) {
-			long value = aCodec.decode(in,last);
+			long value = aCodec.decode(in, this.last);
 			this.last = (k == 0 ? 0 : value);
-			return value;
+			return normalise(aCodec, value);
 		} else {
-			this.last = bCodec.decode(in,last);
-			return this.last;
+			this.last = bCodec.decode(in, this.last);
+			return normalise(bCodec, this.last);
 		}
 	}
 
-    public int[] decodeInts(int n, InputStream in) throws IOException, Pack200Exception {
+    private long normalise(Codec codecUsed, long value) {
+        if(codecUsed instanceof BHSDCodec && ((BHSDCodec)codecUsed).isDelta()) {
+            BHSDCodec bhsd = (BHSDCodec)codecUsed;
+            long cardinality = bhsd.cardinality();
+           while (value > bhsd.largest()) {
+                value -= cardinality;
+            }
+            while (value < bhsd.smallest()) {
+                value += cardinality;
+            }
+        }
+        return value;
+	}
+
+	public int[] decodeInts(int n, InputStream in) throws IOException, Pack200Exception {
         int[] band = new int[n];
         int[] aValues = aCodec.decodeInts(k, in);
         normalise(aValues, aCodec);



Mime
View raw message