- get rid of synchronized method modifier

- close stream in finally section
- BaseOSProcessHandler uses BaseOutputReader instead of OutputReader
This commit is contained in:
Sergey Simonchik
2012-08-16 17:35:54 +04:00
parent 423bebb371
commit 7ea75ae120
3 changed files with 28 additions and 9 deletions
@@ -17,7 +17,7 @@ package com.intellij.execution.process;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.util.Consumer;
import com.intellij.util.io.OutputReader;
import com.intellij.util.io.BaseOutputReader;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -66,7 +66,7 @@ public class BaseOSProcessHandler extends ProcessHandler {
@Override
public void startNotified(final ProcessEvent event) {
try {
final OutputReader stdoutReader = new OutputReader(createProcessOutReader()) {
final BaseOutputReader stdoutReader = new BaseOutputReader(createProcessOutReader()) {
@Override
protected void onTextAvailable(@NotNull String text) {
notifyTextAvailable(text, ProcessOutputTypes.STDOUT);
@@ -78,7 +78,7 @@ public class BaseOSProcessHandler extends ProcessHandler {
}
};
final OutputReader stderrReader = new OutputReader(createProcessErrReader()) {
final BaseOutputReader stderrReader = new BaseOutputReader(createProcessErrReader()) {
@Override
protected void onTextAvailable(@NotNull String text) {
notifyTextAvailable(text, ProcessOutputTypes.STDERR);
@@ -60,7 +60,6 @@ public abstract class BaseOutputReader {
boolean read = readAvailable();
if (isStopped) {
myReader.close();
break;
}
@@ -75,16 +74,30 @@ public abstract class BaseOutputReader {
catch (Exception e) {
LOG.error(e);
}
finally {
try {
myReader.close();
}
catch (IOException e) {
LOG.error("Can't close stream", e);
}
}
}
protected synchronized boolean readAvailable() throws IOException {
/**
* Reads as much data as possible without blocking.
* @return true if non-zero amount of data has been read
* @exception IOException If an I/O error occurs
*/
protected final boolean readAvailable() throws IOException {
char[] buffer = myBuffer;
StringBuilder token = myTextBuffer;
token.setLength(0);
boolean read = false;
int n;
while ((n = myReader.read(buffer)) > 0) {
while (myReader.ready()) {
int n = myReader.read(buffer);
if (n <= 0) break;
read = true;
for (int i = 0; i < n; i++) {
@@ -43,7 +43,6 @@ public abstract class OutputReader extends BaseOutputReader {
}
if (isStopped) {
myReader.close();
break;
}
@@ -58,6 +57,14 @@ public abstract class OutputReader extends BaseOutputReader {
catch (Exception e) {
LOG.error(e);
}
finally {
try {
myReader.close();
}
catch (IOException e) {
LOG.warn("Can't close reader", e);
}
}
}
public void readFully() throws InterruptedException {
@@ -70,5 +77,4 @@ public abstract class OutputReader extends BaseOutputReader {
}
}
}