From 9823291c3679d3c6d4570897318e4b454c153674 Mon Sep 17 00:00:00 2001 From: enikey Date: Thu, 25 Dec 2008 09:51:03 +0000 Subject: [PATCH] [Refactoring] Move "recordCompactLen", "recordCompressedData" methods from class RfbProto to TightDecoder. Completely don't using RecordInterface in tight decoder to record session. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@3468 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- .../com/tightvnc/decoder/TightDecoder.java | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/java/src/com/tightvnc/decoder/TightDecoder.java b/java/src/com/tightvnc/decoder/TightDecoder.java index f7fab75f..015f73cd 100644 --- a/java/src/com/tightvnc/decoder/TightDecoder.java +++ b/java/src/com/tightvnc/decoder/TightDecoder.java @@ -8,6 +8,8 @@ import java.awt.Image; import java.awt.Rectangle; import java.awt.Toolkit; import java.awt.image.ImageObserver; +import java.io.IOException; +import java.util.zip.Deflater; import java.util.zip.Inflater; // @@ -144,7 +146,7 @@ public class TightDecoder extends RawDecoder implements ImageObserver { byte[] jpegData = new byte[rfbis.readCompactLen()]; rfbis.readFully(jpegData); if (dos != null) { - rec.recordCompactLen(jpegData.length); + recordCompactLen(jpegData.length); dos.write(jpegData); } @@ -298,7 +300,7 @@ public class TightDecoder extends RawDecoder implements ImageObserver { byte[] buf = new byte[dataSize]; myInflater.inflate(buf); if (dos != null) { - rec.recordCompressedData(buf); + recordCompressedData(buf); } if (numColors != 0) { @@ -466,6 +468,45 @@ public class TightDecoder extends RawDecoder implements ImageObserver { } } + // + // Write an integer in compact representation (1..3 bytes) into the + // recorded session file. + // + + void recordCompactLen(int len) throws IOException { + byte[] buf = new byte[3]; + int bytes = 0; + buf[bytes++] = (byte)(len & 0x7F); + if (len > 0x7F) { + buf[bytes-1] |= 0x80; + buf[bytes++] = (byte)(len >> 7 & 0x7F); + if (len > 0x3FFF) { + buf[bytes-1] |= 0x80; + buf[bytes++] = (byte)(len >> 14 & 0xFF); + } + } + if (dos != null) dos.write(buf, 0, bytes); + } + + // + // Compress and write the data into the recorded session file. + // + + void recordCompressedData(byte[] data, int off, int len) throws IOException { + Deflater deflater = new Deflater(); + deflater.setInput(data, off, len); + int bufSize = len + len / 100 + 12; + byte[] buf = new byte[bufSize]; + deflater.finish(); + int compressedSize = deflater.deflate(buf); + recordCompactLen(compressedSize); + if (dos != null) dos.write(buf, 0, compressedSize); + } + + void recordCompressedData(byte[] data) throws IOException { + recordCompressedData(data, 0, data.length); + } + // // Private members // -- 2.39.5