package lava.net.common; import java.util.Vector; import lava.net.common.VariableModifier; /** * **/ public class Packet { /** * **/ private Vector header = null; /** * **/ private String body = null; /** * **/ public Packet() { header = new Vector(); } /** * **/ public Packet(Vector header, String body) { this.header = header == null ? new Vector() : header; this.body = body; } /** * **/ protected void addVariableModifier(VariableModifier modifier) { if(modifier == null) return; header.addElement(modifier); } /** * **/ public void setVariable(String name, Value value) { addVariableModifier(new VariableModifier(// VariableModifier.GLYPH_SET,name,value)); } /** * **/ public Vector getHeader() { return header; } /** * **/ public String getStringBody() { return body; } /** * **/ public byte[] getBytesBody() { return body.getBytes(); } /** * **/ public char[] getCharsBody() { return body.toCharArray(); } /** * **/ public void setBody(String body) { if(body != null && body.equals("")) this.body = null; else this.body = body; } /** * **/ public void setBody(byte[] body) { if(body != null && body.length == 0) this.body = null; else this.body = new String(body); } /** * **/ public void setBody(char[] body) { if(body != null && body.length == 0) this.body = null; else this.body = new String(body); } /** * **/ public boolean isEmpty() { return (header == null || header.size() <= 0) && // (body == null || body.length() <= 0); } }