changeset 48:e6d5ec9ec15e

add splitBufferTest.java
author Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
date Fri, 04 May 2012 01:00:02 +0900
parents 65b798ba8145
children 13dadbb4aa5f
files src/treeVnc/MyRfbProtoProxy.java src/treeVnc/RfbProto.java src/treeVnc/splitBufferTest.java
diffstat 3 files changed, 200 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/src/treeVnc/MyRfbProtoProxy.java	Thu May 03 14:49:53 2012 +0900
+++ b/src/treeVnc/MyRfbProtoProxy.java	Fri May 04 01:00:02 2012 +0900
@@ -9,6 +9,8 @@
 import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -82,7 +84,7 @@
 	private RequestScreenThread rThread;
 	private Thread requestThread;
 
-	public MyRfbProtoProxy() throws IOException {
+	public MyRfbProtoProxy() {
 	}
 
 	MyRfbProtoProxy(String h, int p, VncViewer v) throws IOException {
@@ -788,7 +790,9 @@
 					blen.putInt(len2);
 					blen.flip();
 					bufs.addFirst(blen);
-
+					if(header.getShort(10) > 1080) {
+						System.out.println("error");
+					}
 					bufs.addFirst(header);
 					multicastqueue.put(bufs);
 				}
@@ -1103,7 +1107,19 @@
 		};
 	}
 
-	private LinkedList<ByteBuffer> splitBuffer(LinkedList<ByteBuffer> input,ByteBuffer header) throws IOException {
+	public LinkedList<ByteBuffer> splitBuffer(LinkedList<ByteBuffer> input,
+			ByteBuffer header) throws IOException {
+		/*
+		ByteBuffer testBuffer = ByteBuffer.allocate(16);
+		header.get(testBuffer.array());
+		LinkedList<ByteBuffer> testB = new LinkedList<ByteBuffer>();
+		int t = 0;
+		while(input.size()>t) {
+			testB.addLast(input.get(t));
+			t++;
+		} 
+		*/
+			
 		LinkedList<ByteBuffer> output = new LinkedList<ByteBuffer>();
 		// int high = rectH / 4;
 		// System.out.println(INFLATE_BUFSIZE * (input.size() - 1)+
@@ -1112,7 +1128,7 @@
 		int height = header.getShort(10);
 		int y = header.getShort(6);
 		int dataLen = width * 64 * 3 * 2;
-		int temp = 0,preserv=0;
+		int temp = 0, preserv = 0;
 		int count = height / 128;
 
 		if (width % 64 == 0)
@@ -1130,6 +1146,9 @@
 			if (tempDataLen == INFLATE_BUFSIZE) {
 				output.addLast(input.poll());
 				createHeader(header, i, height, y);
+				if(header.getShort(10) > 1080) {
+					System.out.println("error");
+				}
 				zipSplitData(header, output);
 				output.clear();
 				temp = INFLATE_BUFSIZE;
@@ -1139,18 +1158,56 @@
 
 				// System.out.println(tempBuf.remaining());
 				ByteBuffer buf1 = ByteBuffer.allocate(INFLATE_BUFSIZE);
+				if(tempBuf.remaining()>tempDataLen)
 				tempBuf.get(buf1.array(), 0, tempDataLen);
+				/*
+				if(buf1.get(0)!=0) {
+					System.out.println("error");
+				}
+				*/
 				buf1.limit(tempDataLen);
 				output.addLast(buf1);
 				createHeader(header, i, height, y);
+				/*
+				if(g==1) {
+					// in this area 
+					// in this area 
+					DataOutputStream dataOutStream = 
+					        new DataOutputStream(
+					          new BufferedOutputStream(
+					            new FileOutputStream("./log.tex")));
+					for(ByteBuffer b : testB){
+				        dataOutStream.write(b.array(), 0, b.remaining());
+				      }
+					DataOutputStream dataOutStream1 = 
+					        new DataOutputStream(
+					          new BufferedOutputStream(
+					            new FileOutputStream("./header.txt")));
+						dataOutStream1.write(testBuffer.array(), 0, testBuffer.remaining());
+						System.out.println("-----------");
+					
+				}
+				*/
+				if(header.getShort(10) > 1080) {
+					System.out.println("error");
+				}
+				if(header.getShort(10)!=128) {
+
+					// System.out.println(header.getShort(10));
+				}
 				zipSplitData(header, output);
 				output.clear();
+//				checkPallet(output);
+				
 				// insert into createHeader
 				// insert into this area zipcode and buf1 clear
-				ByteBuffer buf2 = ByteBuffer.allocate(INFLATE_BUFSIZE);
-				tempBuf.get(buf2.array(), 0, tempBuf.remaining());
-				buf2.limit(INFLATE_BUFSIZE - tempDataLen);
-				output.addLast(buf2);
+				buf1 = ByteBuffer.allocate(INFLATE_BUFSIZE);
+				tempBuf.get(buf1.array(), 0, tempBuf.remaining());
+				if(buf1.get(0)!=0) {
+					System.out.println("error");
+				}
+				buf1.limit(INFLATE_BUFSIZE - tempDataLen);
+				output.addLast(buf1);
 				temp = INFLATE_BUFSIZE - tempDataLen;
 			}
 			preserv = i;
@@ -1159,28 +1216,56 @@
 		while (input.size() != 0) {
 			output.addLast(input.poll());
 		}
-		createHeader(header, preserv+1, height, y);
-		zipSplitData(header, output);
+//		checkPallet(output);
+		if(count==0)
+			preserv  -= 1;
+		createHeader(header, preserv + 1, height, y);
+/*
+		if(g==1) {
+			// in this area 
+			DataOutputStream dataOutStream = 
+			        new DataOutputStream(
+			          new BufferedOutputStream(
+			            new FileOutputStream("./log.txt")));
+			for(ByteBuffer b : testB){
+		        dataOutStream.write(b.array(), 0, b.remaining());
+		      }
+
+			DataOutputStream dataOutStream1 = 
+			        new DataOutputStream(
+			          new BufferedOutputStream(
+			            new FileOutputStream("./header.tex")));
+				dataOutStream1.write(testBuffer.array(), 0, testBuffer.remaining());
+				System.out.println("-----------");
+		}
+		*/
+		if(header.getShort(10) > 1080) {
+			System.out.println("error");
+		}
+		if(header.getShort(10)!=128) {
+			zipSplitData(header, output);
+			// System.out.println(header.getShort(10));
+		}
 		output.clear();
-
+		
 		return output;
 	}
 
 	private void splitData(LinkedList<ByteBuffer> input, ByteBuffer header)
 			throws IOException, DataFormatException {
 
-		splitBuffer(input,header);
-//		for (int i = 0; i < (rectH / 128) + 1; i++) {
-//			LinkedList<ByteBuffer> tempBuf = new LinkedList<ByteBuffer>();
-//			while (buf.peek() != null) {
-//				tempBuf.addLast(buf.poll());
-//			}
-//			// Deflater nDeflater = deflater;
-//			zipSplitData(header, tempBuf);
-//			// System.out.println("pass");
-//			if (buf.size() != 0)
-//				buf.remove();
-//		}
+		splitBuffer(input, header);
+		// for (int i = 0; i < (rectH / 128) + 1; i++) {
+		// LinkedList<ByteBuffer> tempBuf = new LinkedList<ByteBuffer>();
+		// while (buf.peek() != null) {
+		// tempBuf.addLast(buf.poll());
+		// }
+		// // Deflater nDeflater = deflater;
+		// zipSplitData(header, tempBuf);
+		// // System.out.println("pass");
+		// if (buf.size() != 0)
+		// buf.remove();
+		// }
 		// System.out.println("throw");
 	}
 
@@ -1194,18 +1279,50 @@
 		blen.putInt(len2);
 		blen.flip();
 		bufs.addFirst(blen);
-//			createHeader(header, i);
+		// createHeader(header, i);
 
 		bufs.addFirst(header);
+		checkHW(header);
 		// broadcastqueue.put(bufs);
 		multicastqueue.put(bufs);
 	}
 
-	private void createHeader(ByteBuffer header, int count,int h,int y) {
+	static void checkHW(ByteBuffer header) {
+		int w = header.getShort(8);
+		int h = header.getShort(10);
+//		System.err.println("p:w="+w+"  h="+h);
+		assert(w>0);
+
+		
+	}
+
+	private void createHeader(ByteBuffer header, int count, int h, int y) {
 		int rH = Math.min(128, h - (128 * count));
 		int rY = y + (128 * count);
-		header.putShort(10, (short) rH);
-		header.putShort(6, (short) rY);
+		if(rH<0) {
+			rY += 128;
+		}
+		header.putShort(10, (short)rH);
+		header.putShort(6, (short)rY);
+	}
+
+	private void checkPallet(LinkedList<ByteBuffer> output) {
+		int check = 64 * 64 * 3 + 1;
+		
+		for (ByteBuffer b : output) {
+			while (true) {
+				if (b.remaining() <= check) {
+					check -= b.limit();
+					break;
+				} else {
+//					System.out.println(b.get(check));
+					if(b.get(check)!=0)
+						b.put(check,(byte)0);
+					check += 64 * 64 * 3 + 1;
+				}
+			}
+		}
+
 	}
 
 }
--- a/src/treeVnc/RfbProto.java	Thu May 03 14:49:53 2012 +0900
+++ b/src/treeVnc/RfbProto.java	Fri May 04 01:00:02 2012 +0900
@@ -126,7 +126,7 @@
 	String host;
 	int port;
 	Socket sock;
-	OutputStream os;
+	public OutputStream os;
 	SessionRecorder rec;
 	boolean inNormalProtocol = false;
 	VncViewer viewer;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/treeVnc/splitBufferTest.java	Fri May 04 01:00:02 2012 +0900
@@ -0,0 +1,55 @@
+package treeVnc;
+
+import static org.junit.Assert.*;
+
+import java.io.BufferedInputStream;
+import java.io.DataInputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.util.LinkedList;
+
+import treeVnc.MyRfbProtoProxy;
+import org.junit.Test;
+
+public class splitBufferTest {
+	MyRfbProtoProxy mrp = new MyRfbProtoProxy();
+
+	@Test
+	public void test() throws IOException {
+		mrp.os = new OutputStream(){
+			@Override
+			public void write(int b) throws IOException {
+			}
+		};
+		
+		LinkedList<ByteBuffer> input = new LinkedList<ByteBuffer>();
+		ByteBuffer header = ByteBuffer.allocate(16);
+		byte[] d = new byte[1024*100];
+		byte b[] = {0, 0, 0, 1, 0, 0, 3, -62, 7, -128, 0, 118, 0, 0, 0, 15};
+		header.put(b);
+		 DataInputStream dataInStream = 
+			        new DataInputStream(
+			          new BufferedInputStream(
+			            new FileInputStream("./log.txt")));
+		 
+		 int readByte = 0,totalByte =0;
+		 while(-1 != (readByte = dataInStream.read(d))){
+			 	ByteBuffer buf = ByteBuffer.allocate(readByte);
+		        buf.put(d, 0, readByte);
+		        totalByte += readByte;
+		        input.addLast(buf);
+		        System.out.println("Read: " + readByte + " Total: " + totalByte);
+		      }
+			
+		try {
+			mrp.splitBuffer(input, header);
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		fail("Not yet implemented");
+	}
+
+}
+