⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcubytelists.java

📁 为公司做的质量考核接口源码,用spring,hibernate,XML实现,对XML接口编程很有帮助
💻 JAVA
字号:
/**
 * 
 */
package com.jr81.source.xml.source;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Vector;


import com.jr81.common.JrUtility;

/**
 * @author new
 *
 */
public class TcuByteLists implements TcuInterfaceByteLists {
	private Vector Items = new Vector();
	private int Size=0;
	
	/* (non-Javadoc)
	 * @see com.xmlpack.TcuInterfaceLists#Clear()
	 */
	public void Clear() {
		// TODO Auto-generated method stub
		Items.clear();
		Size=0;
	}

	/* (non-Javadoc)
	 * @see com.xmlpack.TcuInterfaceLists#GetCount()
	 */
	public int GetCount() {
		// TODO Auto-generated method stub
		return Items.size();
	}

	/* (non-Javadoc)
	 * @see com.xmlpack.TcuInterfaceLists#GetLength()
	 */
	public int GetLength() {
		// TODO Auto-generated method stub
		return Size;
	}

	/* (non-Javadoc)
	 * @see com.xmlpack.TcuInterfaceLists#AddList(com.xmlpack.TcuXmlList)
	 */
	public void AddList(TcuByteList value) {
		// TODO Auto-generated method stub
		Items.add(value);
		Size+=value.getSize();
	}

	/* (non-Javadoc)
	 * @see com.xmlpack.TcuInterfaceLists#AddList(byte[], byte[])
	 */
	public void AddList(byte[] name, byte[] value) {
		// TODO Auto-generated method stub
		AddList(name,value,0);
	}

	/* (non-Javadoc)
	 * @see com.xmlpack.TcuInterfaceLists#AddList(byte[], byte[], int)
	 */
	public void AddList(byte[] name, byte[] value, int type) {
		// TODO Auto-generated method stub
		TcuByteList BaseItem = new TcuByteList();
		BaseItem.setName(name);
		BaseItem.setValue(value);
		BaseItem.setItemTag(type);
		AddList(BaseItem);
	}

	/* (non-Javadoc)
	 * @see com.xmlpack.TcuInterfaceLists#DeleteList(int)
	 */
	public void DeleteList(int index) {
		// TODO Auto-generated method stub
		Size=Size-((TcuByteList) GetList(index)).getSize();
		Items.remove(index);
	}

	/* (non-Javadoc)
	 * @see com.xmlpack.TcuInterfaceLists#DeleteList(java.lang.String)
	 */
	public void DeleteList(String name) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see com.xmlpack.TcuInterfaceLists#GetList(int)
	 */
	public TcuByteList GetList(int index) {
		// TODO Auto-generated method stub
		return  (TcuByteList) Items.elementAt(index);
	}

	/* (non-Javadoc)
	 * @see com.xmlpack.TcuInterfaceLists#GetList(java.lang.String)
	 */
	public TcuByteList GetList(String name) {
		// TODO Auto-generated method stub
		for(int i=0;i<Items.size();i++){
			String Name=new String(GetList(i).getName());
			//if (Item(i).getName().equals(name.getBytes())){
			if (Name.toUpperCase().equals(name.toUpperCase())){
				return GetList(i);				
			}
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see com.xmlpack.TcuInterfaceLists#GetListByteValue(java.lang.String)
	 */
	public byte[] GetListByteValue(String name) {
		// TODO Auto-generated method stub
		return GetList(name).getValue();
	}

	/* (non-Javadoc)
	 * @see com.xmlpack.TcuInterfaceLists#GetListStrValue(java.lang.String)
	 */
	public String GetListStrValue(String name) {
		// TODO Auto-generated method stub
		String value=new String(GetList(name).getValue());
		if (value.length()>0){
			return value;
		}
		else
			return "";
	}

	/* (non-Javadoc)
	 * @see com.xmlpack.TcuInterfaceLists#Assign(com.xmlpack.TcuLists)
	 */
	public void Assign(TcuLists value) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see com.xmlpack.TcuInterfaceLists#FromByteXml(byte[])
	 */
	public boolean FromByteXml(byte[] value) {
		// TODO Auto-generated method stub
		if (value==null){
			System.out.println("BaseItems fromByteArray error,Null bytearray");
			return false;
		}
		ByteArrayInputStream in=new ByteArrayInputStream(value);
		return fromStream(in);
	}

	/* (non-Javadoc)
	 * @see com.xmlpack.TcuInterfaceLists#ToByteXml()
	 */
	public byte[] ToByteXml() throws IOException {
		// TODO Auto-generated method stub
		return ((ByteArrayOutputStream)toStream()).toByteArray();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

	public void AddList(TcuXmlList value) {
		// TODO Auto-generated method stub
		Items.add(value);
		Size+=value.GetLength();
	}

	public void AddList(byte[] name, boolean value) {
		// TODO Auto-generated method stub
		if (value){
			AddList(name,"-1".getBytes(),0);
		}
		else{
			AddList(name,"0".getBytes(),0);	
		}
	}

	public void AddList(byte[] name, int value) {
		// TODO Auto-generated method stub
		AddList(name,Integer.toString(value).getBytes(),0);
	}

	public void AddList(byte[] name, float value) {
		// TODO Auto-generated method stub
		AddList(name,Float.toString(value).getBytes(),0);
	}

	public boolean GetListBooleanValue(String name) {
		// TODO Auto-generated method stub
		if (GetList(name).equals("-1")){
			return true;
		}
		else			
		return false;	
	}

	public float GetListFloatValue(String name) {
		// TODO Auto-generated method stub
		return Float.parseFloat(GetListStrValue(name));	
	}

	public int GetListIntValue(String name) {
		// TODO Auto-generated method stub
		return Integer.valueOf(GetListStrValue(name)).intValue();	
	}

	public OutputStream toStream() throws IOException {
		// TODO Auto-generated method stub
		ByteArrayOutputStream result=new ByteArrayOutputStream(Size+4*GetCount()+4);
		byte[] inLength = new byte[4];
		
		///写入ItemsCount
		inLength = JrUtility.int2bytes(GetCount());
		result.write(inLength,0,4);
		
		for(int i=0;i<Items.size();i++){
			TcuByteList BaseItem = (TcuByteList)GetList(i);			
			
			//写入ItemSize
			inLength = JrUtility.int2bytes(BaseItem.getSize());
			result.write(inLength,0,4);
			
			//写入Item内容
			result.write(((ByteArrayOutputStream) BaseItem.toStream()).toByteArray(),0,BaseItem.getSize());
		}		
		return result;
	}

	public boolean fromStream(InputStream value) {
		// TODO Auto-generated method stub
		try{
			Clear();
			byte[] inLength = new byte[4];
			int size=0;
			
			value.read(inLength,0,4);
			int count = JrUtility.bytes2int(inLength);
			for (int i=0;i<count;i++){
				value.read(inLength,0,4);
				size = JrUtility.bytes2int(inLength);
				byte[] buffer = new byte[size];
				value.read(buffer,0,size);
				ByteArrayInputStream in=new ByteArrayInputStream(buffer);
				TcuByteList BaseItem =new TcuByteList ();
				BaseItem.fromStream(in);
				AddList(BaseItem);
			}
			return true;
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}	
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -