use of org.gradle.internal.io.LineBufferingOutputStream in project gradle by gradle.
the class LineBufferingOutputStreamTest method logsEachLineAsASeparateLogMessage.
@Test
public void logsEachLineAsASeparateLogMessage() throws IOException {
LineBufferingOutputStream outputStream = new LineBufferingOutputStream(action, 8);
context.checking(new Expectations() {
{
one(action).text(TextUtil.toPlatformLineSeparators("line 1\n"));
one(action).text(TextUtil.toPlatformLineSeparators("line 2\n"));
}
});
outputStream.write(TextUtil.toPlatformLineSeparators("line 1\nline 2\n").getBytes());
}
use of org.gradle.internal.io.LineBufferingOutputStream in project gradle by gradle.
the class LineBufferingOutputStreamTest method cannotWriteAfterClose.
@Test(expected = IOException.class)
public void cannotWriteAfterClose() throws IOException {
LineBufferingOutputStream outputStream = new LineBufferingOutputStream(action, 8);
context.checking(new Expectations() {
{
one(action).endOfStream(null);
}
});
outputStream.close();
outputStream.write("ignore me".getBytes());
}
use of org.gradle.internal.io.LineBufferingOutputStream in project gradle by gradle.
the class LineBufferingOutputStreamTest method buffersTextUntilEndOfLineReached.
@Test
public void buffersTextUntilEndOfLineReached() throws IOException {
System.setProperty("line.separator", "-");
LineBufferingOutputStream outputStream = new LineBufferingOutputStream(action, 8);
context.checking(new Expectations() {
{
one(action).text("line 1-");
}
});
outputStream.write("line ".getBytes());
outputStream.write("1-line 2".getBytes());
context.checking(new Expectations() {
{
one(action).text("line 2-");
}
});
outputStream.write("-".getBytes());
}
use of org.gradle.internal.io.LineBufferingOutputStream in project gradle by gradle.
the class LineBufferingOutputStreamTest method handlesSingleCharacterLineSeparator.
@Test
public void handlesSingleCharacterLineSeparator() throws IOException {
System.setProperty("line.separator", "-");
LineBufferingOutputStream outputStream = new LineBufferingOutputStream(action, 8);
context.checking(new Expectations() {
{
one(action).text("line 1-");
one(action).text("line 2-");
}
});
outputStream.write(String.format("line 1-line 2-").getBytes());
}
use of org.gradle.internal.io.LineBufferingOutputStream in project gradle by gradle.
the class InputForwarder method start.
public InputForwarder start() {
lifecycleLock.lock();
try {
if (started) {
throw new IllegalStateException("input forwarder has already been started");
}
disconnectableInput = new DisconnectableInputStream(input, bufferSize);
outputBuffer = new LineBufferingOutputStream(handler, bufferSize);
forwardingExecuter = executorFactory.create("Forward input");
forwardingExecuter.execute(new Runnable() {
public void run() {
byte[] buffer = new byte[bufferSize];
int readCount;
Throwable readFailure = null;
try {
while (true) {
try {
readCount = disconnectableInput.read(buffer, 0, bufferSize);
if (readCount < 0) {
break;
}
} catch (AsynchronousCloseException e) {
break;
} catch (IOException e) {
readFailure = e;
break;
}
outputBuffer.write(buffer, 0, readCount);
}
// will flush any unterminated lines out synchronously
outputBuffer.flush();
} catch (IOException e) {
// should not happen
throw UncheckedException.throwAsUncheckedException(e);
} finally {
handler.endOfStream(readFailure);
}
}
});
started = true;
} finally {
lifecycleLock.unlock();
}
return this;
}
Aggregations