Code example for PipedReader

Methods: read

0
        testInterruptOutputStream(out);
    } 
 
    public void testInterruptPipedReader() throws Exception { 
        PipedWriter writer = new PipedWriter();
        PipedReader reader = new PipedReader(writer);
        testInterruptReader(reader);
    } 
 
    public void testInterruptPipedWriter() throws Exception { 
        final PipedWriter writer = new PipedWriter();
        new PipedReader(writer);
        testInterruptWriter(writer);
    } 
 
    public void testInterruptReadablePipeChannel() throws Exception { 
        testInterruptReadableChannel(Pipe.open().source());
    } 
 
    public void testInterruptWritablePipeChannel() throws Exception { 
        testInterruptWritableChannel(Pipe.open().sink());
    } 
 
    public void testInterruptReadableSocketChannel() throws Exception { 
        sockets = newSocketChannelPair();
        testInterruptReadableChannel(sockets[0].getChannel());
    } 
 
    public void testInterruptWritableSocketChannel() throws Exception { 
        sockets = newSocketChannelPair();
        testInterruptReadableChannel(sockets[0].getChannel());
    } 
 
    /** 
     * Returns a pair of connected sockets backed by NIO socket channels. 
     */ 
    private Socket[] newSocketChannelPair() throws IOException {
        ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
        serverSocketChannel.socket().bind(new InetSocketAddress(0));
        SocketChannel clientSocketChannel = SocketChannel.open();
        clientSocketChannel.connect(serverSocketChannel.socket().getLocalSocketAddress());
        SocketChannel server = serverSocketChannel.accept();
        serverSocketChannel.close();
        return new Socket[] { clientSocketChannel.socket(), server.socket() };
    } 
 
    private void testInterruptInputStream(final InputStream in) throws Exception {
        interruptMeLater(); 
        try { 
            in.read();
            fail();
        } catch (InterruptedIOException expected) {
        } 
    } 
 
    private void testInterruptReader(final PipedReader reader) throws Exception {
        interruptMeLater(); 
        try { 
            reader.read();
            fail();
        } catch (InterruptedIOException expected) {
        } 
    }