Пример #1
0
    /**/
    public static void main(string[] strarr)
    {
        int num = 16;

        if (strarr.Length == 1)
        {
            num = Integer.parseInt(strarr[0]);
        }
        int num2 = 0;

        while (!BinaryStdIn.IsEmpty)
        {
            if (num == 0)
            {
                BinaryStdIn.readBoolean();
            }
            else
            {
                if (num2 != 0)
                {
                    bool expr_28 = num2 != 0;
                    int  expr_2A = num;
                    if (expr_2A == -1 || (expr_28 ? 1 : 0) % expr_2A == 0)
                    {
                        StdOut.println();
                    }
                }
                if (BinaryStdIn.readBoolean())
                {
                    StdOut.print(1);
                }
                else
                {
                    StdOut.print(0);
                }
            }
            num2++;
        }
        if (num != 0)
        {
            StdOut.println();
        }
        StdOut.println(new StringBuilder().append(num2).append(" bits").toString());
    }
}

public sealed class BinaryIn
{
    private const int EOF = -1;
    private BufferedInputStream @in;
    private int buffer;
    private int N;


    private void fillBuffer()
    {
        try
        {
            this.buffer = [email protected]();
            this.N      = 8;
        }
        catch (IOException arg_1C_0)
        {
            goto IL_20;
        }
        return;

IL_20:
        System.err.println("EOF");
        this.buffer = -1;
        this.N      = -1;
    }

    public virtual bool IsEmpty
    {
        return(this.buffer == -1);
    }


    public virtual char readChar()
    {
        if (this.IsEmpty)
        {
            string arg_12_0 = "Reading from empty input stream";

            throw new RuntimeException(arg_12_0);
        }
        int num;

        if (this.N == 8)
        {
            num = this.buffer;
            this.fillBuffer();
            return((char)(num & 255));
        }
        num   = this.buffer;
        num <<= 8 - this.N;
        int n = this.N;

        this.fillBuffer();
        if (this.IsEmpty)
        {
            string arg_6B_0 = "Reading from empty input stream";

            throw new RuntimeException(arg_6B_0);
        }
        this.N = n;
        num   |= (int)((uint)this.buffer >> this.N);
        return((char)(num & 255));
    }

    public virtual bool readBoolean()
    {
        if (this.IsEmpty)
        {
            string arg_12_0 = "Reading from empty input stream";

            throw new RuntimeException(arg_12_0);
        }
        this.N--;
        int result = ((this.buffer >> this.N & 1) == 1) ? 1 : 0;

        if (this.N == 0)
        {
            this.fillBuffer();
        }
        return(result != 0);
    }

    public virtual int readInt()
    {
        int num = 0;

        for (int i = 0; i < 4; i++)
        {
            int num2 = (int)this.readChar();
            num <<= 8;
            num  |= num2;
        }
        return(num);
    }

    public virtual long readLong()
    {
        long num = 0L;

        for (int i = 0; i < 8; i++)
        {
            int num2 = (int)this.readChar();
            num <<= 8;
            num  |= (long)num2;
        }
        return(num);
    }

    public BinaryIn(string str)
    {
        try
        {
            File file = new File(str);
            if (!file.exists())
            {
                URL uRL = java.lang.Object.instancehelper_getClass(this).getResource(str);
                if (uRL == null)
                {
                    uRL = new URL(str);
                }
                URLConnection uRLConnection = uRL.openConnection();
                InputStream   inputStream   = uRLConnection.getInputStream();
                this.@in = new BufferedInputStream(inputStream);
                this.fillBuffer();
                goto IL_74;
            }
            FileInputStream fileInputStream = new FileInputStream(file);
            this.@in = new BufferedInputStream(fileInputStream);
            this.fillBuffer();
        }
        catch (IOException arg_71_0)
        {
            goto IL_76;
        }
        return;

IL_74:
        return;

IL_76:
        System.err.println(new StringBuilder().append("Could not open ").append(str).toString());
    }

    public BinaryIn()
    {
        BufferedInputStream.__ <clinit>();
        this.@in = new BufferedInputStream(System.@in);
        this.fillBuffer();
    }

    public BinaryIn(InputStream @is)
    {
        this.@in = new BufferedInputStream(@is);
        this.fillBuffer();
    }

    public BinaryIn(Socket s)
    {
        try
        {
            InputStream inputStream = s.getInputStream();
            this.@in = new BufferedInputStream(inputStream);
            this.fillBuffer();
        }
        catch (IOException arg_25_0)
        {
            goto IL_29;
        }
        return;

IL_29:
        System.err.println(new StringBuilder().append("Could not open ").append(s).toString());
    }

    public BinaryIn(URL url)
    {
        try
        {
            URLConnection uRLConnection = url.openConnection();
            InputStream   inputStream   = uRLConnection.getInputStream();
            this.@in = new BufferedInputStream(inputStream);
            this.fillBuffer();
        }
        catch (IOException arg_2C_0)
        {
            goto IL_30;
        }
        return;

IL_30:
        System.err.println(new StringBuilder().append("Could not open ").append(url).toString());
    }

    public virtual bool exists()
    {
        return(this.@in != null);
    }

    public virtual char readChar(int i)
    {
        if (i < 1 || i > 16)
        {
            string arg_28_0 = new StringBuilder().append("Illegal value of r = ").append(i).toString();

            throw new RuntimeException(arg_28_0);
        }
        if (i == 8)
        {
            return(this.readChar());
        }
        int num = 0;

        for (int j = 0; j < i; j++)
        {
            num = (int)((ushort)(num << 1));
            int num2 = this.readBoolean() ? 1 : 0;
            if (num2 != 0)
            {
                num = (int)((ushort)(num | 1));
            }
        }
        return((char)num);
    }

    public virtual string readString()
    {
        if (this.IsEmpty)
        {
            string arg_12_0 = "Reading from empty input stream";

            throw new RuntimeException(arg_12_0);
        }
        StringBuilder stringBuilder = new StringBuilder();

        while (!this.IsEmpty)
        {
            int c = (int)this.readChar();
            stringBuilder.append((char)c);
        }
        return(stringBuilder.toString());
    }

    public virtual short readShort()
    {
        int num = 0;

        for (int i = 0; i < 2; i++)
        {
            int num2 = (int)this.readChar();
            num = (int)((short)(num << 8));
            num = (int)((short)(num | num2));
        }
        return((short)num);
    }

    public virtual int readInt(int i)
    {
        if (i < 1 || i > 32)
        {
            string arg_28_0 = new StringBuilder().append("Illegal value of r = ").append(i).toString();

            throw new RuntimeException(arg_28_0);
        }
        if (i == 32)
        {
            return(this.readInt());
        }
        int num = 0;

        for (int j = 0; j < i; j++)
        {
            num <<= 1;
            int num2 = this.readBoolean() ? 1 : 0;
            if (num2 != 0)
            {
                num |= 1;
            }
        }
        return(num);
    }

    public virtual double readDouble()
    {
        DoubleConverter doubleConverter;

        return(DoubleConverter.ToDouble(this.readLong(), ref doubleConverter));
    }

    public virtual float readFloat()
    {
        FloatConverter floatConverter;

        return(FloatConverter.ToFloat(this.readInt(), ref floatConverter));
    }

    public virtual byte readByte()
    {
        int num = (int)this.readChar();

        return((byte)((sbyte)(num & 255)));
    }

    /**/
    public static void main(string[] strarr)
    {
        BinaryIn binaryIn = new BinaryIn(strarr[0]);

        BinaryOut.__ <clinit>();
        BinaryOut binaryOut = new BinaryOut(strarr[1]);

        while (!binaryIn.IsEmpty)
        {
            int ch = (int)binaryIn.readChar();
            binaryOut.write((char)ch);
        }
        binaryOut.flush();
    }