Using strong types File and RemoteFile in public arguments where appropriate.

This commit is contained in:
Samuel Carlsson 2014-03-20 11:37:04 +01:00
parent ac47d49cc7
commit 29c3a3956a
3 changed files with 12 additions and 9 deletions

View File

@ -88,11 +88,10 @@ public class JadbDevice {
return 0664;
}
public void push(String localPath, String remotePath) throws IOException, JadbException {
public void push(File local, RemoteFile remote) throws IOException, JadbException {
ensureTransportIsSelected();
SyncTransport sync = transport.startSync();
File local = new File(localPath);
sync.send("SEND", remotePath + "," + Integer.toString(getMode(local)));
sync.send("SEND", remote.getPath() + "," + Integer.toString(getMode(local)));
FileInputStream fileStream = new FileInputStream(local);
sync.sendStream(fileStream);
@ -102,12 +101,12 @@ public class JadbDevice {
sync.verifyStatus();
}
public void pull(String remotePath, String localPath) throws IOException, JadbException {
public void pull(RemoteFile remote, File local) throws IOException, JadbException {
ensureTransportIsSelected();
SyncTransport sync = transport.startSync();
sync.send("RECV", remotePath);
sync.send("RECV", remote.getPath());
FileOutputStream fileStream = new FileOutputStream(new File(localPath));
FileOutputStream fileStream = new FileOutputStream(local);
sync.readChunksTo(fileStream);
fileStream.close();
}

View File

@ -14,4 +14,6 @@ public class RemoteFile {
public int getSize() { throw new NotImplementedException(); }
public long getLastModified() { throw new NotImplementedException(); }
public boolean isDirectory() { throw new NotImplementedException(); }
public String getPath() { return path;}
}

View File

@ -1,11 +1,13 @@
package se.vidstige.jadb.test;
import java.io.File;
import java.util.List;
import org.junit.Test;
import se.vidstige.jadb.JadbDevice;
import se.vidstige.jadb.JadbConnection;
import se.vidstige.jadb.RemoteFile;
import se.vidstige.jadb.RemoteFileRecord;
public class RealDeviceTestCases {
@ -33,7 +35,7 @@ public class RealDeviceTestCases {
List<RemoteFileRecord> files = any.list("/");
for (RemoteFileRecord f : files)
{
System.out.println(f.getName());
System.out.println(f.getPath());
}
}
@ -42,7 +44,7 @@ public class RealDeviceTestCases {
{
JadbConnection jadb = new JadbConnection();
JadbDevice any = jadb.getAnyDevice();
any.push("README.md", "/sdcard/README.md");
any.push(new File("README.md"), new RemoteFile("/sdcard/README.md"));
}
@Test
@ -50,6 +52,6 @@ public class RealDeviceTestCases {
{
JadbConnection jadb = new JadbConnection();
JadbDevice any = jadb.getAnyDevice();
any.pull("/sdcard/README.md", "foobar.md");
any.pull(new RemoteFile("/sdcard/README.md"), new File("foobar.md"));
}
}