Example #1
0
 /**
  * Reads a binary sequence from standard input; converts each two bits
  * to an 8-bit extended ASCII character over the alphabet { A, C, T, G };
  * and writes the results to standard output.
  */
 public static void expand() {
     Alphabet DNA = Alphabet.DNA;
     int n = BinaryStdIn.readInt();
     // Read two bits; write char. 
     for (int i = 0; i < n; i++) {
         char c = BinaryStdIn.readChar(2);
         BinaryStdOut.write(DNA.toChar(c), 8);
     }
     BinaryStdOut.close();
 }
Example #2
0
 /**
  * Reads a sequence of bits from standard input (that are encoded
  * using run-length encoding with 8-bit run lengths); decodes them;
  * and writes the results to standard output.
  */
 public static void expand() { 
     boolean b = false; 
     while (!BinaryStdIn.isEmpty()) {
         int run = BinaryStdIn.readInt(LG_R);
         for (int i = 0; i < run; i++)
             BinaryStdOut.write(b);
         b = !b;
     }
     BinaryStdOut.close();
 }
Example #3
0
        public static void expand()
        {
            int num = 0;

            while (!BinaryStdIn.IsEmpty)
            {
                int num2 = BinaryStdIn.readInt(8);
                for (int i = 0; i < num2; i++)
                {
                    BinaryStdOut.write(num != 0);
                }
                num = ((num != 0) ? 0 : 1);
            }
            BinaryStdOut.close();
        }
Example #4
0
    /**
     * Reads a sequence of bits that represents a Huffman-compressed message from
     * standard input; expands them; and writes the results to standard output.
     */
    public static void expand() {

        // read in Huffman trie from input stream
        Node root = readTrie(); 

        // number of bytes to write
        int length = BinaryStdIn.readInt();

        // decode using the Huffman trie
        for (int i = 0; i < length; i++) {
            Node x = root;
            while (!x.isLeaf()) {
                boolean bit = BinaryStdIn.readBoolean();
                if (bit) x = x.right;
                else     x = x.left;
            }
            BinaryStdOut.write(x.ch, 8);
        }
        BinaryStdOut.close();
    }
Example #5
0
    public static void expand()
    {
        string[] array = new string[4096];
        int      i;

        for (i = 0; i < 256; i++)
        {
            array[i] = new StringBuilder().append("").append((char)i).toString();
        }
        string[] arg_44_0 = array;
        int      arg_44_1 = i;

        i++;
        arg_44_0[arg_44_1] = "";
        int    num  = BinaryStdIn.readInt(12);
        string text = array[num];

        while (true)
        {
            BinaryStdOut.write(text);
            num = BinaryStdIn.readInt(12);
            if (num == 256)
            {
                break;
            }
            string text2 = array[num];
            if (i == num)
            {
                text2 = new StringBuilder().append(text).append(java.lang.String.instancehelper_charAt(text, 0)).toString();
            }
            if (i < 4096)
            {
                string[] arg_BE_0 = array;
                int      arg_BE_1 = i;
                i++;
                arg_BE_0[arg_BE_1] = new StringBuilder().append(text).append(java.lang.String.instancehelper_charAt(text2, 0)).toString();
            }
            text = text2;
        }
        BinaryStdOut.close();
    }
Example #6
0
    /**
     * Reads a sequence of bit encoded using LZW compression with
     * 12-bit codewords from standard input; expands them; and writes
     * the results to standard output.
     */
    public static void expand() {
        String[] st = new String[L];
        int i; // next available codeword value

        // initialize symbol table with all 1-character strings
        for (i = 0; i < R; i++)
            st[i] = "" + (char) i;
        st[i++] = "";                        // (unused) lookahead for EOF

        int codeword = BinaryStdIn.readInt(W);
        if (codeword == R) return;           // expanded message is empty string
        String val = st[codeword];

        while (true) {
            BinaryStdOut.write(val);
            codeword = BinaryStdIn.readInt(W);
            if (codeword == R) break;
            String s = st[codeword];
            if (i == codeword) s = val + val.charAt(0);   // special case hack
            if (i < L) st[i++] = val + s.charAt(0);
            val = s;
        }
        BinaryStdOut.close();
    }