package CoreFS.Util;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Map;

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

import CoreFS.SA06.CoreParamObject;
import CoreFS.SA06.CoreReturnObject;

public class StringUtils {	
	public static String Sysid="";
	public static boolean isEmpty(String parameter) {
		return parameter == null || parameter.trim().length() == 0;
	}
	public static String trim(String parameter)
	{
		return	parameter.trim();
	}
	
	 /**
	  * @desc : 对服务端向客户端传递的对象序列化
	  * @create 20100928
	  */
  public static byte[] Serializationparm(CoreReturnObject core) {
		StringBuilder response = new StringBuilder();

		byte[] b = null;
		try {
			ByteArrayOutputStream bos = new ByteArrayOutputStream();
			HessianOutput oos = new HessianOutput(bos);
			oos.writeObject(core);
			oos.close();
			b = bos.toByteArray();
			bos.close();
			oos.close();
		} catch (Exception e) {
			System.out.println("Hessian 不支持该类型");
			e.printStackTrace();
		}
		return b;
	}
 /**
  *@desc : 对客户端的参数对像反序列化
  *@create 20100928
  */
 public static CoreParamObject DeserializeParam(byte[] message) {
		CoreParamObject ob = new CoreParamObject();
		try {

			ByteArrayInputStream bis = new ByteArrayInputStream(message);

			HessianInput ois = new HessianInput(bis);
			ob = (CoreParamObject) ois.readObject();
			ois.close();
			bis.close();
		} catch (Exception e) {
			// throw (new CoreException("没有得到参数对象！"));
			e.printStackTrace();
		}
		return ob;
	}
	
	public static String mainPath="";
	public  void setMainPath(String mainPath) {
		StringUtils.mainPath = mainPath;
	}
	
	public static String ip="";
	public static int port=21;
	public static Boolean isFtp=false;
	public static String userName="";
	public static String  password="";
	
	public  void setIp(String ip) {
		StringUtils.ip = ip;
	}
	public  void setPort(int port) {
		StringUtils.port = port;
	}
	public  void setIsFtp(Boolean isFtp) {
		StringUtils.isFtp = isFtp;
	}
	public  void setUserName(String userName) {
		StringUtils.userName = userName;
	}
	public  void setPassword(String password) {
		StringUtils.password = password;
	}
}
