use of java.io.PipedOutputStream in project robovm by robovm.
the class OldPipedOutputStreamTest method test_connectLjava_io_PipedInputStream.
public void test_connectLjava_io_PipedInputStream() throws IOException {
out = new PipedOutputStream();
try {
out.connect(new PipedInputStream());
} catch (Exception e) {
fail("Test 1: Unexpected exception when connecting: " + e.getLocalizedMessage());
}
try {
out.write('B');
} catch (IOException e) {
fail("Test 2: Unexpected IOException when writing after connecting.");
}
try {
out.connect(new PipedInputStream());
fail("Test 3: IOException expected when reconnecting the stream.");
} catch (IOException e) {
// Expected.
}
try {
out.connect(null);
fail("Test 4: NullPointerException expected.");
} catch (NullPointerException e) {
// Expected.
}
}
use of java.io.PipedOutputStream in project robovm by robovm.
the class OldPipedOutputStreamTest method test_writeI.
public void test_writeI() throws IOException {
out = new PipedOutputStream();
try {
out.write(42);
fail("Test 1: IOException expected.");
} catch (IOException e) {
// Expected.
}
rt = new Thread(reader = new PReader(out));
rt.start();
out.write('c');
out.flush();
assertEquals("Test 2: The byte read does not match the byte written. ", "c", reader.read(1));
/* Test disabled due to incomplete implementation, see ticket #92.
rt.interrupt();
try {
out.write(42);
fail("Test 3: IOException expected.");
} catch (IOException e) {
// Expected.
}
}
*/
reader.getReader().close();
try {
out.write(42);
fail("Test 4: IOException expected.");
} catch (IOException e) {
// Expected.
}
}
use of java.io.PipedOutputStream in project robovm by robovm.
the class OldPipedOutputStreamTest method test_flush.
public void test_flush() throws Exception {
out = new PipedOutputStream();
rt = new Thread(reader = new PReader(out));
rt.start();
out.write(testString.getBytes(), 0, 10);
assertTrue("Test 1: Bytes have been written before flush.", reader.available() != 0);
out.flush();
assertEquals("Test 2: Flush failed. ", testString.substring(0, 10), reader.read(10));
}
use of java.io.PipedOutputStream in project felix by apache.
the class Closure method execute.
@SuppressWarnings("unchecked")
private Object execute(List<Object> values, Channel capturingOutput) throws Exception {
if (null != values) {
parmv = new ArrayList<>(values);
parms = new ArgList(parmv);
} else if (null != parent) {
// inherit parent closure parameters
parmv = parent.parmv != null ? new ArrayList<>(parent.parmv) : null;
parms = parmv != null ? new ArgList(parmv) : null;
} else {
// inherit session parameters
Object args = session.get("args");
if (null != args && args instanceof List<?>) {
parmv = new ArrayList<>((List<Object>) args);
parms = new ArgList(parmv);
}
}
Result last = null;
Operator operator = null;
for (Iterator<Executable> iterator = program.tokens().iterator(); iterator.hasNext(); ) {
Operator prevOperator = operator;
Executable executable = iterator.next();
if (iterator.hasNext()) {
operator = (Operator) iterator.next();
} else {
operator = null;
}
if (prevOperator != null) {
if (Token.eq("&&", prevOperator)) {
if (!last.isSuccess()) {
continue;
}
} else if (Token.eq("||", prevOperator)) {
if (last.isSuccess()) {
continue;
}
}
}
Channel[] streams;
boolean[] toclose = new boolean[10];
if (Pipe.getCurrentPipe() != null) {
streams = Pipe.getCurrentPipe().streams.clone();
} else {
streams = new Channel[10];
System.arraycopy(session.channels, 0, streams, 0, 3);
}
if (capturingOutput != null) {
streams[1] = capturingOutput;
toclose[1] = true;
}
CommandSessionImpl.JobImpl job;
if (executable instanceof Pipeline) {
Pipeline pipeline = (Pipeline) executable;
List<Executable> exec = pipeline.tokens();
Token s = exec.get(0);
Token e = exec.get(exec.size() - 1);
Token t = program.subSequence(s.start - program.start, e.start + e.length - program.start);
job = session().createJob(t);
for (int i = 0; i < exec.size(); i++) {
Statement ex = (Statement) exec.get(i);
Operator op = i < exec.size() - 1 ? (Operator) exec.get(++i) : null;
Channel[] nstreams;
boolean[] ntoclose;
boolean endOfPipe;
if (i == exec.size() - 1) {
nstreams = streams;
ntoclose = toclose;
endOfPipe = true;
} else if (Token.eq("|", op)) {
PipedInputStream pis = new PipedInputStream();
PipedOutputStream pos = new PipedOutputStream(pis);
nstreams = streams.clone();
nstreams[1] = Channels.newChannel(pos);
ntoclose = toclose.clone();
ntoclose[1] = true;
streams[0] = Channels.newChannel(pis);
toclose[0] = true;
endOfPipe = false;
} else if (Token.eq("|&", op)) {
PipedInputStream pis = new PipedInputStream();
PipedOutputStream pos = new PipedOutputStream(pis);
nstreams = streams.clone();
nstreams[1] = nstreams[2] = Channels.newChannel(pos);
ntoclose = toclose.clone();
ntoclose[1] = ntoclose[2] = true;
streams[0] = Channels.newChannel(pis);
toclose[0] = true;
endOfPipe = false;
} else {
throw new IllegalStateException("Unrecognized pipe operator: '" + op + "'");
}
Pipe pipe = new Pipe(this, job, ex, nstreams, ntoclose, endOfPipe);
job.addPipe(pipe);
}
} else {
job = session().createJob(executable);
Pipe pipe = new Pipe(this, job, (Statement) executable, streams, toclose, true);
job.addPipe(pipe);
}
// Start pipe in background
if (operator != null && Token.eq("&", operator)) {
job.start(Status.Background);
last = new Result((Object) null);
} else // Start in foreground and wait for results
{
last = job.start(Status.Foreground);
if (last == null) {
last = new Result((Object) null);
} else if (last.exception != null) {
throw last.exception;
}
}
}
return last == null ? null : last.result;
}
use of java.io.PipedOutputStream in project sonarlint-core by SonarSource.
the class SettingsDownloaderTest method testFetchGlobalSettings.
@Test
public void testFetchGlobalSettings() throws Exception {
SonarLintWsClient wsClient = WsClientTestUtils.createMock();
ValuesWsResponse response = ValuesWsResponse.newBuilder().addSettings(Setting.newBuilder().setKey("sonar.core.treemap.colormetric").setValue("violations_density").setInherited(true)).addSettings(Setting.newBuilder().setKey("sonar.core.treemap.sizemetric").setValue("ncloc")).addSettings(Setting.newBuilder().setKey("views.servers").setValues(Values.newBuilder().addValues("135817900907501"))).build();
PipedInputStream in = new PipedInputStream();
final PipedOutputStream out = new PipedOutputStream(in);
response.writeTo(out);
out.close();
WsClientTestUtils.addResponse(wsClient, "/api/settings/values.protobuf", in);
new SettingsDownloader(wsClient).fetchGlobalSettingsTo("6.3", destDir);
GlobalProperties properties = ProtobufUtil.readFile(destDir.resolve(StoragePaths.PROPERTIES_PB), GlobalProperties.parser());
assertThat(properties.getPropertiesMap()).containsOnly(entry("sonar.core.treemap.sizemetric", "ncloc"), entry("views.servers", "135817900907501"));
}
Aggregations