view src/treeVnc/splitBufferTest.java @ 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
children f77309fa8a9c
line wrap: on
line source

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");
	}

}