Examples of BlockingInputStream


Examples of org.jgroups.util.BlockingInputStream

        in.write(buf, 0, buf.length);
    }


    public void testReadOnClosedInputStream() throws IOException {
        final BlockingInputStream in=new BlockingInputStream(100);
        in.close();
        byte[] buf=new byte[100];
        int num=in.read(buf, 0, buf.length);
        assert num == -1 : " expected -1 (EOF) but got " + num;
    }
View Full Code Here

Examples of org.jgroups.util.BlockingInputStream

        assert num == -1 : " expected -1 (EOF) but got " + num;
    }

   
    public void testWriteCloseRead() throws IOException {
        final BlockingInputStream in=new BlockingInputStream(100);
        for(int i=1; i <= 5; i++) {
            byte[] buf=("Hello world " + i).getBytes();
            in.write(buf);
        }
        in.close();

        int size=in.available();
        byte[] buf=new byte[100];
        int num=in.read(buf);
        assert num == size;
    }
View Full Code Here

Examples of org.jgroups.util.BlockingInputStream

        assert num == size;
    }


    public void testWriteCloseRead2() throws IOException {
        final BlockingInputStream in=new BlockingInputStream(100);
        StringBuilder sb=new StringBuilder();
        for(int i=1; i <=10; i++)
            sb.append("Hello world " + i);
        byte[] buffer=sb.toString().getBytes();
        new Writer(in, buffer).start();
        Util.sleep(500);

        byte[] buf=new byte[200];
        int num=in.read(buf);
        assert num == buffer.length;
    }
View Full Code Here

Examples of org.jgroups.util.BlockingInputStream

        int num=in.read(buf);
        assert num == buffer.length;
    }

    public void testWriteCloseRead3() throws IOException {
        final BlockingInputStream in=new BlockingInputStream(300);
        StringBuilder sb=new StringBuilder();
        for(int i=1; i <=10; i++)
            sb.append("Hello world " + i);
        byte[] buffer=sb.toString().getBytes();
        new Writer(in, buffer).execute(); // don't use a separate thread

        byte[] buf=new byte[200];
        int num=in.read(buf);
        assert num == buffer.length;
    }
View Full Code Here

Examples of org.jgroups.util.BlockingInputStream

    }


   
    public void testSimpleTransfer() throws IOException {
        final BlockingInputStream in=new BlockingInputStream(100);
        byte[] buffer=new byte[500];
        for(int i=0; i < buffer.length; i++)
            buffer[i]=(byte)(i % 2 == 0? 0 : 1);
        new Writer(in, buffer).start();
       
        byte[] tmp=new byte[500];
        int offset=0;
        while(true) {
            int bytes=in.read(tmp, offset, tmp.length - offset);
            if(bytes == -1)
                break;
            offset+=bytes;
        }
        System.out.println("read " + offset + " bytes");
View Full Code Here

Examples of org.jgroups.util.BlockingInputStream

        }
    }


    public void testLargeTransfer() throws IOException {
        final BlockingInputStream in=new BlockingInputStream(8192);
        final byte[] buffer=generateBuffer(1000000);
        new Writer(in, buffer).start();

        byte[] tmp=new byte[buffer.length];
        int offset=0;
        while(true) {
            int bytes=in.read(tmp, offset, tmp.length - offset);
            if(bytes == -1)
                break;
            offset+=bytes;
        }
        System.out.println("read " + offset + " bytes");
View Full Code Here

Examples of org.jgroups.util.BlockingInputStream

            assert buffer[i] == tmp[i];
        System.out.println("OK");
    }

    public void testLargeTransfer2() throws IOException {
        final BlockingInputStream in=new BlockingInputStream(8192);
        final byte[] buffer=generateBuffer(1000000);
        new Writer(in, buffer).start();

        byte[] tmp=new byte[buffer.length];
        int bytes=in.read(tmp); // reads 1 million bytes in one go

        System.out.println("read " + bytes + " bytes");
        assert bytes == buffer.length : "read " + bytes + " bytes but expected " + buffer.length;
        System.out.print("Verifying that the buffers are the same: ");
        for(int i=0; i < tmp.length; i++)
View Full Code Here

Examples of org.jgroups.util.BlockingInputStream

            assert buffer[i] == tmp[i];
        System.out.println("OK");
    }

    public void testWriterMultipleChunks() throws Exception {
        final BlockingInputStream in=new BlockingInputStream(100);
        final byte[] buffer=generateBuffer(500);
        Writer writer=new Writer(in, buffer, 5, true);
        writer.start();

        byte[] tmp=new byte[20];
        int num=0;
        while(true) {
            int read=in.read(tmp);
            if(read == -1)
                break;
            num+=read;
        }
        System.out.println("read " + num + " bytes");
View Full Code Here

Examples of org.jgroups.util.BlockingInputStream

        System.out.println("read " + num + " bytes");
        assert num == 5 * buffer.length;
    }

    public void testMultipleWriters() throws Exception {
        final BlockingInputStream in=new BlockingInputStream(100);
        final byte[] buffer=generateBuffer(500);

        final Writer[] writers=new Writer[5];
        for(int i=0; i < writers.length; i++) {
            writers[i]=new Writer(in, buffer, 1, false);
            writers[i].setName("writer-" + (i+1));
            writers[i].start();
        }

        new Thread() {
            public void run() {
                while(true) {
                    boolean all_done=true;
                    for(Writer writer: writers) {
                        if(writer.isAlive()) {
                            all_done=false;
                            break;
                        }
                    }
                    if(all_done) {
                        Util.close(in);
                        return;
                    }
                    else
                        Util.sleep(100);
                }
            }
        }.start();

        byte[] tmp=new byte[400];
        int num=0;
        while(true) {
            int read=in.read(tmp, 0, tmp.length);
            if(read == -1)
                break;
            num+=read;
        }
        System.out.println("read " + num + " bytes");
View Full Code Here

Examples of org.jgroups.util.BlockingInputStream

            assert writer.isAlive() == false;
    }


    public void testWriteExceedingCapacity() throws IOException {
        final BlockingInputStream in=new BlockingInputStream(10);
        new Thread() {
            public void run() {
                byte[] tmp=new byte[20];
                int num=0;
                try {
                    while(true) {
                        int read=in.read(tmp);
                        if(read == -1)
                            break;
                        num+=read;
                    }
                    System.out.println("read " + num + " bytes");
                }
                catch(IOException e) {
                    e.printStackTrace();
                }
            }
        }.start();

        byte[] buffer=new byte[15];
        try {
            in.write(buffer);
        }
        finally {
            Util.close(in);
        }
    }
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.