Adding a (potential) initialization for Alarm; Modifying IoTSocket to allocate a...
[iot2.git] / iotjava / iotrmi / Java / IoTSocket.java
index ba8af4a43fbe689eff8afcf160d892801cd450cb..75855132bbc9a988d69515da21cf65970278c7e7 100644 (file)
@@ -85,6 +85,12 @@ public abstract class IoTSocket {
                // Receive until maxlen
                if (maxlen>BUFFSIZE) {
                        System.out.println("IoTSocketClient/Server: Sending more bytes then will fit in buffer! Number of bytes: " + maxlen);
+                       // Allocate a bigger array when needed
+                       int newLen = 2;
+                       while (newLen < maxlen) // Shift until we get a new buffer size that's bigger than maxLen (basically power of 2)
+                               newLen = newLen << 1;
+                       System.out.println("IoTSocketClient/Server: Allocating a bigger buffer now with size: " + newLen);
+                       data = new byte[newLen];
                }
                val = new byte[maxlen];
                while (totalbytes < maxlen)