oops, bad commit! I only meant to commit the changes to the TightDecoder.

git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4822 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/java/com/tigervnc/rdr/InStream.java b/java/com/tigervnc/rdr/InStream.java
index f998025..a18ea4e 100644
--- a/java/com/tigervnc/rdr/InStream.java
+++ b/java/com/tigervnc/rdr/InStream.java
@@ -30,7 +30,6 @@
   // maximum of nItems).
 
   public int check(int itemSize, int nItems, boolean wait) {
-/*
     int available = end - ptr;
     if (itemSize * nItems > available) {
       if (itemSize > available)
@@ -39,14 +38,6 @@
       nItems = available / itemSize;
     }
     return nItems;
-*/
-    if (ptr + itemSize * nItems > end) {
-      if (ptr + itemSize > end)
-        return overrun(itemSize, nItems, wait);
-
-      nItems = (end - ptr) / itemSize;
-    }
-    return nItems;
   }
 
   public int check(int itemSize, int nItems) { return check(itemSize, nItems, true); }
@@ -120,17 +111,14 @@
   // no byte-ordering, we just use big-endian.
 
   public final int readOpaque8()  { return readU8(); }
-  public final int readOpaque16() { check(2); int r0 = b[ptr++];
-                                    int r1 = b[ptr++]; return r0 << 8 | r1; }
-  public final int readOpaque32() { check(4); int r0 = b[ptr++]; int r1 = b[ptr++]; 
-                                    int r2 = b[ptr++]; int r3 = b[ptr++]; 
-                                    return r0 << 24 | r1 << 16 | r2 << 8 | r3; }
-  public final int readOpaque24A() { check(3, 1, true); int r0 = b[ptr++];
-                                     int r1 = b[ptr++]; int r2 = b[ptr++];
-                                     return r0 << 24 | r1 << 16 | r2 << 8; }
-  public final int readOpaque24B() { check(3, 1, true); int r0 = b[ptr++];
-                                     int r1 = b[ptr++]; int r2 = b[ptr++];
-                                     return r0 << 16 | r1 << 8 | r2; }
+  public final int readOpaque16() { return readU16(); }
+  public final int readOpaque32() { return readU32(); }
+  public final int readOpaque24A() { check(3, 1, true); int b0 = b[ptr++];
+                                     int b1 = b[ptr++]; int b2 = b[ptr++];
+                                     return b0 << 24 | b1 << 16 | b2 << 8; }
+  public final int readOpaque24B() { check(3, 1, true); int b0 = b[ptr++];
+                                     int b1 = b[ptr++]; int b2 = b[ptr++];
+                                     return b0 << 16 | b1 << 8 | b2; }
 
   public final int readPixel(int bytesPerPixel, boolean bigEndian) {
     byte[] pix = new byte[4];
@@ -202,5 +190,4 @@
   protected byte[] b;
   protected int ptr;
   protected int end;
-  protected int start;
 }
diff --git a/java/com/tigervnc/rdr/JavaInStream.java b/java/com/tigervnc/rdr/JavaInStream.java
index fb6ab8b..faa968a 100644
--- a/java/com/tigervnc/rdr/JavaInStream.java
+++ b/java/com/tigervnc/rdr/JavaInStream.java
@@ -21,37 +21,25 @@
 //
 
 package com.tigervnc.rdr;
-import java.io.InputStream;
-import java.io.DataInputStream;
 
 public class JavaInStream extends InStream {
 
   static final int defaultBufSize = 8192;
   static final int minBulkSize = 1024;
 
-  public JavaInStream(InputStream jis_, int bufSize_) 
-  {
-    jis = new DataInputStream(jis_);
+  public JavaInStream(java.io.InputStream jis_, int bufSize_) {
+    jis = jis_;
     bufSize = bufSize_;
     b = new byte[bufSize];
-    ptr = end = offset = start = 0;
+    ptr = end = offset = 0;
     timing = false;
     timeWaitedIn100us = 5;
     timedKbits = 0;
   }
 
-  public JavaInStream(InputStream jis_) 
-  {
-    this(jis_, defaultBufSize);
-  }
+  public JavaInStream(java.io.InputStream jis_) { this(jis_, defaultBufSize); }
 
-  public int pos() 
-  {
-    return offset + ptr - start;
-  }
-
-  public void readBytes(byte[] data, int dataPtr, int length) 
-  {
+  public void readBytes(byte[] data, int dataPtr, int length) {
     if (length < minBulkSize) {
       super.readBytes(data, dataPtr, length);
       return;
@@ -73,32 +61,56 @@
     }
   }
 
+  public int pos() { return offset + ptr; }
+
+  public void startTiming() {
+    timing = true;
+
+    // Carry over up to 1s worth of previous rate for smoothing.
+
+    if (timeWaitedIn100us > 10000) {
+      timedKbits = timedKbits * 10000 / timeWaitedIn100us;
+      timeWaitedIn100us = 10000;
+    }
+  }
+
+  public void stopTiming() {
+    timing = false; 
+    if (timeWaitedIn100us < timedKbits/2)
+      timeWaitedIn100us = timedKbits/2; // upper limit 20Mbit/s
+  }
+
+  public long kbitsPerSecond() {
+    return timedKbits * 10000 / timeWaitedIn100us;
+  }
+
+  public long timeWaited() { return timeWaitedIn100us; }
+
   protected int overrun(int itemSize, int nItems, boolean wait) {
     if (itemSize > bufSize)
       throw new Exception("JavaInStream overrun: max itemSize exceeded");
 
     if (end - ptr != 0)
-      System.arraycopy(b, ptr, b, start, end - ptr);
+      System.arraycopy(b, ptr, b, 0, end - ptr);
 
-    offset += ptr - start;
-    end -= ptr - start;
-    ptr = start;
+    offset += ptr;
+    end -= ptr;
+    ptr = 0;
 
-    int bytes_to_read;
-    while (end < start + itemSize) {
-      bytes_to_read = start + bufSize - end;
+    while (end < itemSize) {
+      int bytes_to_read = bufSize - end;
 
       if (!timing) {
         bytes_to_read = Math.min(bytes_to_read, Math.max(itemSize*nItems, 8));
       }
 
       int n = read(b, end, bytes_to_read, wait);
-      if (n == 0) return 0;
+
       end += n;
     }
 
-    if (itemSize * nItems > end - ptr)
-      nItems = (end - ptr) / itemSize;
+    if (itemSize * nItems > end)
+      nItems = end / itemSize;
 
     return nItems;
   }
@@ -110,17 +122,7 @@
 
       int n = -1;
       try {
-        //System.out.println("available: "+jis.available());
-        //int available = jis.available();
-        //if (!wait && (available == 0))
-        //  return 0;
-        //if (available > 0 && available < len) {
-        //  n = jis.read(buf, bufPtr, available);
-        //} else {  
-          n = jis.read(buf, bufPtr, len);
-        //}
-      } catch (java.net.SocketTimeoutException e) {
-        return Math.max(n,0);
+        n = jis.read(buf, bufPtr, len);
       } catch (java.io.IOException e) {
         throw new IOException(e);
       }
@@ -148,34 +150,9 @@
       return n;
 
   }
-  private int read(byte[] buf, int bufPtr, int len) { 
-    return read(buf, bufPtr, len, true); 
-  }
+  private int read(byte[] buf, int bufPtr, int len) { return read(buf, bufPtr, len, true); }
 
-  public void startTiming() {
-    timing = true;
-
-    // Carry over up to 1s worth of previous rate for smoothing.
-
-    if (timeWaitedIn100us > 10000) {
-      timedKbits = timedKbits * 10000 / timeWaitedIn100us;
-      timeWaitedIn100us = 10000;
-    }
-  }
-
-  public void stopTiming() {
-    timing = false; 
-    if (timeWaitedIn100us < timedKbits/2)
-      timeWaitedIn100us = timedKbits/2; // upper limit 20Mbit/s
-  }
-
-  public long kbitsPerSecond() {
-    return timedKbits * 10000 / timeWaitedIn100us;
-  }
-
-  public long timeWaited() { return timeWaitedIn100us; }
-
-  private DataInputStream jis;
+  private java.io.InputStream jis;
   private int offset;
   private int bufSize;
 
diff --git a/java/com/tigervnc/rdr/ZlibInStream.java b/java/com/tigervnc/rdr/ZlibInStream.java
index 44f4828..46b1c50 100644
--- a/java/com/tigervnc/rdr/ZlibInStream.java
+++ b/java/com/tigervnc/rdr/ZlibInStream.java
@@ -138,4 +138,5 @@
   private int offset;
   private com.jcraft.jzlib.ZStream zs;
   private int bytesIn;
+  private int start;
 }