Package org.apache.harmony.pack200

Examples of org.apache.harmony.pack200.PopulationCodec


    private void checkDecode(byte[] data, long[] expectedResult, Codec codec)
            throws IOException, Pack200Exception {
        InputStream in = new ByteArrayInputStream(data);

        int[] result = new PopulationCodec(codec, codec, codec).decodeInts(
                expectedResult.length, in);
        assertEquals(expectedResult.length, result.length);
        for (int i = 0; i < expectedResult.length; i++) {
            assertEquals(expectedResult[i], result[i]);
        }
View Full Code Here


        assertEquals(0, in.available());
    }
   
    public void testEncodeSingleValue() {
        try {
            new PopulationCodec(BHSDCodec.SIGNED5, BHSDCodec.SIGNED5, BHSDCodec.UDELTA5).encode(5);
            fail("Should not allow a single value to be encoded as we don't know which codec to use");
        } catch (Pack200Exception e) {
            // pass
        }
        try {
            new PopulationCodec(BHSDCodec.SIGNED5, BHSDCodec.SIGNED5, BHSDCodec.UDELTA5).encode(5, 8);
            fail("Should not allow a single value to be encoded as we don't know which codec to use");
        } catch (Pack200Exception e) {
            // pass
        }
    }
View Full Code Here

                20, 20, 10, 10, 999, 20, 789, 10, 10, 355, 12345 };
        // first 5 of band to be encoded with DELTA5
        byte[] bytes1 = Codec.DELTA5
                .encode(new int[] { 11, 12, 33, 4000, -555 });
        // rest of band to be encoded with a PopulationCodec
        PopulationCodec popCodec = new PopulationCodec(Codec.UNSIGNED5,
                Codec.BYTE1, Codec.UNSIGNED5);
        byte[] bytes2 = popCodec.encode(new int[] { 10, 20 }, new int[] { 0, 1,
                2, 1, 0, 2, 2, 2, 1, 1, 0, 2, 0, 1, 1, 0, 0 }, new int[] { 5,
                3, 999, 789, 355, 12345 });
        byte[] bandEncoded = new byte[bytes1.length + bytes2.length];
        System.arraycopy(bytes1, 0, bandEncoded, 0, bytes1.length);
        System.arraycopy(bytes2, 0, bandEncoded, bytes1.length, bytes2.length);
        RunCodec runCodec = new RunCodec(5, Codec.DELTA5, new PopulationCodec(
                Codec.UNSIGNED5, Codec.BYTE1, Codec.UNSIGNED5));
        int[] bandDecoded = runCodec.decodeInts(band.length,
                new ByteArrayInputStream(bandEncoded));
        assertEquals(band.length, bandDecoded.length);
        for (int i = 0; i < band.length; i++) {
View Full Code Here

        //if(!codecUsed.equals(codec)) {
        //    int bytes = codecUsed.lastBandLength;
        //    System.out.println(count + " " + name + " encoded with " + codecUsed + " "  + bytes);
        //}
        if (codecUsed instanceof PopulationCodec) {
            PopulationCodec popCodec = (PopulationCodec) codecUsed;
            int[] favoured = (int[]) popCodec.getFavoured().clone();
            Arrays.sort(favoured);
            for (int i = 0; i < band.length; i++) {
                boolean favouredValue = Arrays.binarySearch(favoured, band[i]) > -1;
                Codec theCodec = favouredValue ? popCodec.getFavouredCodec()
                        : popCodec.getUnfavouredCodec();
                if (theCodec instanceof BHSDCodec
                        && ((BHSDCodec) theCodec).isDelta()) {
                    BHSDCodec bhsd = (BHSDCodec) theCodec;
                    long cardinality = bhsd.cardinality();
                    while (band[i] > bhsd.largest()) {
View Full Code Here

                while (band[i] < bhsd.smallest()) {
                    band[i] += cardinality;
                }
            }
        } else if (codecUsed instanceof PopulationCodec) {
            PopulationCodec popCodec = (PopulationCodec) codecUsed;
            long[] favoured = (long[]) popCodec.getFavoured().clone();
            Arrays.sort(favoured);
            for (int i = 0; i < band.length; i++) {
                boolean favouredValue = Arrays.binarySearch(favoured, band[i]) > -1;
                Codec theCodec = favouredValue ? popCodec.getFavouredCodec()
                        : popCodec.getUnvafouredCodec();
                if (theCodec instanceof BHSDCodec
                        && ((BHSDCodec) theCodec).isDelta()) {
                    BHSDCodec bhsd = (BHSDCodec) theCodec;
                    long cardinality = bhsd.cardinality();
                    while (band[i] > bhsd.largest()) {
View Full Code Here

                while (band[i] < bhsd.smallest()) {
                    band[i] += cardinality;
                }
            }
        } else if (codecUsed instanceof PopulationCodec) {
            PopulationCodec popCodec = (PopulationCodec) codecUsed;
            long[] favoured = (long[]) popCodec.getFavoured().clone();
            Arrays.sort(favoured);
            for (int i = 0; i < band.length; i++) {
                boolean favouredValue = Arrays.binarySearch(favoured, band[i]) > -1;
                Codec theCodec = favouredValue ? popCodec.getFavouredCodec()
                        : popCodec.getUnvafouredCodec();
                if (theCodec instanceof BHSDCodec
                        && ((BHSDCodec) theCodec).isDelta()) {
                    BHSDCodec bhsd = (BHSDCodec) theCodec;
                    long cardinality = bhsd.cardinality();
                    while (band[i] > bhsd.largest()) {
View Full Code Here

                while (band[i] < bhsd.smallest()) {
                    band[i] += cardinality;
                }
            }
        } else if (codecUsed instanceof PopulationCodec) {
            PopulationCodec popCodec = (PopulationCodec) codecUsed;
            long[] favoured = (long[]) popCodec.getFavoured().clone();
            Arrays.sort(favoured);
            for (int i = 0; i < band.length; i++) {
                boolean favouredValue = Arrays.binarySearch(favoured, band[i]) > -1;
                Codec theCodec = favouredValue ? popCodec.getFavouredCodec()
                        : popCodec.getUnvafouredCodec();
                if (theCodec instanceof BHSDCodec
                        && ((BHSDCodec) theCodec).isDelta()) {
                    BHSDCodec bhsd = (BHSDCodec) theCodec;
                    long cardinality = bhsd.cardinality();
                    while (band[i] > bhsd.largest()) {
View Full Code Here

                while (band[i] < bhsd.smallest()) {
                    band[i] += cardinality;
                }
            }
        } else if (codecUsed instanceof PopulationCodec) {
            PopulationCodec popCodec = (PopulationCodec) codecUsed;
            long[] favoured = (long[]) popCodec.getFavoured().clone();
            Arrays.sort(favoured);
            for (int i = 0; i < band.length; i++) {
                boolean favouredValue = Arrays.binarySearch(favoured, band[i]) > -1;
                Codec theCodec = favouredValue ? popCodec.getFavouredCodec()
                        : popCodec.getUnvafouredCodec();
                if (theCodec instanceof BHSDCodec
                        && ((BHSDCodec) theCodec).isDelta()) {
                    BHSDCodec bhsd = (BHSDCodec) theCodec;
                    long cardinality = bhsd.cardinality();
                    while (band[i] > bhsd.largest()) {
View Full Code Here

                while (band[i] < bhsd.smallest()) {
                    band[i] += cardinality;
                }
            }
        } else if (codecUsed instanceof PopulationCodec) {
            PopulationCodec popCodec = (PopulationCodec) codecUsed;
            long[] favoured = (long[]) popCodec.getFavoured().clone();
            Arrays.sort(favoured);
            for (int i = 0; i < band.length; i++) {
                boolean favouredValue = Arrays.binarySearch(favoured, band[i]) > -1;
                Codec theCodec = favouredValue ? popCodec.getFavouredCodec()
                        : popCodec.getUnvafouredCodec();
                if (theCodec instanceof BHSDCodec
                        && ((BHSDCodec) theCodec).isDelta()) {
                    BHSDCodec bhsd = (BHSDCodec) theCodec;
                    long cardinality = bhsd.cardinality();
                    while (band[i] > bhsd.largest()) {
View Full Code Here

                while (band[i] < bhsd.smallest()) {
                    band[i] += cardinality;
                }
            }
        } else if (codecUsed instanceof PopulationCodec) {
            PopulationCodec popCodec = (PopulationCodec) codecUsed;
            long[] favoured = (long[]) popCodec.getFavoured().clone();
            Arrays.sort(favoured);
            for (int i = 0; i < band.length; i++) {
                boolean favouredValue = Arrays.binarySearch(favoured, band[i]) > -1;
                Codec theCodec = favouredValue ? popCodec.getFavouredCodec()
                        : popCodec.getUnvafouredCodec();
                if (theCodec instanceof BHSDCodec
                        && ((BHSDCodec) theCodec).isDelta()) {
                    BHSDCodec bhsd = (BHSDCodec) theCodec;
                    long cardinality = bhsd.cardinality();
                    while (band[i] > bhsd.largest()) {
View Full Code Here

TOP

Related Classes of org.apache.harmony.pack200.PopulationCodec

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.