/**
* Get the bytes for this block.
*/
public Bufferlo toBytes(String localHost, int localPort) {
// the writer with no size info
Bufferlo writer = new Bufferlo();
// populate the map of headers
Map headers = new TreeMap();
if(resourceUri != null) headers.put(RESOURCE_URI, resourceUri.toString(localHost, localPort));
if(sessionId != -1) headers.put(SESSION_ID, new Integer(sessionId));
if(action != null) headers.put(ACTION, action);
if(updateId != -1) headers.put(UPDATE_ID, new Integer(updateId));
// write the header values
for(Iterator i = headers.entrySet().iterator(); i.hasNext(); ) {
Map.Entry mapEntry = (Map.Entry)i.next();
writer.write(mapEntry.getKey().toString());
writer.write(": ");
writer.write(mapEntry.getValue().toString());
writer.write("\r\n");
}
writer.write("\r\n");
// write the payload
if(payload != null) {
writer.append(payload.duplicate());
}
// wrap the size
Bufferlo writerWithSize = new Bufferlo();
writerWithSize.write("" + writer.length());
writerWithSize.write("\r\n");
writerWithSize.append(writer);
writerWithSize.write("\r\n");
// all done
return writerWithSize;
}