package lava.net.mmp; import java.io.OutputStream; import java.io.IOException; import java.util.Vector; import java.lang.String; import lava.net.common.Value; import lava.net.common.VariableModifier; import lava.net.common.ModifierParser; /** * **/ public class MMPOutput { /** * **/ String endOfPacket = // "" + VariableModifier.EOL + MMPInput.END_PACKET + VariableModifier.EOL; /** * **/ private OutputStream out = null; /** * **/ private StringBuffer packet = new StringBuffer(); /** * **/ public MMPOutput(OutputStream out) { this.out = out; } /** * **/ public synchronized void close() throws IOException { out.close(); } /** * **/ public void writePacket(MMPPacket packet) throws IOException { Vector header = packet.getHeader(); String body = packet.getStringBody(); if(body != null && body.indexOf(endOfPacket) >= 0) { if(header == null) header = new Vector(); header.addElement(new VariableModifier(// VariableModifier.GLYPH_SET,// MMPMessageCenter.lengthTag,// new Value(String.valueOf(body.length())))); } this.packet.setLength(0); this.packet.append(ModifierParser.writeHeader(header)); if(body != null && body.length() > 0) { this.packet.append(VariableModifier.EOL); this.packet.append(body); this.packet.append(VariableModifier.EOL); } this.packet.append(MMPInput.END_PACKET); this.packet.append(VariableModifier.EOL); out.write(this.packet.toString().getBytes()); out.flush(); } /** * We later introduced the . initialization of streams -lynX 2005 **/ public void writeInit() throws IOException { String dot = new String(); dot += MMPInput.END_PACKET; dot += VariableModifier.EOL; out.write(dot.getBytes()); out.flush(); } }