changeset 573:4636bbd2e1f7

bytes can unzip in checkroutine
author riono
date Thu, 06 Feb 2020 21:57:35 +0900
parents a0eeba3ee5d4
children 3f1d576e182d
files src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java
diffstat 1 files changed, 43 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java	Thu Feb 06 20:02:19 2020 +0900
+++ b/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java	Thu Feb 06 21:57:35 2020 +0900
@@ -46,6 +46,9 @@
 import java.util.LinkedList;
 import java.util.Timer;
 import java.util.logging.Logger;
+import java.util.Objects;
+import java.util.zip.DataFormatException;
+import java.util.zip.Inflater;
 
 
 public class ReceiverTask implements Runnable {
@@ -382,6 +385,18 @@
             }
             in.readByte();
             int numberOfRectangeles = in.readInt16();
+
+            Reader checkReaderC1 = new Reader(new ByteArrayInputStream(c1.array()));
+            checkReaderC1.readByte();      // message ID
+            checkReaderC1.readByte();      // padding
+            checkReaderC1.readInt16();     // num of rectangle
+
+            FramebufferUpdateRectangle checkRect = new FramebufferUpdateRectangle();
+            checkRect.fill(checkReaderC1);
+            int length = checkRect.width * checkRect.height * renderer.getBytesPerPixel();
+            int zippedLength = (int) checkReaderC1.readUInt32();
+            byte[] unzipBytes = unzip(checkReaderC1, zippedLength, length, checkRect.getEncodingType());
+            CompairBytes(unzipBytes, checkBytes, flushOffset, flushEnd);
             while (numberOfRectangeles-- > 0) {
                 rect.fill(in);
                 System.out.println("check rect " + rect);
@@ -395,8 +410,35 @@
         }
     }
 
-    private void CompairBytes(Byte[] checkBytes, int flushOffset, int flushEnd) {
+    private void CompairBytes(byte[] compressBytes, byte[] unCompressBytes, int flushOffset, int flushEnd) {
+        if (compressBytes.length == (flushEnd - flushOffset)) {
+            if (Objects.deepEquals(compressBytes, unCompressBytes)) {
+                System.out.println("Bytes compair is true");
+            } else {
+                System.out.println("Bytes is not equal elements");
+            }
+        }else {
+            System.out.println("Bytes is not equal lenght");
+        }
+    }
 
+    private byte[] unzip(Reader reader, int zippedLength, int length,EncodingType encodingType)
+            throws TransportException {
+        Inflater decoder = null;
+        byte [] bytes = com.glavsoft.rfb.encoding.decoder.ByteBuffer.getInstance().getBuffer(zippedLength + length);
+        reader.readBytes(bytes, 0, zippedLength);
+        if (encodingType == EncodingType.ZRLEE) {
+            //decoder = new ZRLEDecoder();
+            decoder = new Inflater();
+        }
+        decoder.setInput(bytes, 0, zippedLength);
+        try {
+            //messageDump(bytes, "inflate: ");
+            decoder.inflate(bytes, zippedLength, length);
+        } catch (DataFormatException e) {
+            throw new TransportException("cannot inflate Zlib data", e);
+        }
+        return bytes;
     }
 
     private void setScreenParameter(FramebufferUpdateRectangle rect,int singleWidth ,int singleHeight) {