/** Replaces a reference from one object to another. */ public boolean replaceRef(Object oldRef, Object newRef) throws IOException { Integer value = (Integer) _refs.remove(oldRef); if (value != null) { _refs.put(newRef, value); return true; } else return false; }
/** * If the object has already been written, just write its ref. * * @return true if we're writing a ref. */ public boolean addRef(Object object) throws IOException { int ref = _refs.get(object); if (ref >= 0) { writeRef(ref); return true; } else { _refs.put(object, _refs.size()); return false; } }
/** Removes a reference. */ public boolean removeRef(Object obj) throws IOException { if (_refs != null) { _refs.remove(obj); return true; } else return false; }
/** * Starts a streaming packet * * <p>A streaming message starts with 'P' * * <pre> * P x02 x00 * </pre> */ public void startStreamingPacket() throws IOException { if (_refs != null) _refs.clear(); flush(); _isStreaming = true; _offset = 3; }
/** * Writes a fault. The fault will be written as a descriptive string followed by an object: <code> * <pre> * F map * </pre></code> <code><pre> * F H * \x04code * \x10the fault code * * \x07message * \x11the fault message * * \x06detail * M\xnnjavax.ejb.FinderException * ... * Z * Z * </pre></code> * * @param code the fault code, a three digit */ public void writeFault(String code, String message, Object detail) throws IOException { flushIfFull(); writeVersion(); _buffer[_offset++] = (byte) 'F'; _buffer[_offset++] = (byte) 'H'; _refs.put(new HashMap(), _refs.size()); writeString("code"); writeString(code); writeString("message"); writeString(message); if (detail != null) { writeString("detail"); writeObject(detail); } flushIfFull(); _buffer[_offset++] = (byte) 'Z'; }
/** Resets the references for streaming. */ public void resetReferences() { if (_refs != null) _refs.clear(); }