Java Byte Array Decompress decompress(byte[] compressed, int sequenceLen)

Here you can find the source of decompress(byte[] compressed, int sequenceLen)

Description

decompress

License

Apache License

Declaration

public static String decompress(byte[] compressed, int sequenceLen) 

Method Source Code

//package com.java2s;
/*// w w w .java  2s.c om
 * Copyright 2015 iychoi.
 *
 * Licensed 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.
 */

public class Main {
    private static char[] convBitToCharLUT = { 'A', 'C', 'G', 'T' };

    public static String decompress(byte[] compressed, int sequenceLen) {
        byte[] byteArr = new byte[sequenceLen];

        int curRead = 0;

        for (int i = 0; i < compressed.length; i++) {
            byte bits = compressed[i];
            byte a = (byte) ((bits >> 6) & 0x3);
            byte b = (byte) ((bits >> 4) & 0x3);
            byte c = (byte) ((bits >> 2) & 0x3);
            byte d = (byte) (bits & 0x3);

            char cha = convBitToChar(a);
            char chb = convBitToChar(b);
            char chc = convBitToChar(c);
            char chd = convBitToChar(d);

            if (curRead < sequenceLen) {
                byteArr[curRead] = (byte) cha;
                curRead++;
            }
            if (curRead < sequenceLen) {
                byteArr[curRead] = (byte) chb;
                curRead++;
            }
            if (curRead < sequenceLen) {
                byteArr[curRead] = (byte) chc;
                curRead++;
            }
            if (curRead < sequenceLen) {
                byteArr[curRead] = (byte) chd;
                curRead++;
            }
        }

        return new String(byteArr);
    }

    private static char convBitToChar(byte bits) {
        return convBitToCharLUT[bits];
    }
}

Related

  1. decompress(byte src[], int src_off, int src_len, byte dst[], int dst_off, int dst_len)
  2. decompress(byte[] in, int len)
  3. decompress_action(byte[] source)
  4. decompressHuffman(byte[] message, int length)
  5. decompressRTF(byte[] src)