Skip to content

Commit

Permalink
Addition to #846 and #855: (#869)
Browse files Browse the repository at this point in the history
* Addition to #846 and #855:
- OkHttpClient instead of ApacheHttpClient
- fix of java.lang.IllegalArgumentException: Input byte array has incorrect ending byte at...

* Addition to #846 and #855:
- using of mime encoder/decoder
  • Loading branch information
TikhomirovSergey authored and SrinivasanTarget committed Apr 18, 2018
1 parent 0b2c407 commit a542fee
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ default String getClipboard(ClipboardContentType contentType) {
*/
default void setClipboardText(String text) {
setClipboard(ClipboardContentType.PLAINTEXT, Base64
.getEncoder()
.getMimeEncoder()
.encode(text.getBytes(StandardCharsets.UTF_8)));
}

Expand All @@ -72,7 +72,7 @@ default void setClipboardText(String text) {
*/
default String getClipboardText() {
byte[] base64decodedBytes = Base64
.getDecoder()
.getMimeDecoder()
.decode(getClipboard(ClipboardContentType.PLAINTEXT));
return new String(base64decodedBytes, StandardCharsets.UTF_8);
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/appium/java_client/ios/HasIOSClipboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ default void setClipboardImage(BufferedImage img) throws IOException {
try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) {
ImageIO.write(checkNotNull(img), "png", os);
setClipboard(ClipboardContentType.IMAGE, Base64
.getEncoder()
.getMimeEncoder()
.encode(os.toByteArray()));
}
}
Expand All @@ -55,7 +55,7 @@ default void setClipboardImage(BufferedImage img) throws IOException {
*/
default BufferedImage getClipboardImage() throws IOException {
final byte[] base64decodedBytes = Base64
.getDecoder()
.getMimeDecoder()
.decode(getClipboard(ClipboardContentType.IMAGE));
return ImageIO.read(new ByteArrayInputStream(base64decodedBytes));
}
Expand All @@ -67,7 +67,7 @@ default BufferedImage getClipboardImage() throws IOException {
*/
default void setClipboardUrl(URL url) {
setClipboard(ClipboardContentType.URL, Base64
.getEncoder()
.getMimeEncoder()
.encode(checkNotNull(url).toString().getBytes(StandardCharsets.UTF_8)));
}

Expand All @@ -79,7 +79,7 @@ default void setClipboardUrl(URL url) {
*/
default URL getClipboardUrl() throws MalformedURLException {
final byte[] base64decodedBytes = Base64
.getDecoder()
.getMimeDecoder()
.decode(getClipboard(ClipboardContentType.URL));
return new URL(new String(base64decodedBytes, StandardCharsets.UTF_8));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.openqa.selenium.remote.http.HttpClient;
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.W3CHttpCommandCodec;
import org.openqa.selenium.remote.internal.ApacheHttpClient;
import org.openqa.selenium.remote.internal.OkHttpClient;
import org.openqa.selenium.remote.service.DriverService;

import java.io.IOException;
Expand Down Expand Up @@ -70,12 +70,12 @@ public AppiumCommandExecutor(Map<String, CommandInfo> additionalCommands,

public AppiumCommandExecutor(Map<String, CommandInfo> additionalCommands,
URL addressOfRemoteServer) {
this(additionalCommands, addressOfRemoteServer, new ApacheHttpClient.Factory());
this(additionalCommands, addressOfRemoteServer, new OkHttpClient.Factory());
}

public AppiumCommandExecutor(Map<String, CommandInfo> additionalCommands,
DriverService service) {
this(additionalCommands, service, new ApacheHttpClient.Factory());
this(additionalCommands, service, new OkHttpClient.Factory());
}

private <B> B getPrivateFieldValue(String fieldName, Class<B> fieldType) {
Expand Down

0 comments on commit a542fee

Please sign in to comment.