annotate src/myVncClient/SessionRecorder.java @ 18:4881586aead9

succeed drawFirstimage()!!
author e085711
date Tue, 26 Apr 2011 09:08:14 +0900
parents f9ecb0315303
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17
f9ecb0315303 add package
e085711
parents: 0
diff changeset
1 package myVncClient;
0
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
2 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
3 // Copyright (C) 2002 Constantin Kaplinsky. All Rights Reserved.
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
4 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
5 // This is free software; you can redistribute it and/or modify
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
6 // it under the terms of the GNU General Public License as published by
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
7 // the Free Software Foundation; either version 2 of the License, or
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
8 // (at your option) any later version.
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
9 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
10 // This software is distributed in the hope that it will be useful,
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
13 // GNU General Public License for more details.
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
14 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
15 // You should have received a copy of the GNU General Public License
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
16 // along with this software; if not, write to the Free Software
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
18 // USA.
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
19 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
20
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
21 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
22 // SessionRecorder is a class to write FBS (FrameBuffer Stream) files.
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
23 // FBS files are used to save RFB sessions for later playback.
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
24 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
25
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
26 import java.io.*;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
27
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
28 class SessionRecorder {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
29
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
30 protected FileOutputStream f;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
31 protected DataOutputStream df;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
32 protected long startTime, lastTimeOffset;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
33
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
34 protected byte[] buffer;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
35 protected int bufferSize;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
36 protected int bufferBytes;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
37
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
38 public SessionRecorder(String name, int bufsize) throws IOException {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
39 f = new FileOutputStream(name);
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
40 df = new DataOutputStream(f);
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
41 startTime = System.currentTimeMillis();
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
42 lastTimeOffset = 0;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
43
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
44 bufferSize = bufsize;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
45 bufferBytes = 0;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
46 buffer = new byte[bufferSize];
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
47 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
48
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
49 public SessionRecorder(String name) throws IOException {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
50 this(name, 65536);
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
51 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
52
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
53 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
54 // Close the file, free resources.
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
55 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
56
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
57 public void close() throws IOException {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
58 try {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
59 flush();
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
60 } catch (IOException e) {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
61 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
62
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
63 df = null;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
64 f.close();
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
65 f = null;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
66 buffer = null;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
67 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
68
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
69 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
70 // Write the FBS file header as defined in the rfbproxy utility.
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
71 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
72
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
73 public void writeHeader() throws IOException {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
74 df.write("FBS 001.000\n".getBytes());
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
75 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
76
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
77 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
78 // Write one byte.
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
79 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
80
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
81 public void writeByte(int b) throws IOException {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
82 prepareWriting();
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
83 buffer[bufferBytes++] = (byte)b;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
84 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
85
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
86 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
87 // Write 16-bit value, big-endian.
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
88 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
89
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
90 public void writeShortBE(int v) throws IOException {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
91 prepareWriting();
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
92 buffer[bufferBytes++] = (byte)(v >> 8);
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
93 buffer[bufferBytes++] = (byte)v;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
94 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
95
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
96 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
97 // Write 32-bit value, big-endian.
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
98 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
99
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
100 public void writeIntBE(int v) throws IOException {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
101 prepareWriting();
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
102 buffer[bufferBytes] = (byte)(v >> 24);
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
103 buffer[bufferBytes + 1] = (byte)(v >> 16);
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
104 buffer[bufferBytes + 2] = (byte)(v >> 8);
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
105 buffer[bufferBytes + 3] = (byte)v;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
106 bufferBytes += 4;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
107 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
108
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
109 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
110 // Write 16-bit value, little-endian.
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
111 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
112
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
113 public void writeShortLE(int v) throws IOException {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
114 prepareWriting();
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
115 buffer[bufferBytes++] = (byte)v;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
116 buffer[bufferBytes++] = (byte)(v >> 8);
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
117 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
118
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
119 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
120 // Write 32-bit value, little-endian.
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
121 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
122
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
123 public void writeIntLE(int v) throws IOException {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
124 prepareWriting();
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
125 buffer[bufferBytes] = (byte)v;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
126 buffer[bufferBytes + 1] = (byte)(v >> 8);
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
127 buffer[bufferBytes + 2] = (byte)(v >> 16);
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
128 buffer[bufferBytes + 3] = (byte)(v >> 24);
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
129 bufferBytes += 4;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
130 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
131
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
132 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
133 // Write byte arrays.
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
134 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
135
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
136 public void write(byte b[], int off, int len) throws IOException {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
137 prepareWriting();
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
138 while (len > 0) {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
139 if (bufferBytes > bufferSize - 4)
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
140 flush(false);
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
141
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
142 int partLen;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
143 if (bufferBytes + len > bufferSize) {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
144 partLen = bufferSize - bufferBytes;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
145 } else {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
146 partLen = len;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
147 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
148 System.arraycopy(b, off, buffer, bufferBytes, partLen);
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
149 bufferBytes += partLen;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
150 off += partLen;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
151 len -= partLen;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
152 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
153 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
154
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
155 public void write(byte b[]) throws IOException {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
156 write(b, 0, b.length);
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
157 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
158
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
159 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
160 // Flush the output. This method saves buffered data in the
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
161 // underlying file object adding data sizes and timestamps. If the
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
162 // updateTimeOffset is set to false, then the current time offset
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
163 // will not be changed for next write operation.
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
164 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
165
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
166 public void flush(boolean updateTimeOffset) throws IOException {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
167 if (bufferBytes > 0) {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
168 df.writeInt(bufferBytes);
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
169 df.write(buffer, 0, (bufferBytes + 3) & 0x7FFFFFFC);
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
170 df.writeInt((int)lastTimeOffset);
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
171 bufferBytes = 0;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
172 if (updateTimeOffset)
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
173 lastTimeOffset = -1;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
174 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
175 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
176
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
177 public void flush() throws IOException {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
178 flush(true);
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
179 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
180
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
181 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
182 // Before writing any data, remember time offset and flush the
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
183 // buffer before it becomes full.
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
184 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
185
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
186 protected void prepareWriting() throws IOException {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
187 if (lastTimeOffset == -1)
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
188 lastTimeOffset = System.currentTimeMillis() - startTime;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
189 if (bufferBytes > bufferSize - 4)
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
190 flush(false);
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
191 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
192
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
193 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
194