當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。