Fixing a problem where errors during pull where not handled correctly.

This commit is contained in:
Samuel Carlsson 2014-03-20 21:31:25 +01:00
parent c28902385f
commit c051da8e7f
2 changed files with 15 additions and 3 deletions

View File

@ -70,10 +70,14 @@ class SyncTransport {
output.write(buffer, offset, length);
}
private int readChunk(byte[] buffer) throws IOException {
private int readChunk(byte[] buffer) throws IOException, JadbException {
String id = readString(4);
if (!"DATA".equals(id)) return -1;
int n = readInt();
if ("FAIL".equals(id))
{
throw new JadbException(readString(n));
}
if (!"DATA".equals(id)) return -1;
return input.read(buffer, 0, n);
}
@ -86,7 +90,7 @@ class SyncTransport {
}
}
public void readChunksTo(OutputStream stream) throws IOException {
public void readChunksTo(OutputStream stream) throws IOException, JadbException {
byte[] buffer = new byte[1024 * 64];
int n = readChunk(buffer);
while (n != -1) {

View File

@ -62,4 +62,12 @@ public class RealDeviceTestCases {
JadbDevice any = jadb.getAnyDevice();
any.pull(new RemoteFile("/sdcard/README.md"), new File("foobar.md"));
}
@Test(expected = JadbException.class)
public void testPullInvalidFile() throws Exception
{
JadbConnection jadb = new JadbConnection();
JadbDevice any = jadb.getAnyDevice();
any.pull(new RemoteFile("/file/does/not/exist"), new File("xyz"));
}
}