diff --git a/src/main/java/io/appium/java_client/PullsFiles.java b/src/main/java/io/appium/java_client/PullsFiles.java
index f85c18a6e..2dd403771 100644
--- a/src/main/java/io/appium/java_client/PullsFiles.java
+++ b/src/main/java/io/appium/java_client/PullsFiles.java
@@ -17,14 +17,10 @@
package io.appium.java_client;
import com.google.common.collect.ImmutableMap;
-import org.openqa.selenium.remote.Response;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
-import static io.appium.java_client.MobileCommand.PULL_FILE;
-import static io.appium.java_client.MobileCommand.PULL_FOLDER;
-
public interface PullsFiles extends ExecutesMethod {
/**
@@ -33,15 +29,16 @@ public interface PullsFiles extends ExecutesMethod {
* built with debuggable flag enabled in order to get access to its container
* on the internal file system.
*
- * @param remotePath If the path starts with @applicationId// prefix, then the file
- * will be pulled from the root of the corresponding application container.
- * Otherwise, the root folder is considered as / on Android and
- * on iOS it is a media folder root (real devices only).
+ * @param remotePath Path to file to read data from the remote device.
+ * Check the documentation on `mobile: pullFile`
+ * extension for more details on possible values
+ * for different platforms.
* @return A byte array of Base64 encoded data.
*/
default byte[] pullFile(String remotePath) {
- Response response = execute(PULL_FILE, ImmutableMap.of("path", remotePath));
- String base64String = response.getValue().toString();
+ String base64String = CommandExecutionHelper.executeScript(this, "mobile: pullFile", ImmutableMap.of(
+ "remotePath", remotePath
+ ));
return Base64.getDecoder().decode(base64String.getBytes(StandardCharsets.UTF_8));
}
@@ -51,15 +48,16 @@ default byte[] pullFile(String remotePath) {
* built with debuggable flag enabled in order to get access to its container
* on the internal file system.
*
- * @param remotePath If the path starts with @applicationId/ prefix, then the folder
- * will be pulled from the root of the corresponding application container.
- * Otherwise, the root folder is considered as / on Android and
- * on iOS it is a media folder root (real devices only).
+ * @param remotePath Path to a folder to read data from the remote device.
+ * Check the documentation on `mobile: pullFolder`
+ * extension for more details on possible values
+ * for different platforms.
* @return A byte array of Base64 encoded zip archive data.
*/
default byte[] pullFolder(String remotePath) {
- Response response = execute(PULL_FOLDER, ImmutableMap.of("path", remotePath));
- String base64String = response.getValue().toString();
+ String base64String = CommandExecutionHelper.executeScript(this, "mobile: pullFolder", ImmutableMap.of(
+ "remotePath", remotePath
+ ));
return Base64.getDecoder().decode(base64String.getBytes(StandardCharsets.UTF_8));
}
diff --git a/src/main/java/io/appium/java_client/PushesFiles.java b/src/main/java/io/appium/java_client/PushesFiles.java
index 552c25a83..813dcb5b1 100644
--- a/src/main/java/io/appium/java_client/PushesFiles.java
+++ b/src/main/java/io/appium/java_client/PushesFiles.java
@@ -16,47 +16,40 @@
package io.appium.java_client;
+import com.google.common.collect.ImmutableMap;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.Base64;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static io.appium.java_client.MobileCommand.pushFileCommand;
-
public interface PushesFiles extends ExecutesMethod {
/**
- * Saves base64 encoded data as a media file on the remote system.
+ * Saves base64-encoded data as a file on the remote system.
*
- * @param remotePath Path to file to write data to on remote device
- * Only the filename part matters there on Simulator, so the remote end
- * can figure out which type of media data it is and save
- * it into a proper folder on the target device. Check
- * 'xcrun simctl addmedia' output to get more details on
- * supported media types.
- * If the path starts with @applicationId/ prefix, then the file
- * will be pushed to the root of the corresponding application container.
+ * @param remotePath Path to file to write data to on remote device.
+ * Check the documentation on `mobile: pushFile`
+ * extension for more details on possible values
+ * for different platforms.
* @param base64Data Base64 encoded byte array of media file data to write to remote device
*/
default void pushFile(String remotePath, byte[] base64Data) {
- CommandExecutionHelper.execute(this, pushFileCommand(remotePath, base64Data));
+ CommandExecutionHelper.executeScript(this, "mobile: pushFile", ImmutableMap.of(
+ "remotePath", remotePath,
+ "payload", new String(base64Data, StandardCharsets.UTF_8)
+ ));
}
/**
- * Saves base64 encoded data as a media file on the remote system.
+ * Sends the file to the remote device.
*
* @param remotePath See the documentation on {@link #pushFile(String, byte[])}
* @param file Is an existing local file to be written to the remote device
- * @throws IOException when there are problems with a file or current file system
+ * @throws IOException when there are problems with a file on current file system
*/
default void pushFile(String remotePath, File file) throws IOException {
- checkNotNull(file, "A reference to file should not be NULL");
- if (!file.exists()) {
- throw new IOException(String.format("The given file %s doesn't exist",
- file.getAbsolutePath()));
- }
pushFile(remotePath, Base64.getEncoder().encode(FileUtils.readFileToByteArray(file)));
}