当前位置: 首页>>代码示例>>Java>>正文


Java Pipe.open方法代码示例

本文整理汇总了Java中java.nio.channels.Pipe.open方法的典型用法代码示例。如果您正苦于以下问题:Java Pipe.open方法的具体用法?Java Pipe.open怎么用?Java Pipe.open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.channels.Pipe的用法示例。


在下文中一共展示了Pipe.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getImpl

import java.nio.channels.Pipe; //导入方法依赖的package包/类
@Override
public <T> T getImpl(Class<? extends T> cl)
{
   if (InputStream.class.isAssignableFrom(cl))
   {
      try
      {
         Pipe pipe = Pipe.open();
         DownloadTask dltask = new DownloadTask(pipe);
         Thread download_thread = new Thread(dltask, "Product Download");
         download_thread.start();

         InputStream is = Channels.newInputStream(pipe.source());
         return cl.cast(is);
      }
      catch (IOException ex)
      {
         LOGGER.error("could not create pipe", ex);
      }
   }
   return null;
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:23,代码来源:DownloadableProduct.java

示例2: write

import java.nio.channels.Pipe; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 * @see io.netty.channel.ChannelOutboundInvoker#write(java.lang.Object)
 */
@Override
public ChannelFuture write(Object message) {
	if(message!=null) {
		if(message instanceof FileRegion) {
			try {
				Pipe pipe = Pipe.open();
				FileRegion fr = (FileRegion)message;
				
				long bytesToRead = fr.count();
				fr.transferTo(pipe.sink(), 0L);
				byte[] content = new byte[(int)bytesToRead];
				pipe.source().read(ByteBuffer.wrap(content));
				channelWrites.add(content);
			} catch (Exception ex) {
				log.error("Failed to read content from pipe", ex);
				channelWrites.add(ex);
			}
		} else {
			channelWrites.add(message);
		}
		log.info("Received Channel Write [{}]  type:[{}]", message, message.getClass().getName());
	}
	
	return null;
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:30,代码来源:InvocationChannel.java

示例3: write

import java.nio.channels.Pipe; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 * @see org.jboss.netty.channel.Channel#write(java.lang.Object)
 */
@Override
public ChannelFuture write(Object message) {
	if(message!=null) {
		if(message instanceof FileRegion) {
			try {
				Pipe pipe = Pipe.open();
				FileRegion fr = (FileRegion)message;
				
				long bytesToRead = fr.getCount();
				fr.transferTo(pipe.sink(), 0L);
				byte[] content = new byte[(int)bytesToRead];
				pipe.source().read(ByteBuffer.wrap(content));
				channelWrites.add(content);
			} catch (Exception ex) {
				log.error("Failed to read content from pipe", ex);
				channelWrites.add(ex);
			}
		} else {
			channelWrites.add(message);
		}
		log.info("Received Channel Write [{}]  type:[{}]", message, message.getClass().getName());
	}
	
	return Channels.succeededFuture(this);
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:30,代码来源:InvocationChannel.java

示例4: testPackageUploadWithFileSucceeds

import java.nio.channels.Pipe; //导入方法依赖的package包/类
@Test
public void testPackageUploadWithFileSucceeds() throws Exception {
  Pipe pipe = Pipe.open();
  String contents = "This is a test!";
  File tmpFile = makeFileWithContents("file.txt", contents);
  when(mockGcsUtil.getObjects(anyListOf(GcsPath.class)))
      .thenReturn(ImmutableList.of(StorageObjectOrIOException.create(
          new FileNotFoundException("some/path"))));

  when(mockGcsUtil.create(any(GcsPath.class), anyString())).thenReturn(pipe.sink());

  List<DataflowPackage> targets =
      defaultPackageUtil.stageClasspathElements(
          ImmutableList.of(tmpFile.getAbsolutePath()), STAGING_PATH, createOptions);
  DataflowPackage target = Iterables.getOnlyElement(targets);

  verify(mockGcsUtil).getObjects(anyListOf(GcsPath.class));
  verify(mockGcsUtil).create(any(GcsPath.class), anyString());
  verifyNoMoreInteractions(mockGcsUtil);

  assertThat(target.getName(), RegexMatcher.matches("file-" + HASH_PATTERN + ".txt"));
  assertThat(target.getLocation(), equalTo(STAGING_PATH + target.getName()));
  assertThat(new LineReader(Channels.newReader(pipe.source(), "UTF-8")).readLine(),
      equalTo(contents));
}
 
开发者ID:apache,项目名称:beam,代码行数:26,代码来源:PackageUtilTest.java

示例5: testPackageUploadWithEmptyDirectorySucceeds

import java.nio.channels.Pipe; //导入方法依赖的package包/类
@Test
public void testPackageUploadWithEmptyDirectorySucceeds() throws Exception {
  Pipe pipe = Pipe.open();
  File tmpDirectory = tmpFolder.newFolder("folder");

  when(mockGcsUtil.getObjects(anyListOf(GcsPath.class)))
      .thenReturn(ImmutableList.of(StorageObjectOrIOException.create(
          new FileNotFoundException("some/path"))));
  when(mockGcsUtil.create(any(GcsPath.class), anyString())).thenReturn(pipe.sink());

  List<DataflowPackage> targets =
      defaultPackageUtil.stageClasspathElements(
          ImmutableList.of(tmpDirectory.getAbsolutePath()), STAGING_PATH, createOptions);
  DataflowPackage target = Iterables.getOnlyElement(targets);

  verify(mockGcsUtil).getObjects(anyListOf(GcsPath.class));
  verify(mockGcsUtil).create(any(GcsPath.class), anyString());
  verifyNoMoreInteractions(mockGcsUtil);

  assertThat(target.getName(), RegexMatcher.matches("folder-" + HASH_PATTERN + ".jar"));
  assertThat(target.getLocation(), equalTo(STAGING_PATH + target.getName()));
  assertNull(new ZipInputStream(Channels.newInputStream(pipe.source())).getNextEntry());
}
 
开发者ID:apache,项目名称:beam,代码行数:24,代码来源:PackageUtilTest.java

示例6: testPackageUploadEventuallySucceeds

import java.nio.channels.Pipe; //导入方法依赖的package包/类
@Test
public void testPackageUploadEventuallySucceeds() throws Exception {
  Pipe pipe = Pipe.open();
  File tmpFile = makeFileWithContents("file.txt", "This is a test!");
  when(mockGcsUtil.getObjects(anyListOf(GcsPath.class)))
      .thenReturn(ImmutableList.of(StorageObjectOrIOException.create(
          new FileNotFoundException("some/path"))));
  when(mockGcsUtil.create(any(GcsPath.class), anyString()))
      .thenThrow(new IOException("Fake Exception: 410 Gone")) // First attempt fails
      .thenReturn(pipe.sink());                               // second attempt succeeds

  try (PackageUtil directPackageUtil =
      PackageUtil.withExecutorService(MoreExecutors.newDirectExecutorService())) {
    directPackageUtil.stageClasspathElements(
        ImmutableList.of(tmpFile.getAbsolutePath()),
        STAGING_PATH,
        fastNanoClockAndSleeper,
        createOptions);
  } finally {
    verify(mockGcsUtil).getObjects(anyListOf(GcsPath.class));
    verify(mockGcsUtil, times(2)).create(any(GcsPath.class), anyString());
    verifyNoMoreInteractions(mockGcsUtil);
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:25,代码来源:PackageUtilTest.java

示例7: testPackageUploadIsNotSkippedWhenSizesAreDifferent

import java.nio.channels.Pipe; //导入方法依赖的package包/类
@Test
public void testPackageUploadIsNotSkippedWhenSizesAreDifferent() throws Exception {
  Pipe pipe = Pipe.open();
  File tmpDirectory = tmpFolder.newFolder("folder");
  tmpFolder.newFolder("folder", "empty_directory");
  tmpFolder.newFolder("folder", "directory");
  makeFileWithContents("folder/file.txt", "This is a test!");
  makeFileWithContents("folder/directory/file.txt", "This is also a test!");
  when(mockGcsUtil.getObjects(anyListOf(GcsPath.class)))
      .thenReturn(ImmutableList.of(StorageObjectOrIOException.create(
          createStorageObject(STAGING_PATH, Long.MAX_VALUE))));
  when(mockGcsUtil.create(any(GcsPath.class), anyString())).thenReturn(pipe.sink());

  defaultPackageUtil.stageClasspathElements(
      ImmutableList.of(tmpDirectory.getAbsolutePath()), STAGING_PATH, createOptions);

  verify(mockGcsUtil).getObjects(anyListOf(GcsPath.class));
  verify(mockGcsUtil).create(any(GcsPath.class), anyString());
  verifyNoMoreInteractions(mockGcsUtil);
}
 
开发者ID:apache,项目名称:beam,代码行数:21,代码来源:PackageUtilTest.java

示例8: main

import java.nio.channels.Pipe; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
  Pipe pipe = Pipe.open();

  Pipe.SinkChannel sinkChannel = pipe.sink();
  Pipe.SourceChannel sourceChannel = pipe.source();
  String newData = "New String to write to file..." + System.currentTimeMillis();
  ByteBuffer buf = ByteBuffer.allocate(48);
  buf.clear();
  buf.put(newData.getBytes());
  buf.flip();

  ByteBuffer bufread = ByteBuffer.allocate(48);

  while (buf.hasRemaining()) {
    sinkChannel.write(buf);
    int bytesRead = sourceChannel.read(bufread);
    System.out.println(bytesRead);
  }

}
 
开发者ID:whyDK37,项目名称:pinenut,代码行数:21,代码来源:PipeTest.java

示例9: getSoundData

import java.nio.channels.Pipe; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public ReadableByteChannel getSoundData() {
	Pipe pipe = null;
	
	try {
		pipe = Pipe.open();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		return null;
	}
	
	decoderthreadpool.execute(new SoundDataDecoder(
			new DuplicateReadOnlyByteChannel(bytechannel), pipe.sink()));
	return pipe.source();
}
 
开发者ID:Cr0s,项目名称:JavaRA,代码行数:20,代码来源:VqaFile.java

示例10: WindowsSelectorImpl

import java.nio.channels.Pipe; //导入方法依赖的package包/类
WindowsSelectorImpl(SelectorProvider sp) throws IOException {
    super(sp);
    pollWrapper = new PollArrayWrapper(INIT_CAP);
    wakeupPipe = Pipe.open();
    wakeupSourceFd = ((SelChImpl)wakeupPipe.source()).getFDVal();

    // Disable the Nagle algorithm so that the wakeup is more immediate
    SinkChannelImpl sink = (SinkChannelImpl)wakeupPipe.sink();
    (sink.sc).socket().setTcpNoDelay(true);
    wakeupSinkFd = ((SelChImpl)sink).getFDVal();

    pollWrapper.addWakeupSocket(wakeupSourceFd, 0);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:14,代码来源:WindowsSelectorImpl.java

示例11: DotNetSelectorImpl

import java.nio.channels.Pipe; //导入方法依赖的package包/类
DotNetSelectorImpl(SelectorProvider sp) throws IOException
{
    super(sp);
    wakeupPipe = Pipe.open();
    wakeupSourceFd = ((SelChImpl)wakeupPipe.source()).getFD().getSocket();

    // Disable the Nagle algorithm so that the wakeup is more immediate
    SinkChannelImpl sink = (SinkChannelImpl)wakeupPipe.sink();
    (sink.sc).socket().setTcpNoDelay(true);
    wakeupSinkFd = ((SelChImpl)sink).getFD().getSocket();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:DotNetSelectorImpl.java

示例12: test

import java.nio.channels.Pipe; //导入方法依赖的package包/类
public void test() throws Exception {

        Thread tester = new Thread("PipeTester") {
            private Pipe testPipe = null;

            @Override
            public void run() {
                for (;;) {
                    boolean interrupted = this.isInterrupted();
                    try {
                        testPipe = Pipe.open();
                        close();
                        if (interrupted) {
                            if (!this.isInterrupted())
                               exc = new RuntimeException("interrupt status reset");
                            break;
                        }
                    } catch (IOException ioe) {
                        exc = ioe;
                    }
                }
            }

            private void close() throws IOException {
                if (testPipe != null) {
                    testPipe.sink().close();
                    testPipe.source().close();
                }
            }
        };

        tester.start();
        Thread.sleep(200);
        tester.interrupt();
        tester.join();

        if (exc != null)
            throw exc;
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:40,代码来源:PipeInterrupt.java

示例13: createInput

import java.nio.channels.Pipe; //导入方法依赖的package包/类
private InputStream createInput(Map<String, List<String>> config) {
    try {
        Pipe pipe = Pipe.open();
        OutputStream rawOutput = Channels.newOutputStream(pipe.sink());
        ObjectOutputStream output = new ObjectOutputStream(rawOutput);
        output.writeObject(config);
        return Channels.newInputStream(pipe.source());
    } catch (IOException e) {
        throw new UncheckedIOException("Could not open pipe.", e);
    }
}
 
开发者ID:ajoberstar,项目名称:jovial,代码行数:12,代码来源:JovialTestExecuter.java

示例14: testPackageUploadWithDirectorySucceeds

import java.nio.channels.Pipe; //导入方法依赖的package包/类
@Test
public void testPackageUploadWithDirectorySucceeds() throws Exception {
  Pipe pipe = Pipe.open();
  File tmpDirectory = tmpFolder.newFolder("folder");
  tmpFolder.newFolder("folder", "empty_directory");
  tmpFolder.newFolder("folder", "directory");
  makeFileWithContents("folder/file.txt", "This is a test!");
  makeFileWithContents("folder/directory/file.txt", "This is also a test!");

  when(mockGcsUtil.getObjects(anyListOf(GcsPath.class)))
      .thenReturn(ImmutableList.of(StorageObjectOrIOException.create(
          new FileNotFoundException("some/path"))));
  when(mockGcsUtil.create(any(GcsPath.class), anyString())).thenReturn(pipe.sink());

  defaultPackageUtil.stageClasspathElements(
      ImmutableList.of(tmpDirectory.getAbsolutePath()), STAGING_PATH, createOptions);

  verify(mockGcsUtil).getObjects(anyListOf(GcsPath.class));
  verify(mockGcsUtil).create(any(GcsPath.class), anyString());
  verifyNoMoreInteractions(mockGcsUtil);

  ZipInputStream inputStream = new ZipInputStream(Channels.newInputStream(pipe.source()));
  List<String> zipEntryNames = new ArrayList<>();
  for (ZipEntry entry = inputStream.getNextEntry(); entry != null;
      entry = inputStream.getNextEntry()) {
    zipEntryNames.add(entry.getName());
  }

  assertThat(zipEntryNames,
      containsInAnyOrder("directory/file.txt", "empty_directory/", "file.txt"));
}
 
开发者ID:apache,项目名称:beam,代码行数:32,代码来源:PackageUtilTest.java

示例15: main

import java.nio.channels.Pipe; //导入方法依赖的package包/类
public static void main(String[] args){
    Pipe pipe;
    Pipe.SinkChannel sinkChannel;
    Pipe.SourceChannel sourceChannel;

    try {
        pipe = Pipe.open();
        new Thread(new ReadWork(pipe.source())).start();
        new Thread(new WriteWork(pipe.sink())).start();

    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:StrongAndroid,项目名称:JavaNote,代码行数:15,代码来源:PipeTest.java


注:本文中的java.nio.channels.Pipe.open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。