@Override public void append(Framedata nextframe) throws InvalidFrameException { ByteBuffer b = nextframe.getPayloadData(); if (unmaskedpayload == null) { unmaskedpayload = ByteBuffer.allocate(b.remaining()); b.mark(); unmaskedpayload.put(b); b.reset(); } else { b.mark(); unmaskedpayload.position(unmaskedpayload.limit()); unmaskedpayload.limit(unmaskedpayload.capacity()); if (b.remaining() > unmaskedpayload.remaining()) { ByteBuffer tmp = ByteBuffer.allocate(b.remaining() + unmaskedpayload.capacity()); unmaskedpayload.flip(); tmp.put(unmaskedpayload); tmp.put(b); unmaskedpayload = tmp; } else { unmaskedpayload.put(b); } unmaskedpayload.rewind(); b.reset(); } fin = nextframe.isFin(); }
@Override public void append(Framedata nextframe) throws InvalidFrameException { if (unmaskedpayload == null) { unmaskedpayload = ByteBuffer.wrap(nextframe.getPayloadData()); } else { // TODO might be inefficient. Cosider a global buffer pool ByteBuffer tmp = ByteBuffer.allocate(nextframe.getPayloadData().length + unmaskedpayload.capacity()); tmp.put(unmaskedpayload.array()); tmp.put(nextframe.getPayloadData()); unmaskedpayload = tmp; } fin = nextframe.isFin(); }
/** * Helper constructor which helps to create "echo" frames. The new object will use the same * underlying payload data. */ public FramedataImpl1(Framedata f) { fin = f.isFin(); optcode = f.getOpcode(); unmaskedpayload = f.getPayloadData(); transferemasked = f.getTransfereMasked(); }