|
16 | 16 |
|
17 | 17 | package io.appium.java_client.remote;
|
18 | 18 |
|
19 |
| -import com.google.common.io.CountingOutputStream; |
20 |
| -import com.google.common.io.FileBackedOutputStream; |
21 | 19 | import org.openqa.selenium.Capabilities;
|
22 | 20 | import org.openqa.selenium.ImmutableCapabilities;
|
23 | 21 | import org.openqa.selenium.SessionNotCreatedException;
|
|
28 | 26 | import org.openqa.selenium.remote.Command;
|
29 | 27 | import org.openqa.selenium.remote.NewSessionPayload;
|
30 | 28 | import org.openqa.selenium.remote.ProtocolHandshake;
|
| 29 | +import org.openqa.selenium.remote.http.Contents; |
31 | 30 | import org.openqa.selenium.remote.http.HttpHandler;
|
32 | 31 |
|
33 | 32 | import java.io.IOException;
|
34 |
| -import java.io.InputStream; |
35 |
| -import java.io.OutputStreamWriter; |
36 |
| -import java.io.Writer; |
| 33 | +import java.io.StringWriter; |
37 | 34 | import java.lang.reflect.InvocationTargetException;
|
38 | 35 | import java.lang.reflect.Method;
|
39 | 36 | import java.util.Map;
|
40 | 37 | import java.util.Set;
|
41 |
| -import java.util.function.Supplier; |
42 | 38 | import java.util.stream.Stream;
|
43 | 39 |
|
44 |
| -import static java.nio.charset.StandardCharsets.UTF_8; |
45 |
| - |
46 | 40 | @SuppressWarnings("UnstableApiUsage")
|
47 | 41 | public class AppiumProtocolHandshake extends ProtocolHandshake {
|
48 | 42 | private static void writeJsonPayload(NewSessionPayload srcPayload, Appendable destination) {
|
@@ -108,34 +102,22 @@ public Result createSession(HttpHandler client, Command command) throws IOExcept
|
108 | 102 | }
|
109 | 103 |
|
110 | 104 | @Override
|
111 |
| - public Either<SessionNotCreatedException, Result> createSession( |
112 |
| - HttpHandler client, NewSessionPayload payload) throws IOException { |
113 |
| - int threshold = (int) Math.min(Runtime.getRuntime().freeMemory() / 10, Integer.MAX_VALUE); |
114 |
| - FileBackedOutputStream os = new FileBackedOutputStream(threshold, true); |
| 105 | + public Either<SessionNotCreatedException, Result> createSession(HttpHandler client, NewSessionPayload payload) { |
115 | 106 |
|
116 |
| - try (CountingOutputStream counter = new CountingOutputStream(os); |
117 |
| - Writer writer = new OutputStreamWriter(counter, UTF_8)) { |
118 |
| - writeJsonPayload(payload, writer); |
| 107 | + StringWriter stringWriter = new StringWriter(); |
| 108 | + writeJsonPayload(payload, stringWriter); |
119 | 109 |
|
120 |
| - Supplier<InputStream> contentSupplier = () -> { |
121 |
| - try { |
122 |
| - return os.asByteSource().openBufferedStream(); |
123 |
| - } catch (IOException e) { |
124 |
| - throw new RuntimeException(e); |
125 |
| - } |
126 |
| - }; |
127 |
| - try { |
128 |
| - Method createSessionMethod = ProtocolHandshake.class.getDeclaredMethod( |
129 |
| - "createSession", HttpHandler.class, Supplier.class, long.class |
130 |
| - ); |
131 |
| - createSessionMethod.setAccessible(true); |
132 |
| - //noinspection unchecked |
133 |
| - return (Either<SessionNotCreatedException, Result>) createSessionMethod.invoke( |
134 |
| - this, client, contentSupplier, counter.getCount() |
135 |
| - ); |
136 |
| - } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { |
137 |
| - throw new WebDriverException(e); |
138 |
| - } |
| 110 | + try { |
| 111 | + Method createSessionMethod = ProtocolHandshake.class.getDeclaredMethod( |
| 112 | + "createSession", HttpHandler.class, Contents.Supplier.class |
| 113 | + ); |
| 114 | + createSessionMethod.setAccessible(true); |
| 115 | + //noinspection unchecked |
| 116 | + return (Either<SessionNotCreatedException, Result>) createSessionMethod.invoke( |
| 117 | + this, client, Contents.utf8String(stringWriter.toString()) |
| 118 | + ); |
| 119 | + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { |
| 120 | + throw new WebDriverException(e); |
139 | 121 | }
|
140 | 122 | }
|
141 | 123 | }
|
0 commit comments