Package org.jgroups.util

Examples of org.jgroups.util.ByteArrayDataOutputStream.buffer()


        ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(1024);
        for(int i=0; i < 500; i++) {
            int ch='a' + i;
            out.writeChar(ch);
        }
        ByteArrayDataInputStream in=new ByteArrayDataInputStream(out.buffer());
        for(int i=0; i < 500; i++) {
            char ch=in.readChar();
            assert ch == 'a' + i;
        }
    }
View Full Code Here


    public void testInt() throws IOException {
        ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(1024);
        int[] numbers={Integer.MIN_VALUE, -322649, -500, 0, 1, 100, 322649, Integer.MAX_VALUE};
        for(int i: numbers)
            out.writeInt(i);
        ByteArrayDataInputStream in=new ByteArrayDataInputStream(out.buffer());
        for(int i: numbers) {
            int num=in.readInt();
            assert num == i;
        }
    }
View Full Code Here

    public void testLong() throws IOException {
        ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(1024);
        long[] numbers={Long.MIN_VALUE, -322649, -500, 0, 1, 100, 322649, Long.MAX_VALUE};
        for(long i: numbers)
            out.writeLong(i);
        ByteArrayDataInputStream in=new ByteArrayDataInputStream(out.buffer());
        for(long i: numbers) {
            long num=in.readLong();
            assert num == i;
        }
    }
View Full Code Here

    public void testCompressedLong() throws IOException {
        ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(1024);
        long[] numbers={Long.MIN_VALUE, -500, 0, 1, 100, Long.MAX_VALUE};
        for(long i: numbers)
            Bits.writeLong(i, out);
        ByteArrayDataInputStream in=new ByteArrayDataInputStream(out.buffer());
        for(long i: numbers) {
            long num=Bits.readLong(in);
            assert num == i;
        }
    }
View Full Code Here

    public void testCompressedLongSequence() throws IOException {
        ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(1024);
        long[] numbers={0, 1, 100, 322649, Long.MAX_VALUE-1000};
        for(long i: numbers)
            Bits.writeLongSequence(i, i + 100,out);
        ByteArrayDataInputStream in=new ByteArrayDataInputStream(out.buffer());
        for(long i: numbers) {
            long[] seq=Bits.readLongSequence(in);
            assert Arrays.equals(seq, new long[]{i, i+100});
        }
    }
View Full Code Here

    public void testFloat() throws IOException {
        ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(1024);
        float[] numbers={-322649.25f, 100.7531f, 0f, 1f, 2.75f, 3.1425f, 322649f, 322649.75f};
        for(float i: numbers)
            out.writeFloat(i);
        ByteArrayDataInputStream in=new ByteArrayDataInputStream(out.buffer());
        for(float i: numbers) {
            float num=in.readFloat();
            assert num == i;
        }
    }
View Full Code Here

    public void testDouble() throws IOException {
        ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(1024);
        double[] numbers={-322649.25, 100.7531, 0.0, 1.5, 2.75, 3.1425, 322649, 322649.75};
        for(double i: numbers)
            out.writeDouble(i);
        ByteArrayDataInputStream in=new ByteArrayDataInputStream(out.buffer());
        for(double i: numbers) {
            double num=in.readDouble();
            assert num == i;
        }
    }
View Full Code Here

    public void testWriteBytes() {
        String name="Bela";
        ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(2);
        out.writeBytes(name);
        assert out.position() == name.length();
        ByteArrayDataInputStream in=new ByteArrayDataInputStream(out.buffer());
        byte[] tmp=new byte[name.length()];
        int read=in.read(tmp, 0, tmp.length);
        assert read == name.length();
        assert name.equals(new String(tmp));
    }
View Full Code Here

    public void testWriteChars() throws IOException {
        String name="Bela";
        ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(2);
        out.writeChars(name);
        assert out.position() == name.length() * 2;
        ByteArrayDataInputStream in=new ByteArrayDataInputStream(out.buffer());
        char[] tmp=new char[name.length()];
        for(int i=0; i < name.length(); i++)
            tmp[i]=in.readChar();
        assert name.equals(new String(tmp));

View Full Code Here

    public void testUTF() throws IOException {
        String name="Bela";
        ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(2);
        out.writeUTF(name);
        assert out.position() == name.length() + 2;
        ByteArrayDataInputStream in=new ByteArrayDataInputStream(out.buffer());
        String tmp=in.readUTF();
        assert name.equals(tmp);
    }

    public void testUTFWithDoubleByteChar() throws IOException {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.