Package java.nio.channels

Examples of java.nio.channels.Pipe.sink()


  @Test
  public void testInputFlow() throws IOException {
    final Pipe pipeFromDisco = Pipe.open();

    final DiscoWorker discoWorker = new DiscoWorker(pipeFromDisco.source(), new NullByteChannel());
    final SinkChannel disco = pipeFromDisco.sink();

    // Put messages in the input pipeline (from the disco master)
    final String okStr = "OK 4 \"ok\"\n";
    disco.write(ByteBuffer.wrap(okStr.getBytes()));
    final String taskStr = "TASK 327 {\"taskid\":0,\"master\":\"http://lhoersten-66113:8989\",\"disco_port\":8989,\"put_port\":8990,\"ddfs_data\":\"/srv/disco/ddfs\",\"disco_data\":\"/srv/disco/data\",\"mode\":\"map\",\"jobfile\":\"/srv/disco/data/localhost/5a/lhoersten-FunshineSimulator@524:7310e:1cb44/jobfile\",\"jobname\":\"lhoersten-FunshineSimulator@524:7310e:1cb44\",\"host\":\"localhost\"}\n";
View Full Code Here


  @Test
  public void testChannelToString() throws IOException {
    final Pipe pipe = Pipe.open();

    final SinkChannel sink = pipe.sink();
    final String expected = "12345678\n";
    sink.write(ByteBuffer.wrap(expected.getBytes()));

    final String actual = DiscoUtils.channelLineToString(pipe.source());
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 void testSocketIOWithTimeout() throws Exception {
   
    // first open pipe:
    Pipe pipe = Pipe.open();
    Pipe.SourceChannel source = pipe.source();
    Pipe.SinkChannel sink = pipe.sink();
   
    try {
      final InputStream in = new SocketInputStream(source, TIMEOUT);
      OutputStream out = new SocketOutputStream(sink, TIMEOUT);
     
View Full Code Here

        ByteBuffer[] bufArray = { buffer, positionedBuffer };
        boolean[] sinkBlockingMode = { true, true, false, false };
        boolean[] sourceBlockingMode = { true, false, true, false };
        for (int i = 0; i < sinkBlockingMode.length; ++i) {
            Pipe pipe = Pipe.open();
            sink = pipe.sink();
            source = pipe.source();

            sink.configureBlocking(sinkBlockingMode[i]);
            source.configureBlocking(sourceBlockingMode[i]);
View Full Code Here

    public EpollSelectorImpl(SelectorProvider selectorProvider) {
        super(selectorProvider);
        try {
            Pipe mockSelector = selectorProvider.openPipe();
            sink = mockSelector.sink();
            source = mockSelector.source();
            sourcefd = ((FileDescriptorHandler) source).getFD();
            source.configureBlocking(false);

            fileDescriptorClass = sourcefd.getClass();
View Full Code Here

    public SelectorImpl(SelectorProvider selectorProvider) {
        super(selectorProvider);
        try {
            Pipe mockSelector = selectorProvider.openPipe();
            sink = mockSelector.sink();
            source = mockSelector.source();
            sourcefd = ((FileDescriptorHandler) source).getFD();
            source.configureBlocking(false);

            readableFDs = new FileDescriptor[1];
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());
  }

  /**
   * @tests java.nio.channels.Pipe#source()
View Full Code Here

    public SelectorImpl(SelectorProvider selectorProvider) {
        super(selectorProvider);
        try {
            Pipe mockSelector = selectorProvider.openPipe();
            sink = mockSelector.sink();
            source = mockSelector.source();
            sourcefd = ((FileDescriptorHandler) source).getFD();
            source.configureBlocking(false);

            readableFDs = new FileDescriptor[1];
View Full Code Here

  public void testSocketIOWithTimeout() throws IOException {
   
    // first open pipe:
    Pipe pipe = Pipe.open();
    Pipe.SourceChannel source = pipe.source();
    Pipe.SinkChannel sink = pipe.sink();
   
    try {
      InputStream in = new SocketInputStream(source, TIMEOUT);
      OutputStream out = new SocketOutputStream(sink, TIMEOUT);
     
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.