bos.reset(); out=new DataOutputStream(bos); msg.writeTo(out); out.flush(); buffer=bos.getRawBuffer(); fragments=Util.fragmentBuffer(buffer, frag_size, bos.size());
synchronized(bos) { bos.reset(); out=new DataOutputStream(bos); msg.writeTo(out); out.flush(); buffer=bos.getRawBuffer(); fragments=Util.fragmentBuffer(buffer, frag_size, bos.size()); }
    private void fragment(Message msg) {        DataOutputStream   out=null;        byte[]             buffer;        byte[]             fragments[];        Event              evt;        FragHeader         hdr;        Message            frag_msg;        Address            dest=msg.getDest(), src=msg.getSrc();        long               id=curr_id++; // used as seqnos        int                num_frags;        try {            // Write message into a byte buffer and fragment it            bos.reset();            out=new DataOutputStream(bos);            msg.writeTo(out);            out.flush();            buffer=bos.getRawBuffer();            fragments=Util.fragmentBuffer(buffer, frag_size, bos.size());            num_frags=fragments.length;            num_sent_frags+=num_frags;            if(trace) {                StringBuffer sb=new StringBuffer();                sb.append("fragmenting packet to ").append(dest != null ? dest.toString() : "<all members>");                sb.append(" (size=").append(buffer.length).append(") into ").append(num_frags);                sb.append(" fragment(s) [frag_size=").append(frag_size).append(']');                log.trace(sb.toString());            }            for(int i=0; i < num_frags; i++) {                frag_msg=new Message(dest, src, fragments[i]);                hdr=new FragHeader(id, i, num_frags);                frag_msg.putHeader(name, hdr);                evt=new Event(Event.MSG, frag_msg);                passDown(evt);            }        }        catch(Exception e) {            log.error("exception occurred trying to fragment message", e);        }        finally {            Util.closeOutputStream(out);        }    }