changeset 5:970d5ac80256

add MyDataInputStream.java and DataInputStream1.java
author one
date Mon, 23 Apr 2012 21:10:23 +0900
parents 657c691c2936
children 01cdbc95142f
files src/treeVnc/DataInputStream1.java src/treeVnc/MyDataInputStream.java src/treeVnc/MyRfbProtoClient.java src/treeVnc/MyRfbProtoProxy.java src/treeVnc/RfbProto.java
diffstat 5 files changed, 144 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/treeVnc/DataInputStream1.java	Mon Apr 23 21:10:23 2012 +0900
@@ -0,0 +1,65 @@
+package treeVnc;
+
+import java.io.BufferedInputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
+
+
+public class DataInputStream1 implements MyDataInputStream {
+	DataInputStream is;
+	public DataInputStream1(BufferedInputStream bufferedInputStream) {
+		is = new DataInputStream(bufferedInputStream);
+	}
+
+	@Override
+	public void readFully(byte[] b, int off, int len) throws IOException {
+		is.readFully(b, off, len);
+	}
+
+	@Override
+	public int available() throws IOException {
+		return is.available();
+	}
+
+	@Override
+	public int skipBytes(int n) throws IOException {
+		return is.skipBytes(n);
+	}
+
+	@Override
+	public int readUnsignedByte() throws IOException {
+		return is.readUnsignedByte();
+	}
+
+	@Override
+	public int readUnsignedShort() throws IOException {
+		return is.readUnsignedShort();
+	}
+
+	@Override
+	public int readInt() throws IOException {
+		return is.readInt();
+	}
+
+	@Override
+	public void read(byte[] headBuf) throws IOException {
+		is.read(headBuf);		
+	}
+
+	@Override
+	public boolean markSupported() {
+		return is.markSupported();
+	}
+
+	@Override
+	public void mark(int i) {
+		is.mark(i);
+	}
+
+	@Override
+	public void reset() {
+		// TODO Auto-generated method stub
+		
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/treeVnc/MyDataInputStream.java	Mon Apr 23 21:10:23 2012 +0900
@@ -0,0 +1,27 @@
+package treeVnc;
+
+import java.io.IOException;
+
+public interface MyDataInputStream {
+
+	void readFully(byte[] b, int off, int len) throws IOException;
+
+	int available() throws IOException;
+
+	int skipBytes(int n) throws IOException;
+
+	int readUnsignedByte() throws IOException;
+
+	int readUnsignedShort() throws IOException;
+
+	int readInt() throws IOException;
+
+	void read(byte[] headBuf) throws IOException;
+
+	boolean markSupported();
+
+	void mark(int i);
+
+	void reset();
+
+}
--- a/src/treeVnc/MyRfbProtoClient.java	Mon Apr 23 20:53:18 2012 +0900
+++ b/src/treeVnc/MyRfbProtoClient.java	Mon Apr 23 21:10:23 2012 +0900
@@ -165,7 +165,7 @@
 		port = p;
 		
 		sock = new Socket(host, port);
-		is = new DataInputStream(new BufferedInputStream(sock.getInputStream(),16384));
+		is = new DataInputStream1(new BufferedInputStream(sock.getInputStream(),16384));
 		os = sock.getOutputStream();
 
 		timing = false;
@@ -393,10 +393,10 @@
 		cliListTmp.clear();
 	}
 
-	boolean ready() throws IOException {
-		BufferedReader br = new BufferedReader(new InputStreamReader(is));
-		return br.ready();
-	}
+//	boolean ready() throws IOException {
+//		BufferedReader br = new BufferedReader(new InputStreamReader(is));
+//		return br.ready();
+//	}
 
 	int cliSize() {
 		return cliList.size();
@@ -407,48 +407,48 @@
 	}
 
 
-	Runnable sendr = new Runnable() {
-		public void run() {
-			broadCastCommnication();	
-		}
-	};
+//	Runnable sendr = new Runnable() {
+//		public void run() {
+//			broadCastCommnication();	
+//		}
+//	};
 		
-	void mcastStart(){
-		new Thread(sendr).start();
-	}
+//	void mcastStart(){
+//		new Thread(sendr).start();
+//	}
 	
 		
-	void broadCastCommnication() {
-		String mcastAddr = "224.0.0.1";
-		int port = 8192;
-		int bufSize = 1024;
-
-        String recvData;
-        is = new DataInputStream(new ByteArrayInputStream(broadCastBuf));
-        
-        try {
-            InetAddress mAddr = InetAddress.getByName(mcastAddr);
-            MulticastSocket soc = new MulticastSocket(port);
-            DatagramPacket recvPacket = new DatagramPacket(broadCastBuf, bufSize);
-
-            soc.joinGroup(mAddr);
-            //System.out.println("マルチキャスト"+mcastAddr+"に参加します");
-
-            while(true) {
-                soc.receive(recvPacket);
-                recvData =new String(recvPacket.getData());
-                recvData = recvData.trim();
-                if(recvData.equals("quit")) {
-                    break;
-                }
-                // System.out.println(recvData);
-            }
-            soc.leaveGroup(mAddr);
-            soc.close();
-        } catch(IOException e) {
-            e.printStackTrace();
-        }
-	}
+//	void broadCastCommnication() {
+//		String mcastAddr = "224.0.0.1";
+//		int port = 8192;
+//		int bufSize = 1024;
+//
+//        String recvData;
+//        is = new DataInputStream(new ByteArrayInputStream(broadCastBuf));
+//        
+//        try {
+//            InetAddress mAddr = InetAddress.getByName(mcastAddr);
+//            MulticastSocket soc = new MulticastSocket(port);
+//            DatagramPacket recvPacket = new DatagramPacket(broadCastBuf, bufSize);
+//
+//            soc.joinGroup(mAddr);
+//            //System.out.println("マルチキャスト"+mcastAddr+"に参加します");
+//
+//            while(true) {
+//                soc.receive(recvPacket);
+//                recvData =new String(recvPacket.getData());
+//                recvData = recvData.trim();
+//                if(recvData.equals("quit")) {
+//                    break;
+//                }
+//                // System.out.println(recvData);
+//            }
+//            soc.leaveGroup(mAddr);
+//            soc.close();
+//        } catch(IOException e) {
+//            e.printStackTrace();
+//        }
+//	}
 	
 	
 	
--- a/src/treeVnc/MyRfbProtoProxy.java	Mon Apr 23 20:53:18 2012 +0900
+++ b/src/treeVnc/MyRfbProtoProxy.java	Mon Apr 23 21:10:23 2012 +0900
@@ -402,10 +402,10 @@
 		cliListTmp.clear();
 	}
 
-	boolean ready() throws IOException {
-		BufferedReader br = new BufferedReader(new InputStreamReader(is));
-		return br.ready();
-	}
+//	boolean ready() throws IOException {
+//		BufferedReader br = new BufferedReader(new InputStreamReader(is));
+//		return br.ready();
+//	}
 
 	int cliSize() {
 		return cliList.size();
--- a/src/treeVnc/RfbProto.java	Mon Apr 23 20:53:18 2012 +0900
+++ b/src/treeVnc/RfbProto.java	Mon Apr 23 21:10:23 2012 +0900
@@ -137,7 +137,7 @@
 	// only via RfbProto methods. We have to do this because we want to
 	// count how many bytes were read.
 	// private DataInputStream is;
-	protected DataInputStream is;
+	protected MyDataInputStream is;
 	// private long numBytesRead = 0;
 	protected long numBytesRead = 0;
 
@@ -216,7 +216,7 @@
 				throw new IOException(e.getMessage());
 			}
 		}
-		is = new DataInputStream(new BufferedInputStream(sock.getInputStream(),
+		is = new DataInputStream1(new BufferedInputStream(sock.getInputStream(),
 				16384));
 		os = sock.getOutputStream();
 
@@ -231,7 +231,7 @@
 
 		sock = newSocket(host, port);
 
-		is = new DataInputStream(new BufferedInputStream(sock.getInputStream(),
+		is = new DataInputStream1(new BufferedInputStream(sock.getInputStream(),
 				16384));
 		os = sock.getOutputStream();
 
@@ -286,7 +286,7 @@
 		host = h;
 		sock = null;
 		sock = newSocket(host, port);
-		is = new DataInputStream(new BufferedInputStream(sock.getInputStream(),
+		is = new DataInputStream1(new BufferedInputStream(sock.getInputStream(),
 				16384));
 		os = sock.getOutputStream();