Package java.nio.channels

Examples of java.nio.channels.Pipe


        }
    }

    public PipeImpl() throws IOException {
        if (useNative) {
            Pipe pipe = Pipe.open();
            source = pipe.source();
            sink = pipe.sink();

        } else {
            PipedInputStream pipedIn = new PipedInputStream();
            try {
                pipedOut = new PipedOutputStream(pipedIn);
View Full Code Here


    @JRubyMethod(name = "pipe", meta = true)
    public static IRubyObject pipe(ThreadContext context, IRubyObject recv) {
        // TODO: This isn't an exact port of MRI's pipe behavior, so revisit
        Ruby runtime = context.getRuntime();
        try {
            Pipe pipe = Pipe.open();

            RubyIO source = new RubyIO(runtime, pipe.source());
            RubyIO sink = new RubyIO(runtime, pipe.sink());

            sink.openFile.getMainStreamSafe().setSync(true);
            return runtime.newArrayNoCopy(new IRubyObject[]{source, sink});
        } catch (BadDescriptorException e) {
            throw runtime.newErrnoEBADFError();
View Full Code Here

  @Test
  public void testUnzipZipInputStreamFile() throws IOException {
    // Test on an unseekable input steam
    File targetFolder = _temporaryFolder.newFolder("unpacked4");

    final Pipe zipPipe = Pipe.open();
    final SinkChannel sink = zipPipe.sink();
    final SourceChannel source = zipPipe.source();
    final InputStream sourceIn = Channels.newInputStream(source);
    final OutputStream sourceOut = Channels.newOutputStream(sink);
    final ZipInputStream zis = new ZipInputStream(sourceIn);
    final FileInputStream fis = new FileInputStream(TestResources.SHARD1);
    final AtomicBoolean failed = new AtomicBoolean(false);
View Full Code Here

        super();
        this.logger = logger;
        try
        {
            Pipe p = Pipe.open();
            SinkChannel sink = p.sink();
            SourceChannel source = p.source();
            writer = Channels.newWriter( sink, Charset.defaultCharset().name() );
            reader = Channels.newReader( source, Charset.defaultCharset().name() );
            parser.setInput( reader );

        }
View Full Code Here

        }
    }

    public PipeImpl() throws IOException {
        if (useNative) {
            Pipe pipe = Pipe.open();
            source = pipe.source();
            sink = pipe.sink();

        } else {
            PipedInputStream pipedIn = new PipedInputStream();
            try {
                pipedOut = new PipedOutputStream(pipedIn);
View Full Code Here

        }
    }

    public PipeImpl() throws IOException {
        if (useNative) {
            Pipe pipe = Pipe.open();
            source = pipe.source();
            sink = pipe.sink();

        } else {
            PipedInputStream pipedIn = new PipedInputStream();
            try {
                pipedOut = new PipedOutputStream(pipedIn);
View Full Code Here

        done.await(5000, TimeUnit.MILLISECONDS));
  }

  @Test
  public void testNewPipeBlockingSemantics() throws IOException {
    Pipe pipe = Pipe.open();
    ByteBuffer buf = ByteBuffer.allocate(10);
    assertTrue(pipe.source().isBlocking());
    pipe.source().configureBlocking(false);
    assertTrue(!pipe.source().isBlocking());
    int rdSz = pipe.source().read(buf); // this operation blocks!
    assertTrue(rdSz <= 0);
  }
View Full Code Here

    assertTrue(rdSz <= 0);
  }

  @Test
  public void testNewPipePartialReadSemantics() throws IOException {
    Pipe pipe = Pipe.open();
    int sz = 10;
    ByteBuffer buf = ByteBuffer.allocate(sz);
    pipe.sink().write(ByteBuffer.wrap("small".getBytes()));
    int rdSz = pipe.source().read(buf); // this operation blocks!
    assertTrue(rdSz <= sz);
  }
View Full Code Here

     */
    public void test_cancelledKeys() throws Exception {
        final AtomicReference<Throwable> failure = new AtomicReference<Throwable>();
        final AtomicBoolean complete = new AtomicBoolean();

        final Pipe pipe = Pipe.open();
        pipe.source().configureBlocking(false);
        final SelectionKey key = pipe.source().register(selector, SelectionKey.OP_READ);

        Thread thread = new Thread() {
            public void run() {
                try {
                    // make sure to call key.cancel() while the main thread is selecting
                    Thread.sleep(500);
                    key.cancel();
                    assertFalse(key.isValid());
                    pipe.sink().write(ByteBuffer.allocate(4)); // unblock select()
                } catch (Throwable e) {
                    failure.set(e);
                } finally {
                    complete.set(true);
                }
View Full Code Here

 
  /**
   * @tests java.nio.channels.Pipe#open()
   */
  public void test_open() throws IOException{
    Pipe pipe = Pipe.open();
    assertNotNull(pipe);
  }
View Full Code Here

TOP

Related Classes of java.nio.channels.Pipe

Copyright © 2018 www.massapicom. 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.