package TestUpdate;

import java.beans.XMLEncoder;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.UnsupportedEncodingException;

import com.caucho.hessian.io.Hessian2Input;
import com.caucho.hessian.io.Hessian2Output;
import com.caucho.hessian.io.HessianInput;
import com.caucho.hessian.io.HessianOutput;


public class TestCls {
	public static void main(String[] args) throws UnsupportedEncodingException {
		
//		UpLoadBean u=new UpLoadBean();
//		u.setFileName("Hessiancsharp.dll");
//		u.setMessage("11");
//		u.setStatu("22");
//		u.setUpLoadDir("/CoreFS.AutoUpdate");
	    String str = "123.txt";
	    System.out.println(str.substring(0,str.lastIndexOf(".")));
	    System.out.println(str.substring(str.lastIndexOf(".")+1));
	    
		TestBean u=new TestBean();
		u.v_id="1";
		u.v_errCode=0;
		u.v_errMsg="1";
		u.v_formkey="2";
		u.v_ip="3";
		u.v_method="t";
		u.v_mid="z";
		u.v_serviceName="s";
		u.v_reqParameters=new Object[]{"55"};
			
		//序列化
		byte[] b = null;
		try {
			ByteArrayOutputStream bos = new ByteArrayOutputStream();
			
			HessianOutput oos = new HessianOutput(bos);
			oos.writeObject(u);
			oos.close();
			b = bos.toByteArray();
			bos.close();
			oos.close();
		} catch (Exception e) {
			System.out.println("Hessian 不支持该类型");
			e.printStackTrace();
		}
//		try{
//		 ByteArrayInputStream is = new ByteArrayInputStream(b);   
//		    ObjectInputStream in = new ObjectInputStream(is);   
//		    Object obj= in.readObject();   
//		}catch (Exception e) {
//			// TODO: handle exception
//			e.printStackTrace();
//		}
		
		//反序列化
		try {
			TestBean ob=new TestBean();
			ByteArrayInputStream bis = new ByteArrayInputStream(b);
			int tt=bis.read();
			HessianInput ois = new HessianInput(bis);
			ob = (TestBean) ois.readObject(TestBean.class);
			ois.close();
			bis.close();
		} catch (Exception e) {
			// throw (new CoreException("没有得到参数对象！"));
			e.printStackTrace();
		}
		
//		  ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
//	       BufferedOutputStream bufferOut = new BufferedOutputStream(byteArrayOut);
//	       XMLEncoder  xmlEncoder=null;
//	       try{
//	    	   xmlEncoder = new XMLEncoder(bufferOut);
//	    	   xmlEncoder.writeObject(u);
//	       }finally{
//	            if(null != xmlEncoder)
//	            	xmlEncoder.close();
//	        }
//		XStream xstream = new XStream();  
//		xstream.toXML(u,bufferOut);
//         byte[] bys = byteArrayOut.toByteArray();
//         String txt =new String(bys,"utf-8");
//         System.out.println(txt);
//         try {
//			byteArrayOut.close();
//			bufferOut.close();
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
         

	}
}
