/** Appends a buffer to a buffer * @param to Buffer is flush mode * @param b buffer to append * @return The position of the valid data before the flipped position. */ public static int append(ByteBuffer to, ByteBuffer b) { int pos = flipToFill(to); try { return put(b, to); } finally { flipToFlush(to, pos); } }
public void writeBuffer(ByteBuffer payload, ByteBuffer buffer) { BufferUtil.put(buffer,payload); }
public void writeBuffer(ByteBuffer payload, ByteBuffer buffer) { BufferUtil.put(buffer,payload); }
public void writeBuffer(ByteBuffer payload, ByteBuffer buffer) { BufferUtil.put(buffer,payload); }
private ByteBuffer readBlock(ByteBuffer buffer, long size) { if (size == 0) { return null; } if (size > buffer.remaining()) { String err = String.format("Truncated data, expected %,d byte(s), but only %,d byte(s) remain",size,buffer.remaining()); throw new MuxException(err); } if (size > Integer.MAX_VALUE) { String err = String.format("[Int-Sane!] Buffer size %,d is too large to be supported (max allowed is %,d)",size,Integer.MAX_VALUE); throw new MuxException(err); } ByteBuffer ret = ByteBuffer.allocateDirect((int)size); BufferUtil.put(buffer,ret); BufferUtil.flipToFlush(ret,0); return ret; }
private ByteBuffer readBlock(ByteBuffer buffer, long size) { if (size == 0) { return null; } if (size > buffer.remaining()) { String err = String.format("Truncated data, expected %,d byte(s), but only %,d byte(s) remain",size,buffer.remaining()); throw new MuxException(err); } if (size > Integer.MAX_VALUE) { String err = String.format("[Int-Sane!] Buffer size %,d is too large to be supported (max allowed is %,d)",size,Integer.MAX_VALUE); throw new MuxException(err); } ByteBuffer ret = ByteBuffer.allocateDirect((int)size); BufferUtil.put(buffer,ret); BufferUtil.flipToFlush(ret,0); return ret; }
private ByteBuffer readBlock(ByteBuffer buffer, long size) { if (size == 0) { return null; } if (size > buffer.remaining()) { String err = String.format("Truncated data, expected %,d byte(s), but only %,d byte(s) remain",size,buffer.remaining()); throw new MuxException(err); } if (size > Integer.MAX_VALUE) { String err = String.format("[Int-Sane!] Buffer size %,d is too large to be supported (max allowed is %,d)",size,Integer.MAX_VALUE); throw new MuxException(err); } ByteBuffer ret = ByteBuffer.allocate((int)size); BufferUtil.put(buffer,ret); BufferUtil.flipToFlush(ret,0); return ret; }
/** Appends a buffer to a buffer * @param to Buffer is flush mode * @param b buffer to append */ public static int append(ByteBuffer to, ByteBuffer b) { int pos = flipToFill(to); try { return put(b, to); } finally { flipToFlush(to, pos); } }
/** Appends a buffer to a buffer * @param to Buffer is flush mode * @param b buffer to append * @return The position of the valid data before the flipped position. */ public static int append(ByteBuffer to, ByteBuffer b) { int pos = flipToFill(to); try { return put(b, to); } finally { flipToFlush(to, pos); } }
/** * Put data from one buffer into another, avoiding over/under flows * @param from Buffer to take bytes from in flush mode * @param to Buffer to put bytes to in flush mode. The buffer is flipToFill before the put and flipToFlush after. * @return number of bytes moved */ public static int flipPutFlip(ByteBuffer from, ByteBuffer to) { int pos= flipToFill(to); try { return put(from,to); } finally { flipToFlush(to,pos); } }
/** * Put data from one buffer into another, avoiding over/under flows * @param from Buffer to take bytes from in flush mode * @param to Buffer to put bytes to in flush mode. The buffer is flipToFill before the put and flipToFlush after. * @return number of bytes moved */ public static int flipPutFlip(ByteBuffer from, ByteBuffer to) { int pos= flipToFill(to); try { return put(from,to); } finally { flipToFlush(to,pos); } }
@Override public void appendMessage(ByteBuffer payload) throws IOException { if (finished) { throw new IOException("Cannot append to finished buffer"); } if (payload == null) { // empty payload is valid return; } driver.getPolicy().assertValidBinaryMessageSize(size + payload.remaining()); size += payload.remaining(); synchronized (buf) { // TODO: grow buffer till max binary message size? // TODO: compact this buffer to fit incoming buffer? // TODO: tell connection to suspend if buffer too full? BufferUtil.put(payload,buf); } if (needsNotification) { needsNotification = true; this.driver.onInputStream(this); } }
@Override public void appendMessage(ByteBuffer payload) throws IOException { if (finished) { throw new IOException("Cannot append to finished buffer"); } if (payload == null) { // empty payload is valid return; } driver.getPolicy().assertValidMessageSize(size + payload.remaining()); size += payload.remaining(); synchronized (buf) { // TODO: grow buffer till max binary message size? // TODO: compact this buffer to fit incoming buffer? // TODO: tell connection to suspend if buffer too full? BufferUtil.put(payload,buf); } if (needsNotification) { needsNotification = true; this.driver.onInputStream(this); } }
@Override public void appendMessage(ByteBuffer payload) throws IOException { if (finished) { throw new IOException("Cannot append to finished buffer"); } if (payload == null) { // empty payload is valid return; } driver.getPolicy().assertValidMessageSize(size + payload.remaining()); size += payload.remaining(); synchronized (buf) { // TODO: grow buffer till max binary message size? // TODO: compact this buffer to fit incoming buffer? // TODO: tell connection to suspend if buffer too full? BufferUtil.put(payload,buf); } if (needsNotification) { needsNotification = true; this.driver.onInputStream(this); } }
public ClientUpgradeResponse parse(ByteBuffer buf) throws ParseException { while (!isDone() && (buf.remaining() > 0)) { String line = lineParser.parse(buf); if (line != null) { if (parseHeader(line)) { // Finished parsing entire header ByteBuffer copy = ByteBuffer.allocateDirect(buf.remaining()); BufferUtil.put(buf,copy); BufferUtil.flipToFlush(copy,0); this.response.setRemainingBuffer(copy); return this.response; } } } return null; }
public ClientUpgradeResponse parse(ByteBuffer buf) throws ParseException { while (!isDone() && (buf.remaining() > 0)) { String line = lineParser.parse(buf); if (line != null) { if (parseHeader(line)) { // Finished parsing entire header ByteBuffer copy = ByteBuffer.allocateDirect(buf.remaining()); BufferUtil.put(buf,copy); BufferUtil.flipToFlush(copy,0); this.response.setRemainingBuffer(copy); return this.response; } } } return null; }
public HttpResponseHeaderParseListener parse(ByteBuffer buf) throws ParseException { while (!isDone() && (buf.remaining() > 0)) { String line = lineParser.parse(buf); if (line != null) { if (parseHeader(line)) { // Now finished with parsing the entire response header // Save the remaining bytes for WebSocket to process. ByteBuffer copy = ByteBuffer.allocate(buf.remaining()); BufferUtil.put(buf,copy); BufferUtil.flipToFlush(copy,0); this.listener.setRemainingBuffer(copy); return listener; } } } return null; }
public <C> void output(C context, Callback<C> callback, long channelId, WebSocketFrame frame) throws IOException { ByteBuffer muxPayload = bufferPool.acquire(frame.getPayloadLength() + DATA_FRAME_OVERHEAD,false); BufferUtil.flipToFill(muxPayload); // start building mux payload writeChannelId(muxPayload,channelId); byte b = (byte)(frame.isFin()?0x80:0x00); // fin b |= (byte)(frame.isRsv1()?0x40:0x00); // rsv1 b |= (byte)(frame.isRsv2()?0x20:0x00); // rsv2 b |= (byte)(frame.isRsv3()?0x10:0x00); // rsv3 b |= (byte)(frame.getOpCode() & 0x0F); // opcode muxPayload.put(b); BufferUtil.put(frame.getPayload(),muxPayload); // build muxed frame WebSocketFrame muxFrame = WebSocketFrame.binary(); BufferUtil.flipToFlush(muxPayload,0); muxFrame.setPayload(muxPayload); // NOTE: the physical connection will handle masking rules for this frame. // release original buffer (no longer needed) bufferPool.release(frame.getPayload()); // send muxed frame down to the physical connection. outgoing.output(context,callback,muxFrame); }
public void generate(long channelId, Frame frame, WriteCallback callback) { ByteBuffer muxPayload = bufferPool.acquire(frame.getPayloadLength() + DATA_FRAME_OVERHEAD,true); BufferUtil.flipToFill(muxPayload); // start building mux payload writeChannelId(muxPayload,channelId); byte b = (byte)(frame.isFin()?0x80:0x00); // fin b |= (byte)(frame.isRsv1()?0x40:0x00); // rsv1 b |= (byte)(frame.isRsv2()?0x20:0x00); // rsv2 b |= (byte)(frame.isRsv3()?0x10:0x00); // rsv3 b |= (byte)(frame.getType().getOpCode() & 0x0F); // opcode muxPayload.put(b); BufferUtil.put(frame.getPayload(),muxPayload); // build muxed frame WebSocketFrame muxFrame = WebSocketFrame.binary(); BufferUtil.flipToFlush(muxPayload,0); muxFrame.setPayload(muxPayload); // NOTE: the physical connection will handle masking rules for this frame. // release original buffer (no longer needed) bufferPool.release(frame.getPayload()); // send muxed frame down to the physical connection. outgoing.outgoingFrame(muxFrame,callback); }
public void generate(long channelId, Frame frame, WriteCallback callback) { ByteBuffer muxPayload = bufferPool.acquire(frame.getPayloadLength() + DATA_FRAME_OVERHEAD,true); BufferUtil.flipToFill(muxPayload); // start building mux payload writeChannelId(muxPayload,channelId); byte b = (byte)(frame.isFin()?0x80:0x00); // fin b |= (byte)(frame.isRsv1()?0x40:0x00); // rsv1 b |= (byte)(frame.isRsv2()?0x20:0x00); // rsv2 b |= (byte)(frame.isRsv3()?0x10:0x00); // rsv3 b |= (byte)(frame.getType().getOpCode() & 0x0F); // opcode muxPayload.put(b); BufferUtil.put(frame.getPayload(),muxPayload); // build muxed frame WebSocketFrame muxFrame = WebSocketFrame.binary(); BufferUtil.flipToFlush(muxPayload,0); muxFrame.setPayload(muxPayload); // NOTE: the physical connection will handle masking rules for this frame. // release original buffer (no longer needed) bufferPool.release(frame.getPayload()); // send muxed frame down to the physical connection. outgoing.outgoingFrame(muxFrame,callback); }