private static final byte[] encodeString(ByteBuffer string)
    {
        int length = string.array().length;
        int num_digits = 1;
        while((length /= 10) > 0)
        {
            num_digits++;
        }
        byte[] bencoded_string = new byte[length+num_digits+1];
        bencoded_string[num_digits] = (byte)':';
        System.arraycopy(string.array(), 0, bencoded_string, num_digits+1, length);
        for(int i = num_digits-1; i >= 0; i--)
        {
            bencoded_string[i] = (byte)((length % 10)+48);
            length /= 10;
        }
        return bencoded_string;
    }