Changed package name from altosui to AltosUI
[fw/altos] / altosui / AltosDebug.java
index d18de80d09d36e0fe9d84f0652f79bbdbd533d5a..4e39401137c7e137c499462348e830e69d48e016 100644 (file)
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package altosui;
+package AltosUI;
 
 import java.lang.*;
 import java.io.*;
 import java.util.concurrent.*;
 import java.util.*;
+import org.altusmetrum.AltosLib.*;
 
 import libaltosJNI.*;
 
@@ -163,7 +164,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 +177,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