mirror of
https://github.com/revanced/jadb.git
synced 2025-02-11 01:26:47 +01:00
Refactor: Creating RemoteFile base class to be used as arguments.
This commit is contained in:
parent
6c01fcc86c
commit
ac47d49cc7
@ -70,13 +70,13 @@ public class JadbDevice {
|
||||
send("shell:" + shellLine.toString());
|
||||
}
|
||||
|
||||
public List<RemoteFile> list(String remotePath) throws IOException, JadbException {
|
||||
public List<RemoteFileRecord> list(String remotePath) throws IOException, JadbException {
|
||||
ensureTransportIsSelected();
|
||||
SyncTransport sync = transport.startSync();
|
||||
sync.send("LIST", remotePath);
|
||||
|
||||
List<RemoteFile> result = new ArrayList<RemoteFile>();
|
||||
for (RemoteFile dent = sync.readDirectoryEntry(); dent != RemoteFile.DONE; dent = sync.readDirectoryEntry())
|
||||
List<RemoteFileRecord> result = new ArrayList<RemoteFileRecord>();
|
||||
for (RemoteFileRecord dent = sync.readDirectoryEntry(); dent != RemoteFileRecord.DONE; dent = sync.readDirectoryEntry())
|
||||
{
|
||||
result.add(dent);
|
||||
}
|
||||
|
@ -1,37 +1,17 @@
|
||||
package se.vidstige.jadb;
|
||||
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
/**
|
||||
* Created by vidstige on 2014-03-19.
|
||||
* Created by vidstige on 2014-03-20
|
||||
*/
|
||||
public class RemoteFile {
|
||||
public static final RemoteFile DONE = new RemoteFile("DONE", null, 0, 0, 0);
|
||||
private final String path;
|
||||
|
||||
private final String name;
|
||||
private final int mode;
|
||||
private final int size;
|
||||
private final long lastModified;
|
||||
public RemoteFile(String path) { this.path = path;}
|
||||
|
||||
public RemoteFile(String id, String name, int mode, int size, long lastModified) {
|
||||
this.name = name;
|
||||
this.mode = mode;
|
||||
this.size = size;
|
||||
this.lastModified = lastModified;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public long getLastModified() {
|
||||
return lastModified;
|
||||
}
|
||||
|
||||
public boolean isDirectory() {
|
||||
return (mode & (1 << 14)) == (1 << 14);
|
||||
}
|
||||
public String getName() { throw new NotImplementedException(); }
|
||||
public int getSize() { throw new NotImplementedException(); }
|
||||
public long getLastModified() { throw new NotImplementedException(); }
|
||||
public boolean isDirectory() { throw new NotImplementedException(); }
|
||||
}
|
||||
|
34
src/se/vidstige/jadb/RemoteFileRecord.java
Normal file
34
src/se/vidstige/jadb/RemoteFileRecord.java
Normal file
@ -0,0 +1,34 @@
|
||||
package se.vidstige.jadb;
|
||||
|
||||
/**
|
||||
* Created by vidstige on 2014-03-19.
|
||||
*/
|
||||
public class RemoteFileRecord extends RemoteFile{
|
||||
public static final RemoteFileRecord DONE = new RemoteFileRecord(null, 0, 0, 0);
|
||||
|
||||
private final int mode;
|
||||
private final int size;
|
||||
private final long lastModified;
|
||||
|
||||
public RemoteFileRecord(String name, int mode, int size, long lastModified) {
|
||||
super(name);
|
||||
this.mode = mode;
|
||||
this.size = size;
|
||||
this.lastModified = lastModified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastModified() {
|
||||
return lastModified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirectory() {
|
||||
return (mode & (1 << 14)) == (1 << 14);
|
||||
}
|
||||
}
|
@ -52,7 +52,7 @@ class SyncTransport {
|
||||
return new String(buffer, Charset.forName("utf-8"));
|
||||
}
|
||||
|
||||
public RemoteFile readDirectoryEntry() throws IOException {
|
||||
public RemoteFileRecord readDirectoryEntry() throws IOException {
|
||||
String id = readString(4);
|
||||
int mode = readInt();
|
||||
int size = readInt();
|
||||
@ -60,8 +60,8 @@ class SyncTransport {
|
||||
int nameLength = readInt();
|
||||
String name = readString(nameLength);
|
||||
|
||||
if (!"DENT".equals(id)) return RemoteFile.DONE;
|
||||
return new RemoteFile(id, name, mode, size, time);
|
||||
if (!"DENT".equals(id)) return RemoteFileRecord.DONE;
|
||||
return new RemoteFileRecord(name, mode, size, time);
|
||||
}
|
||||
|
||||
private void sendChunk(byte[] buffer, int offset, int length) throws IOException {
|
||||
|
@ -6,7 +6,7 @@ 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 {
|
||||
|
||||
@ -30,8 +30,8 @@ public class RealDeviceTestCases {
|
||||
{
|
||||
JadbConnection jadb = new JadbConnection();
|
||||
JadbDevice any = jadb.getAnyDevice();
|
||||
List<RemoteFile> files = any.list("/");
|
||||
for (RemoteFile f : files)
|
||||
List<RemoteFileRecord> files = any.list("/");
|
||||
for (RemoteFileRecord f : files)
|
||||
{
|
||||
System.out.println(f.getName());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user