DataInputStream.avt

Переключить прокрутку окна
Загрузить этот исходный код

/*
    Исходный код среды исполнения ПВТ-ОО.

    Этот исходный код является частью проекта ПВТ-ОО.

    Copyright © 2021 Малик Разработчик

    Это свободная программа: вы можете перераспространять её и/или
    изменять её на условиях Меньшей Стандартной общественной лицензии GNU в том виде,
    в каком она была опубликована Фондом свободного программного обеспечения;
    либо версии 3 лицензии, либо (по вашему выбору) любой более поздней версии.

    Эта программа распространяется в надежде, что она может быть полезна,
    но БЕЗО ВСЯКИХ ГАРАНТИЙ; даже без неявной гарантии ТОВАРНОГО ВИДА
    или ПРИГОДНОСТИ ДЛЯ ОПРЕДЕЛЁННЫХ ЦЕЛЕЙ. Подробнее см. в Меньшей Стандартной
    общественной лицензии GNU.

    Вы должны были получить копию Меньшей Стандартной общественной лицензии GNU
    вместе с этой программой. Если это не так, см.
    <http://www.gnu.org/licenses/>.
*/

package avt.io;

import avt.io.charset.*;

public final class DataInputStream(Object, Closeable, ByteReader, Extendable)
{
    public static DataInputStream create(ByteReader reader, String charsetName) throws UnsupportedCharsetNameException {
        Charset charset = Charset.get(charsetName);
        return new DataInputStream(reader, charset);
    }


    private final ByteReader fldReader;
    private final CustomDataInput fldBigEndian;
    private final CustomDataInput fldLittleEndian;

    public (ByteReader reader): this(reader, Charset.getDefault()) {  }

    public (ByteReader reader, Charset charset) {
        if(charset == null) charset = Charset.getDefault();
        fldReader = reader;
        fldBigEndian = new BigEndianDataInput(reader) { fldCharset = charset };
        fldLittleEndian = new LittleEndianDataInput(reader) { fldCharset = charset };
    }

    public void close() throws IOException { fldReader.close(); }

    public int read() throws IOException { return fldReader.read(); }

    public int read(byte[] dst) throws IOException { return fldReader.read(dst); }

    public int read(byte[] dst, int offset, int length) throws IOException { return fldReader.read(dst, offset, length); }

    public long skip(long bytesQuantity) throws IOException { return fldReader.skip(bytesQuantity); }

    public Extension[] getExtensions() { return fldReader.getExtensions(); }

    public Extension getExtension(Class type) { return fldReader.getExtension(type); }

    public ByteReader reader { read = fldReader }

    public DataInput bigEndianDataInput { read = fldBigEndian }

    public DataInput littleEndianDataInput { read = fldLittleEndian }

    public Charset charset { read = getCharset, write = setCharset }

    private void setCharset(Charset newCharset) {
        if(newCharset == null) newCharset = Charset.getDefault();
        fldLittleEndian.fldCharset = newCharset;
        fldBigEndian.fldCharset = newCharset;
    }

    private Charset getCharset() { return fldBigEndian.fldCharset; }
}

abstract class CustomDataInput(Object, DataInput)
{
    Charset fldCharset;
    final ByteReader fldReader;

    public (ByteReader reader) { fldReader = reader; }

    public abstract char readChar() throws IOException;

    public abstract int readUnsignedShort() throws IOException;

    public abstract int readShort() throws IOException;

    public abstract int readInt() throws IOException;

    public abstract int2 readUnsignedByte2() throws IOException;

    public abstract int2 readUnsignedShort2() throws IOException;

    public abstract int2 readByte2() throws IOException;

    public abstract int2 readShort2() throws IOException;

    public abstract int2 readInt2() throws IOException;

    public abstract int4 readUnsignedByte4() throws IOException;

    public abstract int4 readUnsignedShort4() throws IOException;

    public abstract int4 readByte4() throws IOException;

    public abstract int4 readShort4() throws IOException;

    public abstract int4 readInt4() throws IOException;

    public abstract int8 readUnsignedByte8() throws IOException;

    public abstract int8 readUnsignedShort8() throws IOException;

    public abstract int8 readByte8() throws IOException;

    public abstract int8 readShort8() throws IOException;

    public abstract int8 readInt8() throws IOException;

    public abstract long readLong() throws IOException;

    public abstract long2 readLong2() throws IOException;

    public abstract long4 readLong4() throws IOException;

    public abstract long8 readLong8() throws IOException;

    public abstract float readFloat() throws IOException;

    public abstract float2 readFloat2() throws IOException;

    public abstract float4 readFloat4() throws IOException;

    public abstract float8 readFloat8() throws IOException;

    public abstract double readDouble() throws IOException;

    public abstract double2 readDouble2() throws IOException;

    public abstract double4 readDouble4() throws IOException;

    public abstract double8 readDouble8() throws IOException;

    public abstract real readReal() throws IOException;

    public void readFully(byte[] dst) throws IOException { readFully(dst, 0, dst == null ? 0 : dst.length); }

    public void readFully(byte[] dst, int offset, int length) throws IOException {
        if(dst == null)
        {
            throw new NullPointerException("аргумент dst равен нулевой ссылке");
        }
        Array.checkBounds(dst, offset, length);
        for(ByteReader reader = fldReader, int readed; length > 0; offset += readed, length -= readed)
        {
            if((readed = reader.read(dst, offset, length)) <= 0)
            {
                throw new EndOfStreamException("достигнут конец потока данных");
            }
        }
    }

    public boolean readBoolean() throws IOException {
        int b0 = fldReader.read();
        if(b0 < 0)
        {
            throw new EndOfStreamException("достигнут конец потока данных");
        }
        return (b0 & 0xff) > 0;
    }

    public int readUnsignedByte() throws IOException {
        int b0 = fldReader.read();
        if(b0 < 0)
        {
            throw new EndOfStreamException("достигнут конец потока данных");
        }
        return b0 & 0xff;
    }

    public int readByte() throws IOException {
        int b0 = fldReader.read();
        if(b0 < 0)
        {
            throw new EndOfStreamException("достигнут конец потока данных");
        }
        return (byte) b0;
    }

    public String readUTF() throws IOException {
        int utfLength = readUnsignedShort();
        if(utfLength <= 0) return "";
        byte[] utfData = new byte[utfLength];
        readFully(utfData, 0, utfLength);
        int resultLength = 0;
        char[] resultData = new char[utfLength];
        for(int i = 0; i < utfLength; )
        {
            int b1 = utfData[i] & 0xffi;
            switch(b1 >> 4)
            {
            case 0x00:
            case 0x01:
            case 0x02:
            case 0x03:
            case 0x04:
            case 0x05:
            case 0x06:
            case 0x07:
                i++;
                resultData[resultLength++] = (char) b1;
                break;
            case 0x0c:
            case 0x0d:
                int b2;
                if((i += 2) > utfLength || ((b2 = utfData[i - 1]) & 0xc0) != 0x80)
                {
                    throw new UTFDataFormatException("ошибка в данных, закодированных кодировкой UTF-8");
                }
                resultData[resultLength++] = (char) ((b1 & 0x1f) << 6 | (b2 & 0x3f));
                break;
            case 0x0e:
                int b2;
                int b3;
                if((i += 3) > utfLength || ((b2 = utfData[i - 2]) & 0xc0) != 0x80 || ((b3 = utfData[i - 1]) & 0xc0) != 0x80)
                {
                    throw new UTFDataFormatException("ошибка в данных, закодированных кодировкой UTF-8");
                }
                resultData[resultLength++] = (char) ((b1 & 0x0f) << 12 | (b2 & 0x3f) << 6 | (b3 & 0x3f));
                break;
            default:
                throw new UTFDataFormatException("ошибка в данных, закодированных кодировкой UTF-8");
            }
        }
        return new String(resultData, 0, resultLength);
    }

    public String readln() throws IOException {
        int length = 0;
        byte[] data = new byte[31];
        Charset charset = fldCharset;
        for(byte[] ending = Platform.instance.lineSeparator.toByteArray(charset), int estart = ending[0] & 0xffi, int elength = ending.length, ByteReader reader = fldReader; length < Int.MAX_VALUE; )
        {
            int b0 = reader.read();
            if(b0 == estart)
            {
                for(int i = 1; i < elength; i++)
                {
                    if(reader.read() != (ending[i] & 0xffi))
                    {
                        throw new MalformedLineSeparatorException("неправильный формат конца строки");
                    }
                }
                break;
            }
            if(b0 < 0) break;
            if(length == data.length) Array.copy(data, 0, data = new byte[(length << 1) + 1], 0, length);
            data[length++] = (byte) b0;
        }
        return new String(data, 0, length, charset);
    }

    public String read() throws IOException {
        int length = 0;
        byte[] data = new byte[31];
        Charset charset = fldCharset;
        byte[] ending = Platform.instance.lineSeparator.toByteArray(charset);
        int estart = ending[0] & 0xffi;
        int elength = ending.length;
        ByteReader reader = fldReader;
        do
        {
            int b0 = reader.read();
            if(b0 < 0) return "";
            if(b0 > 0x20)
            {
                data[0] = (byte) b0;
                length = 1;
                break;
            }
        } while(true);
        while(length < Int.MAX_VALUE)
        {
            int b0 = reader.read();
            if(b0 == estart)
            {
                for(int i = 1; i < elength; i++)
                {
                    if(reader.read() != (ending[i] & 0xffi))
                    {
                        throw new MalformedLineSeparatorException("неправильный формат конца строки");
                    }
                }
                break;
            }
            if(b0 <= 0x20) break;
            if(length == data.length) Array.copy(data, 0, data = new byte[(length << 1) + 1], 0, length);
            data[length++] = (byte) b0;
        }
        return new String(data, 0, length, charset);
    }
}

final class BigEndianDataInput(CustomDataInput)
{
    public (ByteReader reader): super(reader) {  }

    public char readChar() throws IOException {
        with(fldReader)
        {
            int b1 = read();
            int b0 = read();
            if((b0 | b1) < 0)
            {
                throw new EndOfStreamException("достигнут конец потока данных");
            }
            return (char) ((b1 & 0xff) << 8 | (b0 & 0xff));
        }
    }

    public int readUnsignedShort() throws IOException {
        with(fldReader)
        {
            int b1 = read();
            int b0 = read();
            if((b0 | b1) < 0)
            {
                throw new EndOfStreamException("достигнут конец потока данных");
            }
            return (b1 & 0xff) << 8 | (b0 & 0xff);
        }
    }

    public int readShort() throws IOException {
        with(fldReader)
        {
            int b1 = read();
            int b0 = read();
            if((b0 | b1) < 0)
            {
                throw new EndOfStreamException("достигнут конец потока данных");
            }
            return (short) ((b1 & 0xff) << 8 | (b0 & 0xff));
        }
    }

    public int readInt() throws IOException {
        with(fldReader)
        {
            int b3 = read();
            int b2 = read();
            int b1 = read();
            int b0 = read();
            if((b0 | b1 | b2 | b3) < 0)
            {
                throw new EndOfStreamException("достигнут конец потока данных");
            }
            return (b3 & 0xff) << 24 | (b2 & 0xff) << 16 | (b1 & 0xff) << 8 | (b0 & 0xff);
        }
    }

    public int2 readUnsignedByte2() throws IOException {
        int b1 = readUnsignedByte();
        int b0 = readUnsignedByte();
        return new int2 { b0, b1 };
    }

    public int2 readUnsignedShort2() throws IOException {
        int s1 = readUnsignedShort();
        int s0 = readUnsignedShort();
        return new int2 { s0, s1 };
    }

    public int2 readByte2() throws IOException {
        int b1 = readByte();
        int b0 = readByte();
        return new int2 { b0, b1 };
    }

    public int2 readShort2() throws IOException {
        int s1 = readShort();
        int s0 = readShort();
        return new int2 { s0, s1 };
    }

    public int2 readInt2() throws IOException {
        int i1 = readInt();
        int i0 = readInt();
        return new int2 { i0, i1 };
    }

    public int4 readUnsignedByte4() throws IOException {
        int b3 = readUnsignedByte();
        int b2 = readUnsignedByte();
        int b1 = readUnsignedByte();
        int b0 = readUnsignedByte();
        return new int4 { b0, b1, b2, b3 };
    }

    public int4 readUnsignedShort4() throws IOException {
        int s3 = readUnsignedShort();
        int s2 = readUnsignedShort();
        int s1 = readUnsignedShort();
        int s0 = readUnsignedShort();
        return new int4 { s0, s1, s2, s3 };
    }

    public int4 readByte4() throws IOException {
        int b3 = readByte();
        int b2 = readByte();
        int b1 = readByte();
        int b0 = readByte();
        return new int4 { b0, b1, b2, b3 };
    }

    public int4 readShort4() throws IOException {
        int s3 = readShort();
        int s2 = readShort();
        int s1 = readShort();
        int s0 = readShort();
        return new int4 { s0, s1, s2, s3 };
    }

    public int4 readInt4() throws IOException {
        int i3 = readInt();
        int i2 = readInt();
        int i1 = readInt();
        int i0 = readInt();
        return new int4 { i0, i1, i2, i3 };
    }

    public int8 readUnsignedByte8() throws IOException {
        int b7 = readUnsignedByte();
        int b6 = readUnsignedByte();
        int b5 = readUnsignedByte();
        int b4 = readUnsignedByte();
        int b3 = readUnsignedByte();
        int b2 = readUnsignedByte();
        int b1 = readUnsignedByte();
        int b0 = readUnsignedByte();
        return new int8 { b0, b1, b2, b3, b4, b5, b6, b7 };
    }

    public int8 readUnsignedShort8() throws IOException {
        int s7 = readUnsignedShort();
        int s6 = readUnsignedShort();
        int s5 = readUnsignedShort();
        int s4 = readUnsignedShort();
        int s3 = readUnsignedShort();
        int s2 = readUnsignedShort();
        int s1 = readUnsignedShort();
        int s0 = readUnsignedShort();
        return new int8 { s0, s1, s2, s3, s4, s5, s6, s7 };
    }

    public int8 readByte8() throws IOException {
        int b7 = readByte();
        int b6 = readByte();
        int b5 = readByte();
        int b4 = readByte();
        int b3 = readByte();
        int b2 = readByte();
        int b1 = readByte();
        int b0 = readByte();
        return new int8 { b0, b1, b2, b3, b4, b5, b6, b7 };
    }

    public int8 readShort8() throws IOException {
        int s7 = readShort();
        int s6 = readShort();
        int s5 = readShort();
        int s4 = readShort();
        int s3 = readShort();
        int s2 = readShort();
        int s1 = readShort();
        int s0 = readShort();
        return new int8 { s0, s1, s2, s3, s4, s5, s6, s7 };
    }

    public int8 readInt8() throws IOException {
        int i7 = readInt();
        int i6 = readInt();
        int i5 = readInt();
        int i4 = readInt();
        int i3 = readInt();
        int i2 = readInt();
        int i1 = readInt();
        int i0 = readInt();
        return new int8 { i0, i1, i2, i3, i4, i5, i6, i7 };
    }

    public long readLong() throws IOException {
        with(fldReader)
        {
            int b7 = read();
            int b6 = read();
            int b5 = read();
            int b4 = read();
            int b3 = read();
            int b2 = read();
            int b1 = read();
            int b0 = read();
            if((b0 | b1 | b2 | b3 | b4 | b5 | b6 | b7) < 0)
            {
                throw new EndOfStreamException("достигнут конец потока данных");
            }
            return (b7 & 0xffL) << 56 | (b6 & 0xffL) << 48 | (b5 & 0xffL) << 40 | (b4 & 0xffL) << 32 | (b3 & 0xffL) << 24 | (b2 & 0xffL) << 16 | (b1 & 0xffL) << 8 | (b0 & 0xffL);
        }
    }

    public long2 readLong2() throws IOException {
        long l1 = readLong();
        long l0 = readLong();
        return new long2 { l0, l1 };
    }

    public long4 readLong4() throws IOException {
        long l3 = readLong();
        long l2 = readLong();
        long l1 = readLong();
        long l0 = readLong();
        return new long4 { l0, l1, l2, l3 };
    }

    public long8 readLong8() throws IOException {
        long l7 = readLong();
        long l6 = readLong();
        long l5 = readLong();
        long l4 = readLong();
        long l3 = readLong();
        long l2 = readLong();
        long l1 = readLong();
        long l0 = readLong();
        return new long8 { l0, l1, l2, l3, l4, l5, l6, l7 };
    }

    public float readFloat() throws IOException {
        with(fldReader)
        {
            int b3 = read();
            int b2 = read();
            int b1 = read();
            int b0 = read();
            if((b0 | b1 | b2 | b3) < 0)
            {
                throw new EndOfStreamException("достигнут конец потока данных");
            }
            return Int.toFloatBits((b3 & 0xff) << 24 | (b2 & 0xff) << 16 | (b1 & 0xff) << 8 | (b0 & 0xff));
        }
    }

    public float2 readFloat2() throws IOException {
        int i1 = readInt();
        int i0 = readInt();
        return Int2.toFloat2Bits(new int2 { i0, i1 });
    }

    public float4 readFloat4() throws IOException {
        int i3 = readInt();
        int i2 = readInt();
        int i1 = readInt();
        int i0 = readInt();
        return Int4.toFloat4Bits(new int4 { i0, i1, i2, i3 });
    }

    public float8 readFloat8() throws IOException {
        int i7 = readInt();
        int i6 = readInt();
        int i5 = readInt();
        int i4 = readInt();
        int i3 = readInt();
        int i2 = readInt();
        int i1 = readInt();
        int i0 = readInt();
        return Int8.toFloat8Bits(new int8 { i0, i1, i2, i3, i4, i5, i6, i7 });
    }

    public double readDouble() throws IOException {
        with(fldReader)
        {
            int b7 = read();
            int b6 = read();
            int b5 = read();
            int b4 = read();
            int b3 = read();
            int b2 = read();
            int b1 = read();
            int b0 = read();
            if((b0 | b1 | b2 | b3 | b4 | b5 | b6 | b7) < 0)
            {
                throw new EndOfStreamException("достигнут конец потока данных");
            }
            return Long.toDoubleBits((b7 & 0xffL) << 56 | (b6 & 0xffL) << 48 | (b5 & 0xffL) << 40 | (b4 & 0xffL) << 32 | (b3 & 0xffL) << 24 | (b2 & 0xffL) << 16 | (b1 & 0xffL) << 8 | (b0 & 0xffL));
        }
    }

    public double2 readDouble2() throws IOException {
        long l1 = readLong();
        long l0 = readLong();
        return Long2.toDouble2Bits(new long2 { l0, l1 });
    }

    public double4 readDouble4() throws IOException {
        long l3 = readLong();
        long l2 = readLong();
        long l1 = readLong();
        long l0 = readLong();
        return Long4.toDouble4Bits(new long4 { l0, l1, l2, l3 });
    }

    public double8 readDouble8() throws IOException {
        long l7 = readLong();
        long l6 = readLong();
        long l5 = readLong();
        long l4 = readLong();
        long l3 = readLong();
        long l2 = readLong();
        long l1 = readLong();
        long l0 = readLong();
        return Long8.toDouble8Bits(new long8 { l0, l1, l2, l3, l4, l5, l6, l7 });
    }

    public real readReal() throws IOException {
        long l1 = readShort();
        long l0 = readLong();
        return Long2.toRealBits(new long2 { l0, l1 });
    }
}

final class LittleEndianDataInput(CustomDataInput)
{
    public (ByteReader reader): super(reader) {  }

    public char readChar() throws IOException {
        with(fldReader)
        {
            int b0 = read();
            int b1 = read();
            if((b0 | b1) < 0)
            {
                throw new EndOfStreamException("достигнут конец потока данных");
            }
            return (char) ((b1 & 0xff) << 8 | (b0 & 0xff));
        }
    }

    public int readUnsignedShort() throws IOException {
        with(fldReader)
        {
            int b0 = read();
            int b1 = read();
            if((b0 | b1) < 0)
            {
                throw new EndOfStreamException("достигнут конец потока данных");
            }
            return (b1 & 0xff) << 8 | (b0 & 0xff);
        }
    }

    public int readShort() throws IOException {
        with(fldReader)
        {
            int b0 = read();
            int b1 = read();
            if((b0 | b1) < 0)
            {
                throw new EndOfStreamException("достигнут конец потока данных");
            }
            return (short) ((b1 & 0xff) << 8 | (b0 & 0xff));
        }
    }

    public int readInt() throws IOException {
        with(fldReader)
        {
            int b0 = read();
            int b1 = read();
            int b2 = read();
            int b3 = read();
            if((b0 | b1 | b2 | b3) < 0)
            {
                throw new EndOfStreamException("достигнут конец потока данных");
            }
            return (b3 & 0xff) << 24 | (b2 & 0xff) << 16 | (b1 & 0xff) << 8 | (b0 & 0xff);
        }
    }

    public int2 readUnsignedByte2() throws IOException {
        int b0 = readUnsignedByte();
        int b1 = readUnsignedByte();
        return new int2 { b0, b1 };
    }

    public int2 readUnsignedShort2() throws IOException {
        int s0 = readUnsignedShort();
        int s1 = readUnsignedShort();
        return new int2 { s0, s1 };
    }

    public int2 readByte2() throws IOException {
        int b0 = readByte();
        int b1 = readByte();
        return new int2 { b0, b1 };
    }

    public int2 readShort2() throws IOException {
        int s0 = readShort();
        int s1 = readShort();
        return new int2 { s0, s1 };
    }

    public int2 readInt2() throws IOException {
        int i0 = readInt();
        int i1 = readInt();
        return new int2 { i0, i1 };
    }

    public int4 readUnsignedByte4() throws IOException {
        int b0 = readUnsignedByte();
        int b1 = readUnsignedByte();
        int b2 = readUnsignedByte();
        int b3 = readUnsignedByte();
        return new int4 { b0, b1, b2, b3 };
    }

    public int4 readUnsignedShort4() throws IOException {
        int s0 = readUnsignedShort();
        int s1 = readUnsignedShort();
        int s2 = readUnsignedShort();
        int s3 = readUnsignedShort();
        return new int4 { s0, s1, s2, s3 };
    }

    public int4 readByte4() throws IOException {
        int b0 = readByte();
        int b1 = readByte();
        int b2 = readByte();
        int b3 = readByte();
        return new int4 { b0, b1, b2, b3 };
    }

    public int4 readShort4() throws IOException {
        int s0 = readShort();
        int s1 = readShort();
        int s2 = readShort();
        int s3 = readShort();
        return new int4 { s0, s1, s2, s3 };
    }

    public int4 readInt4() throws IOException {
        int i0 = readInt();
        int i1 = readInt();
        int i2 = readInt();
        int i3 = readInt();
        return new int4 { i0, i1, i2, i3 };
    }

    public int8 readUnsignedByte8() throws IOException {
        int b0 = readUnsignedByte();
        int b1 = readUnsignedByte();
        int b2 = readUnsignedByte();
        int b3 = readUnsignedByte();
        int b4 = readUnsignedByte();
        int b5 = readUnsignedByte();
        int b6 = readUnsignedByte();
        int b7 = readUnsignedByte();
        return new int8 { b0, b1, b2, b3, b4, b5, b6, b7 };
    }

    public int8 readUnsignedShort8() throws IOException {
        int s0 = readUnsignedShort();
        int s1 = readUnsignedShort();
        int s2 = readUnsignedShort();
        int s3 = readUnsignedShort();
        int s4 = readUnsignedShort();
        int s5 = readUnsignedShort();
        int s6 = readUnsignedShort();
        int s7 = readUnsignedShort();
        return new int8 { s0, s1, s2, s3, s4, s5, s6, s7 };
    }

    public int8 readByte8() throws IOException {
        int b0 = readByte();
        int b1 = readByte();
        int b2 = readByte();
        int b3 = readByte();
        int b4 = readByte();
        int b5 = readByte();
        int b6 = readByte();
        int b7 = readByte();
        return new int8 { b0, b1, b2, b3, b4, b5, b6, b7 };
    }

    public int8 readShort8() throws IOException {
        int s0 = readShort();
        int s1 = readShort();
        int s2 = readShort();
        int s3 = readShort();
        int s4 = readShort();
        int s5 = readShort();
        int s6 = readShort();
        int s7 = readShort();
        return new int8 { s0, s1, s2, s3, s4, s5, s6, s7 };
    }

    public int8 readInt8() throws IOException {
        int i0 = readInt();
        int i1 = readInt();
        int i2 = readInt();
        int i3 = readInt();
        int i4 = readInt();
        int i5 = readInt();
        int i6 = readInt();
        int i7 = readInt();
        return new int8 { i0, i1, i2, i3, i4, i5, i6, i7 };
    }

    public long readLong() throws IOException {
        with(fldReader)
        {
            int b0 = read();
            int b1 = read();
            int b2 = read();
            int b3 = read();
            int b4 = read();
            int b5 = read();
            int b6 = read();
            int b7 = read();
            if((b0 | b1 | b2 | b3 | b4 | b5 | b6 | b7) < 0)
            {
                throw new EndOfStreamException("достигнут конец потока данных");
            }
            return (b7 & 0xffL) << 56 | (b6 & 0xffL) << 48 | (b5 & 0xffL) << 40 | (b4 & 0xffL) << 32 | (b3 & 0xffL) << 24 | (b2 & 0xffL) << 16 | (b1 & 0xffL) << 8 | (b0 & 0xffL);
        }
    }

    public long2 readLong2() throws IOException {
        long l0 = readLong();
        long l1 = readLong();
        return new long2 { l0, l1 };
    }

    public long4 readLong4() throws IOException {
        long l0 = readLong();
        long l1 = readLong();
        long l2 = readLong();
        long l3 = readLong();
        return new long4 { l0, l1, l2, l3 };
    }

    public long8 readLong8() throws IOException {
        long l0 = readLong();
        long l1 = readLong();
        long l2 = readLong();
        long l3 = readLong();
        long l4 = readLong();
        long l5 = readLong();
        long l6 = readLong();
        long l7 = readLong();
        return new long8 { l0, l1, l2, l3, l4, l5, l6, l7 };
    }

    public float readFloat() throws IOException {
        with(fldReader)
        {
            int b0 = read();
            int b1 = read();
            int b2 = read();
            int b3 = read();
            if((b0 | b1 | b2 | b3) < 0)
            {
                throw new EndOfStreamException("достигнут конец потока данных");
            }
            return Int.toFloatBits((b3 & 0xff) << 24 | (b2 & 0xff) << 16 | (b1 & 0xff) << 8 | (b0 & 0xff));
        }
    }

    public float2 readFloat2() throws IOException {
        int i0 = readInt();
        int i1 = readInt();
        return Int2.toFloat2Bits(new int2 { i0, i1 });
    }

    public float4 readFloat4() throws IOException {
        int i0 = readInt();
        int i1 = readInt();
        int i2 = readInt();
        int i3 = readInt();
        return Int4.toFloat4Bits(new int4 { i0, i1, i2, i3 });
    }

    public float8 readFloat8() throws IOException {
        int i0 = readInt();
        int i1 = readInt();
        int i2 = readInt();
        int i3 = readInt();
        int i4 = readInt();
        int i5 = readInt();
        int i6 = readInt();
        int i7 = readInt();
        return Int8.toFloat8Bits(new int8 { i0, i1, i2, i3, i4, i5, i6, i7 });
    }

    public double readDouble() throws IOException {
        with(fldReader)
        {
            int b0 = read();
            int b1 = read();
            int b2 = read();
            int b3 = read();
            int b4 = read();
            int b5 = read();
            int b6 = read();
            int b7 = read();
            if((b0 | b1 | b2 | b3 | b4 | b5 | b6 | b7) < 0)
            {
                throw new EndOfStreamException("достигнут конец потока данных");
            }
            return Long.toDoubleBits((b7 & 0xffL) << 56 | (b6 & 0xffL) << 48 | (b5 & 0xffL) << 40 | (b4 & 0xffL) << 32 | (b3 & 0xffL) << 24 | (b2 & 0xffL) << 16 | (b1 & 0xffL) << 8 | (b0 & 0xffL));
        }
    }

    public double2 readDouble2() throws IOException {
        long l0 = readLong();
        long l1 = readLong();
        return Long2.toDouble2Bits(new long2 { l0, l1 });
    }

    public double4 readDouble4() throws IOException {
        long l0 = readLong();
        long l1 = readLong();
        long l2 = readLong();
        long l3 = readLong();
        return Long4.toDouble4Bits(new long4 { l0, l1, l2, l3 });
    }

    public double8 readDouble8() throws IOException {
        long l0 = readLong();
        long l1 = readLong();
        long l2 = readLong();
        long l3 = readLong();
        long l4 = readLong();
        long l5 = readLong();
        long l6 = readLong();
        long l7 = readLong();
        return Long8.toDouble8Bits(new long8 { l0, l1, l2, l3, l4, l5, l6, l7 });
    }

    public real readReal() throws IOException {
        long l0 = readLong();
        long l1 = readShort();
        return Long2.toRealBits(new long2 { l0, l1 });
    }
}