use of java.nio.channels.Pipe in project j2objc by google.
the class ChannelsTest method createNonBlockingChannel.
private Pipe.SourceChannel createNonBlockingChannel(byte[] content) throws IOException {
Pipe pipe = Pipe.open();
WritableByteChannel sinkChannel = pipe.sink();
sinkChannel.write(ByteBuffer.wrap(content));
Pipe.SourceChannel sourceChannel = pipe.source();
sourceChannel.configureBlocking(false);
return sourceChannel;
}
use of java.nio.channels.Pipe in project jdk8u_jdk by JetBrains.
the class Basic method main.
public static void main(String[] args) throws Exception {
Pipe p = Pipe.open();
p.source().close();
p.sink().close();
}
use of java.nio.channels.Pipe in project beam by apache.
the class PackageUtilTest method testPackageUploadWithDirectorySucceeds.
@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());
PackageUtil.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"));
}
use of java.nio.channels.Pipe in project beam by apache.
the class PackageUtilTest method testPackageUploadWithEmptyDirectorySucceeds.
@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 = PackageUtil.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());
}
use of java.nio.channels.Pipe in project beam by apache.
the class PackageUtilTest method testPackageUploadWithExplicitPackageName.
@Test
public void testPackageUploadWithExplicitPackageName() throws Exception {
Pipe pipe = Pipe.open();
File tmpFile = makeFileWithContents("file.txt", "This is a test!");
final String overriddenName = "alias.txt";
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 = PackageUtil.stageClasspathElements(ImmutableList.of(overriddenName + "=" + 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(), equalTo(overriddenName));
assertThat(target.getLocation(), RegexMatcher.matches(STAGING_PATH + "file-" + HASH_PATTERN + ".txt"));
}
Aggregations