3261N/A * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * See the section "Adaptive Encodings" in the Pack200 spec. 0N/A // CodingMethod methods. 0N/A // writeArrayTo must be coded iteratively, not recursively: 0N/A if (K <=
0)
return 1;
// 1st K value 0N/A // This is the increment we expect to apply: 0N/A K1 &= ~(
unit-
1);
// cut off stray low-order bits 0N/A // Is K of the form ((KB:[0..255])+1) * 16^(KX:{0..3])? 0N/A if (
KX <
0)
return false;
0N/A //assert(!isTrivial()); // can happen 0N/A // See the isCodableLength restriction in CodingChooser. 0N/A continue;
// tail call, to avoid deep stack recursion 0N/A public static void main(String av[]) { 0N/A {254,255,256,256+1*16,256+2*16}, 0N/A {0xfd,0xfe,0xff,0x100,0x110,0x120,0x130}, 0N/A {0xfd0,0xfe0,0xff0,0x1000,0x1100,0x1200,0x1300}, 0N/A {0xfd00,0xfe00,0xff00,0x10000,0x11000,0x12000,0x13000}, 0N/A {0xfd000,0xfe000,0xff000,0x100000} 0N/A for (int i = 0; i < samples.length; i++) { 0N/A for (int j = 0; j < samples[i].length; j++) { 0N/A int K = samples[i][j]; 0N/A int KX = getKXOf(K); 0N/A int KB = getKBOf(K); 0N/A System.out.println("K="+Integer.toHexString(K)+ 0N/A " KX="+KX+" KB="+KB); 0N/A assert(isCodableLength(K)); 0N/A assert(K == decodeK(KX, KB)); 0N/A if (j == 0) continue; 0N/A int K1 = samples[i][j-1]; 0N/A assert(K == getNextK(K1));