From a542feeb954833420b9f480a6f65c7025900b87d Mon Sep 17 00:00:00 2001 From: Sergey Tikhomirov Date: Wed, 18 Apr 2018 09:34:59 +0300 Subject: [PATCH] Addition to #846 and #855: (#869) * 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 --- .../io/appium/java_client/clipboard/HasClipboard.java | 4 ++-- .../java/io/appium/java_client/ios/HasIOSClipboard.java | 8 ++++---- .../appium/java_client/remote/AppiumCommandExecutor.java | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/io/appium/java_client/clipboard/HasClipboard.java b/src/main/java/io/appium/java_client/clipboard/HasClipboard.java index a0a07c556..ca813c4e0 100644 --- a/src/main/java/io/appium/java_client/clipboard/HasClipboard.java +++ b/src/main/java/io/appium/java_client/clipboard/HasClipboard.java @@ -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))); } @@ -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); } diff --git a/src/main/java/io/appium/java_client/ios/HasIOSClipboard.java b/src/main/java/io/appium/java_client/ios/HasIOSClipboard.java index e04166116..221906279 100644 --- a/src/main/java/io/appium/java_client/ios/HasIOSClipboard.java +++ b/src/main/java/io/appium/java_client/ios/HasIOSClipboard.java @@ -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())); } } @@ -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)); } @@ -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))); } @@ -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)); } diff --git a/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java b/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java index f8651dad6..5426de95f 100644 --- a/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java +++ b/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java @@ -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; @@ -70,12 +70,12 @@ public AppiumCommandExecutor(Map additionalCommands, public AppiumCommandExecutor(Map additionalCommands, URL addressOfRemoteServer) { - this(additionalCommands, addressOfRemoteServer, new ApacheHttpClient.Factory()); + this(additionalCommands, addressOfRemoteServer, new OkHttpClient.Factory()); } public AppiumCommandExecutor(Map additionalCommands, DriverService service) { - this(additionalCommands, service, new ApacheHttpClient.Factory()); + this(additionalCommands, service, new OkHttpClient.Factory()); } private B getPrivateFieldValue(String fieldName, Class fieldType) {