本文整理汇总了Java中java.nio.channels.Pipe.SinkChannel类的典型用法代码示例。如果您正苦于以下问题:Java SinkChannel类的具体用法?Java SinkChannel怎么用?Java SinkChannel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SinkChannel类属于java.nio.channels.Pipe包,在下文中一共展示了SinkChannel类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import java.nio.channels.Pipe.SinkChannel; //导入依赖的package包/类
private void run() throws Exception
{
NioThread nt=new NioThread();
final Socket s=new Socket("localhost", 9999);
SourceChannel in=ConnectNio.inputStreamToPipe(s.getInputStream());
in.configureBlocking(false);
SinkChannel out=ConnectNio.outputStreamToPipe(s.getOutputStream(), s);
out.configureBlocking(false);
DualChannelProcessorMultiplexer multiplexer=new DualChannelProcessorMultiplexer(nt, in, out, false,
CoolRMINioRemoter.clientId, CoolRMINioRemoter.serverId);
CoolRMINioClient cli=new CoolRMINioClient(getClass().getClassLoader(), false);
cli.connect(multiplexer);
multiplexer.start();
nt.start();
Iremote r= (Iremote)cli.getService(Iremote.class, Iremote.class.getName());
System.out.println(""+r.getValue("Kitten"));
System.out.println(""+r.getValue("Kitten"));
System.out.println(""+r.getValue("Kitten"));
System.out.println(""+r.getValue("Kitten"));
cli.close();
nt.close();
}
示例2: testStagingPreservesClasspath
import java.nio.channels.Pipe.SinkChannel; //导入依赖的package包/类
@Test
public void testStagingPreservesClasspath() throws Exception {
File smallFile = makeFileWithContents("small.txt", "small");
File largeFile = makeFileWithContents("large.txt", "large contents");
when(mockGcsUtil.getObjects(anyListOf(GcsPath.class)))
.thenReturn(ImmutableList.of(StorageObjectOrIOException.create(
new FileNotFoundException("some/path"))));
when(mockGcsUtil.create(any(GcsPath.class), anyString()))
.thenAnswer(new Answer<SinkChannel>() {
@Override
public SinkChannel answer(InvocationOnMock invocation) throws Throwable {
return Pipe.open().sink();
}
});
List<DataflowPackage> targets =
defaultPackageUtil.stageClasspathElements(
ImmutableList.of(smallFile.getAbsolutePath(), largeFile.getAbsolutePath()),
STAGING_PATH,
createOptions);
// Verify that the packages are returned small, then large, matching input order even though
// the large file would be uploaded first.
assertThat(targets.get(0).getName(), startsWith("small"));
assertThat(targets.get(1).getName(), startsWith("large"));
}
示例3: isOpen
import java.nio.channels.Pipe.SinkChannel; //导入依赖的package包/类
private boolean isOpen(Object resource) {
if (resource instanceof SourceChannel) {
return ((SourceChannel)resource).isOpen();
} else if (resource instanceof SinkChannel) {
return ((SinkChannel)resource).isOpen();
} else if (resource instanceof Selector) {
return ((Selector)resource).isOpen();
} else if (resource instanceof ServerSocketChannel) {
return ((ServerSocketChannel)resource).isOpen();
} else if (resource instanceof SocketChannel) {
return ((SocketChannel)resource).isOpen();
} else {
throw new AssertionFailedError("Don't know how to check if this type is open: " + resource.getClass());
}
}
示例4: testConstructor
import java.nio.channels.Pipe.SinkChannel; //导入依赖的package包/类
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "SinkChannel",
args = {java.nio.channels.spi.SelectorProvider.class}
)
public void testConstructor() throws IOException {
SinkChannel channel =
SelectorProvider.provider().openPipe().sink();
assertNotNull(channel);
assertSame(SelectorProvider.provider(),channel.provider());
channel = Pipe.open().sink();
assertNotNull(channel);
assertSame(SelectorProvider.provider(),channel.provider());
}
示例5: test_sink
import java.nio.channels.Pipe.SinkChannel; //导入依赖的package包/类
/**
* @tests java.nio.channels.Pipe#sink()
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "sink",
args = {}
)
public void test_sink() throws IOException {
Pipe pipe = Pipe.open();
SinkChannel sink = pipe.sink();
assertTrue(sink.isBlocking());
}
示例6: HandshakeHandler
import java.nio.channels.Pipe.SinkChannel; //导入依赖的package包/类
HandshakeHandler(boolean clientMode, SourceChannel in, SinkChannel out)
throws SSLException {
this.in = in;
this.out = out;
engine = getEngine();
engine.setUseClientMode(clientMode);
String[] cipherSuites = engine.getSupportedCipherSuites();
Set<String> enabledSuites = new HashSet<String>();
for (String cipherSuite : cipherSuites) {
if (cipherSuite.contains("anon")) {
enabledSuites.add(cipherSuite);
}
}
engine.setEnabledCipherSuites((String[]) enabledSuites.toArray(
new String[enabledSuites.size()]));
engine.beginHandshake();
status = engine.getHandshakeStatus();
if (clientMode) {
LOGTAG = "CLIENT: ";
} else {
LOGTAG = "SERVER: ";
}
log("CipherSuites: " + Arrays.toString(engine.getEnabledCipherSuites()));
log(status);
readBuffer = ByteBuffer.allocate(200000);
writeBuffer = ByteBuffer.allocate(20000);
}
示例7: prepareEngines
import java.nio.channels.Pipe.SinkChannel; //导入依赖的package包/类
void prepareEngines() throws IOException {
Pipe clientSendPipe = Pipe.open();
Pipe serverSendPipe = Pipe.open();
SinkChannel clientSink = clientSendPipe.sink();
SourceChannel serverSource = clientSendPipe.source();
SinkChannel serverSink = serverSendPipe.sink();
SourceChannel clientSource = serverSendPipe.source();
clientEngine = new HandshakeHandler(true, clientSource, clientSink);
serverEngine = new HandshakeHandler(false, serverSource, serverSink);
}
示例8: PipeSelectableChannel
import java.nio.channels.Pipe.SinkChannel; //导入依赖的package包/类
PipeSelectableChannel(final SinkChannel out, final SourceChannel in) {
if (out == null) {
throw new NullPointerException("out == null");
}
if (in == null) {
throw new NullPointerException("in == null");
}
if ((in.validOps() & out.validOps()) != 0) {
throw new IllegalArgumentException("sink and source have overlapping validOps");
}
this.out = out;
this.in = in;
}
示例9: EchoInputStreamWrapper
import java.nio.channels.Pipe.SinkChannel; //导入依赖的package包/类
private EchoInputStreamWrapper(InputStream in, SinkChannel out) {
this.in = in;
this.out = out;
setName(getClass().getName() + "-" + idCounter.incrementAndGet());
setDaemon(true);
}
示例10: mai
import java.nio.channels.Pipe.SinkChannel; //导入依赖的package包/类
public mai(Context paramContext, File paramFile, String paramString, long paramLong1, long paramLong2, Map<String, String> paramMap)
{
if ((paramLong1 < 0L) || ((paramLong2 != -1L) && (paramLong1 > paramLong2))) {
throw new IllegalArgumentException("Invalid stream limits");
}
this.f = paramLong1;
this.d = paramLong2;
long l1;
if (paramFile == null)
{
l1 = 0L;
this.e = l1;
if (this.f >= this.e) {
break label216;
}
this.b = new RandomAccessFile(paramFile, "r");
this.b.seek(this.f);
}
for (;;)
{
if (paramString == null) {
break label224;
}
Pipe localPipe = Pipe.open();
this.c = Channels.newInputStream(localPipe.source());
Pipe.SinkChannel localSinkChannel = localPipe.sink();
this.a = ixd.a(paramContext).a(paramString, 4, paramMap, localSinkChannel, this);
long l2 = Math.max(this.e, this.f);
if (l2 != 0L)
{
new StringBuilder(41).append("Starting request at: ").append(l2);
this.a.a(l2);
}
this.a.f();
return;
l1 = paramFile.length();
break;
label216:
this.b = null;
}
label224:
this.a = null;
this.c = null;
}
示例11: OutPipe
import java.nio.channels.Pipe.SinkChannel; //导入依赖的package包/类
public OutPipe(SinkChannel sink) throws IOException {
s = sink;
s.configureBlocking(true);
}
示例12: test_sink
import java.nio.channels.Pipe.SinkChannel; //导入依赖的package包/类
/**
* @tests java.nio.channels.Pipe#sink()
*/
public void test_sink() throws IOException {
Pipe pipe = Pipe.open();
SinkChannel sink = pipe.sink();
assertTrue(sink.isBlocking());
}
示例13: DualChannelProcessorMultiplexer
import java.nio.channels.Pipe.SinkChannel; //导入依赖的package包/类
/**
*
* @param t
* @param c
* @param client
* @param thisId Identifier of this multiplexer endpoint. This is sent to the client on connection.
* @param remoteId Required identifier of the other endpoint. This is checked to be equal to the value received from the client.
*/
public DualChannelProcessorMultiplexer(NioThread t, SourceChannel source, SinkChannel sink, boolean client, byte[] thisId, byte[] remoteId) {
super(thisId, remoteId);
cpSink=new CPSink(t, sink, client);
cpSource=new CPSource(t, source, client);
}