Add a method for output streams cleanup by mykola-mokhnach · Pull Request #909 · appium/java-client

Expand Up @@ -35,37 +35,32 @@ import java.util.List; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; import javax.annotation.Nullable;
public final class AppiumDriverLocalService extends DriverService {
private static final String URL_MASK = "http://%s:%d/wd/hub"; private final File nodeJSExec; private final int nodeJSPort; private final ImmutableList<String> nodeJSArgs; private final ImmutableMap<String, String> nodeJSEnvironment; private final String ipAddress; private final long startupTimeout; private final TimeUnit timeUnit; private final ReentrantLock lock = new ReentrantLock(true); //uses "fair" thread ordering policy private final ListOutputStream stream = new ListOutputStream().add(System.out); private final URL url;


private CommandLine process = null;
AppiumDriverLocalService(String ipAddress, File nodeJSExec, int nodeJSPort, ImmutableList<String> nodeJSArgs, ImmutableMap<String, String> nodeJSEnvironment, long startupTimeout, TimeUnit timeUnit) throws IOException { super(nodeJSExec, nodeJSPort, nodeJSArgs, nodeJSEnvironment); this.ipAddress = ipAddress; this.nodeJSExec = nodeJSExec; this.nodeJSPort = nodeJSPort; this.nodeJSArgs = nodeJSArgs; this.nodeJSEnvironment = nodeJSEnvironment; this.startupTimeout = startupTimeout; this.timeUnit = timeUnit; this.url = new URL(String.format(URL_MASK, this.ipAddress, this.nodeJSPort)); this.url = new URL(String.format(URL_MASK, ipAddress, nodeJSPort)); }
public static AppiumDriverLocalService buildDefaultService() { Expand Down Expand Up @@ -185,6 +180,7 @@ private void destroyProcess() { * @return String logs if the server has been run. * null is returned otherwise. */ @Nullable public String getStdOut() { if (process != null) { return process.getStdOut(); Expand Down Expand Up @@ -215,4 +211,12 @@ public void addOutPutStreams(List<OutputStream> outputStreams) { } }
/** * Remove all existing server output streams. * * @return true if at least one output stream has been cleared */ public boolean clearOutPutStreams() { return stream.clear(); } }