+ } else { // Launch thread
+
+ loading_url = url;
+ LOG ("textclient launching %s...", url);
+
+ new Thread (new Runnable() {
+ public void run() {
+ int size0 = 10240;
+ int size = size0;
+ int count = 0;
+ ByteBuffer body = ByteBuffer.allocateDirect (size);
+
+ try {
+ URL u = new URL (loading_url);
+ // LOG ("textclient thread loading: %s", u.toString());
+ InputStream s = u.openStream();
+ byte buf[] = new byte[10240];
+ while (true) {
+ int n = s.read (buf);
+ if (n == -1) break;
+ // LOG ("textclient thread read %d", n);
+ if (count + n + 1 >= size) {
+ int size2 = (int) (size * 1.2 + size0);
+ // LOG ("textclient thread expand %d -> %d", size, size2);
+ ByteBuffer body2 = ByteBuffer.allocateDirect (size2);
+ body.rewind();
+ body2.put (body);
+ body2.position (count);
+ body = body2;
+ size = size2;
+ }
+ body.put (buf, 0, n);
+ count += n;
+ }
+ } catch (Exception e) {
+ LOG ("load URL error: %s", e.toString());
+ body.clear();
+ body.put (e.toString().getBytes());
+ body.put ((byte) 0);
+ }
+
+ // LOG ("textclient thread finished %s (%d)", loading_url, size);
+ loaded_url_body = body;
+ }
+ }).start();
+
+ return null;
+ }