Package java.nio.channels

Examples of java.nio.channels.Pipe


        SecurityManager old = System.getSecurityManager();
        SecurityManager sm = new MockSM();

        try {
            System.setSecurityManager(sm);
            Pipe pipe = Pipe.open();
            assertNotNull(pipe);
        } finally {
            System.setSecurityManager(old);
        }
    }
View Full Code Here


  /**
   * @tests java.nio.channels.Pipe#sink()
   */
  public void test_sink() throws IOException {
    Pipe pipe = Pipe.open();
    SinkChannel sink = pipe.sink();
    assertTrue(sink.isBlocking());
  }
View Full Code Here

  /**
   * @tests java.nio.channels.Pipe#source()
   */
  public void test_source() throws IOException {
    Pipe pipe = Pipe.open();
    SourceChannel source = pipe.source();
    assertTrue(source.isBlocking());
  }
View Full Code Here

    @JRubyMethod(name = "pipe", meta = true, compat = RUBY1_8)
    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.runtime;
        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

    @JRubyMethod(name = "pipe", meta = true, compat = RUBY1_9)
    public static IRubyObject pipe19(ThreadContext context, IRubyObject recv, IRubyObject modes) {
        Ruby runtime = context.runtime;
        try {
            Pipe pipe = Pipe.open();

            RubyIO source = new RubyIO(runtime, pipe.source());
            source.setEncodingFromOptions(EncodingOption.getEncodingOptionFromString(runtime, modes.toString()));
            RubyIO sink = new RubyIO(runtime, pipe.sink());

//            Encoding ascii8bit = context.runtime.getEncodingService().getAscii8bitEncoding();
//            sink.setupReadWriteEncodings(context, ascii8bit, ascii8bit);

            sink.openFile.getMainStreamSafe().setSync(true);
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

    }

    @Test(timeout = 5000)
    public void testWriteToByteChannel() throws IOException {

        final Pipe pipe = Pipe.open();

        executor.execute(new Runnable() {

            @Override
            public void run() {

                try {
                    info.writeTo(pipe.sink());
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });

        final Parsed<SBDInfo> parsed = SBDInfo.readFrom(pipe.source(), FEC_PARAMS);

        if (valid) {
            assertEquals(info, parsed.value());
        }
        else {
View Full Code Here

    }

    @Test(timeout = 5000)
    public void testWriteToByteChannel() throws IOException {

        final Pipe pipe = Pipe.open();

        executor.execute(new Runnable() {

            @Override
            public void run() {

                try {
                    PARAMS.writeTo(pipe.sink());
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });

        final Parsed<FECParameters> parsed = FECParameters.readFrom(pipe.source());

        assertEquals(PARAMS, parsed.value());
    }
View Full Code Here

  // REMIND: create threads and other resources lazily?

  selector = Selector.open();

  Pipe pipe = Pipe.open();
  wakeupPipeSink = pipe.sink();
  wakeupPipeSource = pipe.source();
  wakeupPipeSource.configureBlocking(false);
  wakeupPipeKey = wakeupPipeSource.register(selector,
              SelectionKey.OP_READ);

  for (int i = 0; i < concurrency; i++) {
View Full Code Here

    params2.setAddCollectionHeader(params.isAddCollectionHeader());
    params2.setAddCollectionFooter(params.isAddCollectionFooter());
    params2.setAddDoctype(params.isAddDoctype());
    params2.setProperties(params.getProperties());

    final Pipe pipe = Pipe.open();
    final ConversionTask task = new ConversionTask();
    task.setConverter(this.c1);
    task.setIn(in);
    task.setOut(Channels.newOutputStream(pipe.sink()));
    task.setParams(params1);
    final ExecutorService taskPool = Executors.newSingleThreadExecutor();
    final Future<Exception> f = taskPool.submit(task);
    taskPool.shutdown();
    Exception e1 = null;
    Exception e2 = null;
    try {
      this.c2.convert(Channels.newInputStream(pipe.source()), out,
          params2);
      e1 = f.get();
    } catch (final Exception e) {
      e2 = e;
    }
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.