private PendingData(IoBuffer buffer, Packet packet) { int size = buffer.limit(); this.byteBuffer = new byte[size]; buffer.get(byteBuffer); this.packet = packet; if (log.isTraceEnabled()) { log.trace("Buffer: {}", Arrays.toString(ArrayUtils.subarray(byteBuffer, 0, 32))); } }
private PendingData(IoBuffer buffer) { int size = buffer.limit(); this.byteBuffer = new byte[size]; buffer.get(byteBuffer); this.packet = null; if (log.isTraceEnabled()) { log.trace("Buffer: {}", Arrays.toString(ArrayUtils.subarray(byteBuffer, 0, 32))); } }
/** * Take a message from this buffer. The message count decreases. * * @return <tt>null</tt> if buffer is empty. */ public RTMPMessage takeMessage() { RTMPMessage message = messageQueue.poll(); if (message != null) { IRTMPEvent body = message.getBody(); if (!(body instanceof IStreamData)) { throw new RuntimeException("Expected IStreamData but got " + body); } messageSize -= ((IStreamData<?>) body).getData().limit(); } return message; }
/** * Put a message into this buffer. * * @param message * RTMP message * @return <tt>true</tt> indicates success and <tt>false</tt> indicates buffer is full. */ public boolean putMessage(RTMPMessage message) { IRTMPEvent body = message.getBody(); if (!(body instanceof IStreamData)) { throw new RuntimeException("Expected IStreamData but got " + body); } int size = ((IStreamData<?>) body).getData().limit(); if (messageSize + size > capacity) { return false; } messageSize += size; messageQueue.offer(message); return true; }
resp.setHeader("Cache-Control", "no-cache"); resp.setContentType(CONTENT_TYPE); int contentLength = buffer.limit() + 1; resp.setContentLength(contentLength); ServletOutputStream output = resp.getOutputStream(); if (conn != null) { byte pollingDelay = conn.getPollingDelay(); log.debug("Sending {} bytes; polling delay: {}", buffer.limit(), pollingDelay); output.write(pollingDelay); } else {
/** * Decode data sent by the client. * * @param data * the data to decode * @return a list of decoded objects */ public List<?> decode(IoBuffer data) { log.debug("decode"); if (closing || state.getState() == RTMP.STATE_DISCONNECTED) { // connection is being closed, don't decode any new packets return Collections.EMPTY_LIST; } if (log.isTraceEnabled()) { log.trace("Current bytes read at decode: {}", data.limit()); } buffer.put(data); buffer.flip(); return decoder.decodeBuffer(this, buffer); }
/** * Sends response to client * * @param resp * Response * @param packet * Remoting packet * @throws Exception * General exception */ protected void sendResponse(HttpServletResponse resp, RemotingPacket packet) throws Exception { log.debug("Sending response"); IoBuffer respBuffer = codecFactory.getRemotingEncoder().encode(packet); if (respBuffer != null) { final ServletOutputStream out = resp.getOutputStream(); resp.setContentLength(respBuffer.limit()); ServletUtils.copy(respBuffer.asInputStream(), out); out.flush(); out.close(); respBuffer.free(); respBuffer = null; } else { log.info("Response buffer was null after encoding"); } }
/** {@inheritDoc} */ @Override public void messageReceived(NextFilter next, IoSession session, Object message) throws Exception { // Create forwarding IO session IoSession forward = (IoSession) session.getAttribute(FORWARD_KEY); if (forward != null && forward.isConnected()) { if (message instanceof IoBuffer) { final IoBuffer buf = (IoBuffer) message; if (log.isDebugEnabled()) { log.debug("[{}] RAW >> {}", name, buf.getHexDump()); } IoBuffer copy = IoBuffer.allocate(buf.limit()); int limit = buf.limit(); copy.put(buf); copy.flip(); forward.write(copy); buf.flip(); buf.position(0); buf.limit(limit); } } next.messageReceived(session, message); }
log.debug("Send size: {}", result.limit());
byteBuffer.position(byteBuffer.limit()); return;
/** {@inheritDoc} */ @Override public void messageReceived(NextFilter next, IoSession session, Object message) throws Exception { if (message instanceof IoBuffer) { IoBuffer out = (IoBuffer) message; if (headers != null) { IoBuffer header = IoBuffer.allocate(12); header.putLong(System.currentTimeMillis()); header.putInt(out.limit() - out.position()); header.flip(); headers.write(header.buf()); } if (raw != null) { raw.write(out.asReadOnlyBuffer().buf()); } } next.messageReceived(session, message); }
log.trace("S0+S1+S2 size: {}", s0s1s2.limit());
/** * {@inheritDoc} */ @Override public int last() { return bb.limit(); }
/** * {@inheritDoc} */ @Override public IoBuffer limit(int newLimit) { buf.limit(newLimit); return this; }
/** * {@inheritDoc} */ @Override public int limit() { return buf.limit(); }
public IoSessionInputStream() { buf = IoBuffer.allocate(16); buf.setAutoExpand(true); buf.limit(0); }
public synchronized void setBuffer(IoBuffer b) { buf = IoBuffer.allocate(b.limit()); buf.put(b); buf.flip(); notifyAll(); } }
public IoSessionInputStream(IoBuffer b) { buf = IoBuffer.allocate(b.limit()); buf.put(b); buf.flip(); } public IoSessionInputStream() {
private void discard(IoBuffer in) { if (Integer.MAX_VALUE - in.remaining() < overflowPosition) { overflowPosition = Integer.MAX_VALUE; } else { overflowPosition += in.remaining(); } in.position(in.limit()); } }