java.nio.channels.Pipe.sink()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(6.1k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中java.nio.channels.Pipe.sink()方法的一些代码示例,展示了Pipe.sink()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Pipe.sink()方法的具体详情如下:
包路径:java.nio.channels.Pipe
类名称:Pipe
方法名:sink

Pipe.sink介绍

[英]Returns the sink channel of the pipe.
[中]返回管道的水槽通道。

代码示例

代码示例来源:origin: wildfly/wildfly

try {
  topPipe.source().configureBlocking(false);
  topPipe.sink().configureBlocking(false);
  final Pipe bottomPipe = Pipe.open();
  try {
    bottomPipe.source().configureBlocking(false);
    bottomPipe.sink().configureBlocking(false);
    final WorkerThread peerThread = getPeerThread(peer);
    final SelectionKey topSourceKey = registerChannel(topPipe.source());
    final SelectionKey topSinkKey = peerThread.registerChannel(topPipe.sink());
    final SelectionKey bottomSourceKey = peerThread.registerChannel(bottomPipe.source());
    final SelectionKey bottomSinkKey = registerChannel(bottomPipe.sink());
    final NioPipeStreamConnection leftConnection = new NioPipeStreamConnection(this, bottomSourceKey, topSinkKey);
    final NioPipeStreamConnection rightConnection = new NioPipeStreamConnection(this, topSourceKey, bottomSinkKey);
  } finally {
    if (! ok) {
      safeClose(bottomPipe.sink());
      safeClose(bottomPipe.source());
    safeClose(topPipe.sink());
    safeClose(topPipe.source());

代码示例来源:origin: wildfly/wildfly

public ChannelPipe<StreamSourceChannel, StreamSinkChannel> createHalfDuplexPipe(final XnioIoFactory peer) throws IOException {
  getWorker().checkShutdown();
  final Pipe pipe = Pipe.open();
  boolean ok = false;
  try {
    pipe.source().configureBlocking(false);
    pipe.sink().configureBlocking(false);
    final WorkerThread peerThread = getPeerThread(peer);
    final SelectionKey readKey = registerChannel(pipe.source());
    final SelectionKey writeKey = peerThread.registerChannel(pipe.sink());
    final NioPipeStreamConnection leftConnection = new NioPipeStreamConnection(this, readKey, null);
    final NioPipeStreamConnection rightConnection = new NioPipeStreamConnection(this, null, writeKey);
    leftConnection.writeClosed();
    rightConnection.readClosed();
    final ChannelPipe<StreamSourceChannel,StreamSinkChannel> result = new ChannelPipe<StreamSourceChannel, StreamSinkChannel>(leftConnection.getSourceChannel(), rightConnection.getSinkChannel());
    ok = true;
    return result;
  } finally {
    if (! ok) {
      safeClose(pipe.sink());
      safeClose(pipe.source());
    }
  }
}

代码示例来源:origin: de.julielab/julie-xml-tools

/**
 * write the segment (denoted by its offset and length) into an output file
 * stream
 */
public void writeToPipe(Pipe pipe, long os, long len)
    throws java.io.IOException {
  SinkChannel sinkChannel = pipe.sink();
  fc.transferTo(os, len, sinkChannel);
}

代码示例来源:origin: org.jruby/jruby-complete

public Object call() throws Exception {
    try {
      selector.select();
    } finally {
      ByteBuffer buf = ByteBuffer.allocate(1);
      buf.put((byte) 0);
      buf.flip();
      pipe.sink().write(buf);
    }
    return null;
  }
}

代码示例来源:origin: org.jruby/jruby-complete

public Object call() throws Exception {
  try {
    selector.select();
  } finally {
    ByteBuffer buf = ByteBuffer.allocate(1);
    buf.put((byte) 0);
    buf.flip();
    pipe.sink().write(buf);
  }
  return null;
}

代码示例来源:origin: org.jruby/jruby-core

public Object call() throws Exception {
  try {
    selector.select();
  } finally {
    ByteBuffer buf = ByteBuffer.allocate(1);
    buf.put((byte) 0);
    buf.flip();
    pipe.sink().write(buf);
  }
  return null;
}

代码示例来源:origin: org.jruby/jruby-core

public Object call() throws Exception {
    try {
      selector.select();
    } finally {
      ByteBuffer buf = ByteBuffer.allocate(1);
      buf.put((byte) 0);
      buf.flip();
      pipe.sink().write(buf);
    }
    return null;
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

public Object call() throws Exception {
    try {
      selector.select();
    } finally {
      ByteBuffer buf = ByteBuffer.allocate(1);
      buf.put((byte) 0);
      buf.flip();
      pipe.sink().write(buf);
    }
    return null;
  }
}

代码示例来源:origin: Refinitiv/Elektron-SDK

void pipeWrite() throws IOException
{
  if (_pipeWriteCount.incrementAndGet() == 1)
    _pipe.sink().write(ByteBuffer.wrap(_pipeWriteByte));
}

代码示例来源:origin: org.restlet/org.restlet

public void run() {
    try {
      final WritableByteChannel wbc = pipe.sink();
      representation.write(wbc);
      wbc.close();
    } catch (IOException ioe) {
      Context.getCurrentLogger().log(Level.FINE,
          "Error while writing to the piped channel.", ioe);
    }
  }
});

代码示例来源:origin: org.apache.qpid/proton-j

@Override
public void wakeup() {
  try {
    wakeup.sink().write(ByteBuffer.allocate(1));
  } catch(ClosedChannelException channelClosedException) {
    // Ignore - pipe already closed by reactor being shutdown.
  } catch(IOException ioException) {
    throw new ReactorInternalException(ioException);
  }
}

代码示例来源:origin: org.wymiwyg/wrhapi

public void run() {
    try {
      SinkChannel sinkChannel = pipe.sink();
      writeTo(sinkChannel);
      sinkChannel.close();
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
}.start();

代码示例来源:origin: org.apache.abdera/abdera-i18n

/**
 * Write to the pipe
 */
public int write(ByteBuffer src) throws IOException {
  checkFlipped();
  return pipe.sink().write(src);
}

代码示例来源:origin: org.apache.abdera/abdera-i18n

/**
 * Get a writer that can write to this pipe. The pipe must be writable
 */
public Writer getWriter() {
  checkFlipped();
  return new PipeChannelWriter(this, Channels.newWriter(pipe.sink(), charset));
}

代码示例来源:origin: org.apache.abdera/abdera-i18n

/**
 * True if the pipe is open
 */
public boolean isOpen() {
  return pipe.sink().isOpen() || pipe.source().isOpen();
}

代码示例来源:origin: org.jruby/jruby-core

public void cleanup() throws IOException {
    pipe.sink().close();
    pipe.source().close();
  }
}

代码示例来源:origin: org.jruby/jruby-complete

public void cleanup() throws IOException {
    pipe.sink().close();
    pipe.source().close();
  }
}

代码示例来源:origin: org.apache.abdera/abdera-i18n

/**
 * Get an outputstream that can write to this pipe. The Pipe must be writable
 */
public OutputStream getOutputStream() {
  checkFlipped();
  return new PipeChannelOutputStream(this, Channels.newOutputStream(pipe.sink()));
}

代码示例来源:origin: jenkinsci/remoting

@After
public void tearDownPipe() throws Exception {
  IOUtils.closeQuietly(clientToServer.sink());
  IOUtils.closeQuietly(clientToServer.source());
  IOUtils.closeQuietly(serverToClient.sink());
  IOUtils.closeQuietly(serverToClient.source());
}

代码示例来源:origin: org.netbeans.api/org-jruby

@JRubyMethod(name = "pipe", meta = true)
public static IRubyObject pipe(ThreadContext context, IRubyObject recv) throws Exception {
  // TODO: This isn't an exact port of MRI's pipe behavior, so revisit
  Ruby runtime = context.getRuntime();
  Pipe pipe = Pipe.open();
    RubyIO source = new RubyIO(runtime, pipe.source());
  RubyIO sink = new RubyIO(runtime, pipe.sink());
    sink.openFile.getMainStream().setSync(true);
  return runtime.newArrayNoCopy(new IRubyObject[] { source, sink });
}

相关文章