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); }
/** * Generates response for non-versioned connections, such as those before FP9. * * @param input * incoming RTMP bytes * @return outgoing handshake */ private IoBuffer generateUnversionedHandshake(byte[] input) { log.debug("Using old style (un-versioned) handshake"); IoBuffer output = IoBuffer.allocate((Constants.HANDSHAKE_SIZE * 2) + 1); // 3073 // non-encrypted output.put(RTMPConnection.RTMP_NON_ENCRYPTED); // set server uptime in seconds output.putInt((int) Red5.getUpTime() / 1000); //0x01 output.position(Constants.HANDSHAKE_SIZE + 1); output.put(input); output.flip(); // fill S1 with handshake data (nearly all 0's) output.mark(); output.position(1); output.get(s1); output.reset(); return output; }
int msgPos = savedBuf.position(); // carry on from previous buffer boolean seenNewline = false; while (!seenNewline && buf.hasRemaining() && msgPos < maxLineLength) { int end = buf.position(); buf.reset(); int start = buf.position(); if (savedBuf.position() > 0) { int len = savedBuf.position() - 1; savedBuf.flip(); int end = buf.position(); buf.reset(); int start = buf.position(); if (savedBuf.position() > 0) { int end = buf.position(); buf.reset(); int start = buf.position(); byte[] tmp = new byte[end - start]; buf.get(tmp);
/** {@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); }
/** * {@inheritDoc} */ @Override public int position() { return buf.position(); }
/** * {@inheritDoc} */ @Override public IoBuffer position(int newPosition) { buf.position(newPosition); return this; }
/** * {@inheritDoc} */ @Override public void put(int index, IoBuffer other) { bb.position(index); bb.put(other); }
private String getMessageStringForError(IoBuffer buffer) throws UnsupportedEncodingException { int initialPosition = buffer.position(); byte[] data = new byte[buffer.limit() - initialPosition]; buffer.get(data); buffer.position(position - initialPosition); return new String(data, charsetEncoding); }
/** * {@inheritDoc} */ @Override public void get(int index, IoBuffer other) { bb.position(index); other.put(bb); }
private String getMessageString(IoBuffer buffer) throws UnsupportedEncodingException { byte[] data = new byte[position - buffer.position()]; buffer.get(data); return new String(data, charsetEncoding); }
private void handleError(IoBuffer buffer, int recoveryPosition, String text, boolean disconnect) throws ProtocolCodecException { buffer.position(recoveryPosition); position = recoveryPosition; state = SEEKING_HEADER; bodyLength = 0; if (disconnect) { throw new CriticalProtocolCodecException(text); } else { log.error(text); } }
private String getMessageStringForError(IoBuffer buffer) throws UnsupportedEncodingException { int initialPosition = buffer.position(); byte[] data = new byte[buffer.limit() - initialPosition]; buffer.get(data); buffer.position(position - initialPosition); return new String(data, charsetEncoding); }
static void getLabel( IoBuffer byteBuffer, StringBuffer domainName, int labelLength ) { for ( int jj = 0; jj < labelLength; jj++ ) { char character = ( char ) byteBuffer.get(); domainName.append( character ); } if ( byteBuffer.get( byteBuffer.position() ) != 0 ) { domainName.append( "." ); } }
@Override public MessageDecoderResult decodable(IoSession session, IoBuffer in) { boolean hasHeader = HEADER_PATTERN.find(in, in.position()) != -1L; return hasHeader ? MessageDecoderResult.OK : (in.remaining() > MAX_UNDECODED_DATA_LENGTH ? MessageDecoderResult.NOT_OK : MessageDecoderResult.NEED_DATA); }
private void discard(IoBuffer in) { if (Integer.MAX_VALUE - in.remaining() < overflowPosition) { overflowPosition = Integer.MAX_VALUE; } else { overflowPosition += in.remaining(); } in.position(in.limit()); } }
@Override protected int write(NioSession session, IoBuffer buf, int length) throws IOException { if (buf.remaining() <= length) { return session.getChannel().write(buf.buf()); } int oldLimit = buf.limit(); buf.limit(buf.position() + length); try { return session.getChannel().write(buf.buf()); } finally { buf.limit(oldLimit); } }