use of java.io.PipedOutputStream in project cdap by caskdata.
the class ASMDatumCodecTest method testMap.
@Test
public void testMap() throws IOException, UnsupportedTypeException {
TypeToken<Map<String, List<String>>> type = new TypeToken<Map<String, List<String>>>() {
};
PipedOutputStream os = new PipedOutputStream();
PipedInputStream is = new PipedInputStream(os);
DatumWriter<Map<String, List<String>>> writer = getWriter(type);
ImmutableMap<String, List<String>> map = ImmutableMap.<String, List<String>>of("k1", Lists.newArrayList("v1"), "k2", Lists.newArrayList("v2", null));
writer.encode(map, new BinaryEncoder(os));
ReflectionDatumReader<Map<String, List<String>>> reader = new ReflectionDatumReader<>(getSchema(type), type);
Assert.assertEquals(map, reader.read(new BinaryDecoder(is), getSchema(type)));
}
use of java.io.PipedOutputStream in project cdap by caskdata.
the class ASMDatumCodecTest method testRecordArray.
@Test
public void testRecordArray() throws IOException, UnsupportedTypeException {
TypeToken<Record[][]> type = new TypeToken<Record[][]>() {
};
PipedOutputStream os = new PipedOutputStream();
PipedInputStream is = new PipedInputStream(os);
DatumWriter<Record[][]> writer = getWriter(type);
Record[][] writeValue = new Record[][] { { new Record(10, "testing", ImmutableList.of("a", "b", "c"), TestEnum.VALUE2) } };
writer.encode(writeValue, new BinaryEncoder(os));
ReflectionDatumReader<Record[][]> reader = new ReflectionDatumReader<>(getSchema(type), type);
Record[][] value = reader.read(new BinaryDecoder(is), getSchema(type));
Assert.assertArrayEquals(writeValue, value);
}
use of java.io.PipedOutputStream in project ant by apache.
the class JUnitLauncherTask method trySwitchSysOutErr.
private Optional<SwitchedStreamHandle> trySwitchSysOutErr(final TestRequest testRequest, final StreamType streamType) {
switch(streamType) {
case SYS_OUT:
{
if (!testRequest.interestedInSysOut()) {
return Optional.empty();
}
break;
}
case SYS_ERR:
{
if (!testRequest.interestedInSysErr()) {
return Optional.empty();
}
break;
}
default:
{
// and return back
return Optional.empty();
}
}
final PipedOutputStream pipedOutputStream = new PipedOutputStream();
final PipedInputStream pipedInputStream;
try {
pipedInputStream = new PipedInputStream(pipedOutputStream);
} catch (IOException ioe) {
// log and return
return Optional.empty();
}
final PrintStream printStream = new PrintStream(pipedOutputStream, true);
final SysOutErrStreamReader streamer;
switch(streamType) {
case SYS_OUT:
{
System.setOut(new PrintStream(printStream));
streamer = new SysOutErrStreamReader(this, pipedInputStream, StreamType.SYS_OUT, testRequest.getSysOutInterests());
final Thread sysOutStreamer = new Thread(streamer);
sysOutStreamer.setDaemon(true);
sysOutStreamer.setName("junitlauncher-sysout-stream-reader");
sysOutStreamer.setUncaughtExceptionHandler((t, e) -> this.log("Failed in sysout streaming", e, Project.MSG_INFO));
sysOutStreamer.start();
break;
}
case SYS_ERR:
{
System.setErr(new PrintStream(printStream));
streamer = new SysOutErrStreamReader(this, pipedInputStream, StreamType.SYS_ERR, testRequest.getSysErrInterests());
final Thread sysErrStreamer = new Thread(streamer);
sysErrStreamer.setDaemon(true);
sysErrStreamer.setName("junitlauncher-syserr-stream-reader");
sysErrStreamer.setUncaughtExceptionHandler((t, e) -> this.log("Failed in syserr streaming", e, Project.MSG_INFO));
sysErrStreamer.start();
break;
}
default:
{
return Optional.empty();
}
}
return Optional.of(new SwitchedStreamHandle(pipedOutputStream, streamer));
}
use of java.io.PipedOutputStream in project tdq-studio-se by Talend.
the class ChartUtils method bufferedToDescriptorOptimized.
public static ImageDescriptor bufferedToDescriptorOptimized(final BufferedImage image) throws IOException {
final PipedOutputStream output = new PipedOutputStream();
final PipedInputStream pipedInputStream = new PipedInputStream();
output.connect(pipedInputStream);
try {
new Thread() {
@Override
public void run() {
try {
ChartUtilities.writeBufferedImageAsPNG(output, image, false, 0);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}.start();
} catch (RuntimeException e) {
if (e.getCause() instanceof IOException) {
throw (IOException) e.getCause();
}
}
ImageData img = new ImageData(pipedInputStream);
ImageDescriptor descriptor = ImageDescriptor.createFromImageData(img);
return descriptor;
}
use of java.io.PipedOutputStream in project cypher-for-gremlin by opencypher.
the class EmbeddedGremlinConsole method start.
public void start() {
System.setProperty("plugins", "v3d3");
PipedInputStream in = new PipedInputStream();
replaceSystemIn(in);
try {
input = new PrintWriter(new PipedOutputStream(in));
} catch (IOException e) {
throw new RuntimeException(e);
}
console = new Thread(() -> new Console(new IO(), new ArrayList<>(), true));
console.start();
}
Aggregations