Skip to content

Commit 9205c89

Browse files
author
Mykola Mokhnach
authored
Add a method for output streams cleanup (#909)
* Add a method for output streams cleanup * Make lint happy
1 parent 09a3c66 commit 9205c89

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java

+11-7
Original file line numberDiff line numberDiff line change
@@ -35,37 +35,32 @@
3535
import java.util.List;
3636
import java.util.concurrent.TimeUnit;
3737
import java.util.concurrent.locks.ReentrantLock;
38+
import javax.annotation.Nullable;
3839

3940
public final class AppiumDriverLocalService extends DriverService {
4041

4142
private static final String URL_MASK = "http://%s:%d/wd/hub";
4243
private final File nodeJSExec;
43-
private final int nodeJSPort;
4444
private final ImmutableList<String> nodeJSArgs;
4545
private final ImmutableMap<String, String> nodeJSEnvironment;
46-
private final String ipAddress;
4746
private final long startupTimeout;
4847
private final TimeUnit timeUnit;
4948
private final ReentrantLock lock = new ReentrantLock(true); //uses "fair" thread ordering policy
5049
private final ListOutputStream stream = new ListOutputStream().add(System.out);
5150
private final URL url;
5251

53-
54-
5552
private CommandLine process = null;
5653

5754
AppiumDriverLocalService(String ipAddress, File nodeJSExec, int nodeJSPort,
5855
ImmutableList<String> nodeJSArgs, ImmutableMap<String, String> nodeJSEnvironment,
5956
long startupTimeout, TimeUnit timeUnit) throws IOException {
6057
super(nodeJSExec, nodeJSPort, nodeJSArgs, nodeJSEnvironment);
61-
this.ipAddress = ipAddress;
6258
this.nodeJSExec = nodeJSExec;
63-
this.nodeJSPort = nodeJSPort;
6459
this.nodeJSArgs = nodeJSArgs;
6560
this.nodeJSEnvironment = nodeJSEnvironment;
6661
this.startupTimeout = startupTimeout;
6762
this.timeUnit = timeUnit;
68-
this.url = new URL(String.format(URL_MASK, this.ipAddress, this.nodeJSPort));
63+
this.url = new URL(String.format(URL_MASK, ipAddress, nodeJSPort));
6964
}
7065

7166
public static AppiumDriverLocalService buildDefaultService() {
@@ -185,6 +180,7 @@ private void destroyProcess() {
185180
* @return String logs if the server has been run.
186181
* null is returned otherwise.
187182
*/
183+
@Nullable
188184
public String getStdOut() {
189185
if (process != null) {
190186
return process.getStdOut();
@@ -215,4 +211,12 @@ public void addOutPutStreams(List<OutputStream> outputStreams) {
215211
}
216212
}
217213

214+
/**
215+
* Remove all existing server output streams.
216+
*
217+
* @return true if at least one output stream has been cleared
218+
*/
219+
public boolean clearOutPutStreams() {
220+
return stream.clear();
221+
}
218222
}

src/main/java/io/appium/java_client/service/local/ListOutputStream.java

+13
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,17 @@ public void close() throws IOException {
5959
stream.close();
6060
}
6161
}
62+
63+
/**
64+
* Clears all the existing output streams.
65+
*
66+
* @return true if at least one output stream has been cleared
67+
*/
68+
public boolean clear() {
69+
if (streams.isEmpty()) {
70+
return false;
71+
}
72+
streams.clear();
73+
return true;
74+
}
6275
}

0 commit comments

Comments
 (0)