diff --git a/src/se/vidstige/jadb/SyncTransport.java b/src/se/vidstige/jadb/SyncTransport.java index 732bf40..bb72989 100644 --- a/src/se/vidstige/jadb/SyncTransport.java +++ b/src/se/vidstige/jadb/SyncTransport.java @@ -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) { diff --git a/test/se/vidstige/jadb/test/RealDeviceTestCases.java b/test/se/vidstige/jadb/test/RealDeviceTestCases.java index 042d5da..fd0c96b 100644 --- a/test/se/vidstige/jadb/test/RealDeviceTestCases.java +++ b/test/se/vidstige/jadb/test/RealDeviceTestCases.java @@ -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")); + } }