summaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorenikey <enikey@3789f03b-4d11-0410-bbf8-ca57d06f2519>2008-12-25 09:51:03 +0000
committerenikey <enikey@3789f03b-4d11-0410-bbf8-ca57d06f2519>2008-12-25 09:51:03 +0000
commit9823291c3679d3c6d4570897318e4b454c153674 (patch)
treedb4cea0201795fa7e08223903623ae29ed97eec2 /java
parentfd22cd646766a1054bf44ef2e55c9a2f27331c88 (diff)
downloadtigervnc-9823291c3679d3c6d4570897318e4b454c153674.tar.gz
tigervnc-9823291c3679d3c6d4570897318e4b454c153674.zip
[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
Diffstat (limited to 'java')
-rw-r--r--java/src/com/tightvnc/decoder/TightDecoder.java45
1 files 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) {
@@ -467,6 +469,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
//