X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosui%2FAltosDebug.java;h=16b10c3af2b07bf278a59f20952723ef2e8fb57b;hp=d18de80d09d36e0fe9d84f0652f79bbdbd533d5a;hb=3fe5c2f9fc01258d45c20070e9874d76bc6c8c07;hpb=924d56a4d2d8b16530cd378b18cfc5d6e08420ed diff --git a/altosui/AltosDebug.java b/altosui/AltosDebug.java index d18de80d..16b10c3a 100644 --- a/altosui/AltosDebug.java +++ b/altosui/AltosDebug.java @@ -17,12 +17,7 @@ package altosui; -import java.lang.*; import java.io.*; -import java.util.concurrent.*; -import java.util.*; - -import libaltosJNI.*; public class AltosDebug extends AltosSerial { @@ -163,7 +158,11 @@ public class AltosDebug extends AltosSerial { int i = 0; byte[] data = new byte[length]; while (i < length) { - String line = get_reply().trim(); + String line = get_reply(); + + if (line == null) + throw new IOException("Timeout in read_bytes"); + line = line.trim(); String tokens[] = line.split("\\s+"); for (int j = 0; j < tokens.length; j++) { if (!Altos.ishex(tokens[j]) || @@ -172,7 +171,12 @@ public class AltosDebug extends AltosSerial { String.format ("Invalid read_bytes reply \"%s\"", line)); try { - data[i + j] = (byte) Integer.parseInt(tokens[j], 16); + if (i + j >= length) + throw new IOException( + String.format + ("Invalid read_bytes reply \"%s\"", line)); + else + data[i + j] = (byte) Integer.parseInt(tokens[j], 16); } catch (NumberFormatException ne) { throw new IOException( String.format