@Override public ByteBuffer getBody() { return ByteBuffer.wrap(body); } };
@Override public ByteBuffer getBody() { return ByteBuffer.wrap(body); } };
@Override public ByteBuffer getBody() { return ByteBuffer.wrap(sdpBytes); } };
@Override public ByteBuffer getBody() { return ByteBuffer.wrap(sdpBytes); } };
/** * Wraps the specified byte array into MINA heap buffer. * Please note that MINA buffers are going to be pooled, and * therefore there can be waste of memory if you wrap * your byte array specifying <tt>offset</tt> and <tt>length</tt>. */ public static ByteBuffer wrap(byte[] byteArray, int offset, int length) { return wrap(java.nio.ByteBuffer.wrap(byteArray, offset, length)); }
/** * Wraps the specified byte array into MINA heap buffer. */ public static ByteBuffer wrap(byte[] byteArray) { return wrap(java.nio.ByteBuffer.wrap(byteArray)); }
private ByteBuffer getNextByteBuffer(InputStream is) throws IOException { byte[] bytes = new byte[writeBufferSize]; int off = 0; int n = 0; while (off < bytes.length && (n = is.read(bytes, off, bytes.length - off)) != -1) { off += n; } if (n == -1 && off == 0) { return null; } return ByteBuffer.wrap(bytes, 0, off); }
public String toString() { final StringBuilder sb = new StringBuilder(); sb.append(getClass().getSimpleName()); sb.append(" with tie breaker: "); final ByteBuffer buf = ByteBuffer.wrap(this.m_tieBreaker); sb.append(ByteBufferHexDumper.getHexdump(buf)); //return getClass().getSimpleName() + " with tie breaker: " + // this.m_tieBreaker; return sb.toString(); }
public String toString() { final StringBuilder sb = new StringBuilder(); sb.append(getClass().getSimpleName()); sb.append(" with tie breaker: "); //final byte[] bytes = this.m_tieBreaker; final ByteBuffer buf = ByteBuffer.wrap(this.m_tieBreaker); sb.append(ByteBufferHexDumper.getHexdump(buf)); //return getClass().getSimpleName() + " with tie breaker: " + // this.m_tieBreaker; return sb.toString(); } }
public WriteFuture writeCrlfKeepAlive(final IoSession io) { if (LOG.isDebugEnabled()) { LOG.debug("Writing double CRLF"); } final String doubleCrlf = "\r\n\r\n"; final ByteBuffer buf; try { buf = ByteBuffer.wrap(doubleCrlf.getBytes("US-ASCII")); } catch (final UnsupportedEncodingException e) { LOG.error("Bad encoding??", e); return null; } return io.write(buf); }
public void messageReceived(final IoSession session, final Object message) { m_log.debug("Received message on TCP frame: {}", message); final TcpFrame frame = (TcpFrame) message; final byte[] data = frame.getData(); final IoSession localSession = m_remoteToLocalSessions.get(session); m_log.debug("Writing raw data to local session"); localSession.write(ByteBuffer.wrap(data)); }
/** * Converts the specified {@link String} to a {@link ByteBuffer}. The * string encoding is assumed to be ASCII. * * @param str The string to convert. * @return The new {@link ByteBuffer}. */ public static ByteBuffer toBuf(final String str) { try { final byte[] bytes = str.getBytes("US-ASCII"); return ByteBuffer.wrap(bytes); } catch (final UnsupportedEncodingException e) { LOG.error("Bad encoding?", e); return ByteBuffer.allocate(0); } }
public void run() { try { final Invite request = m_messageFactory .createInviteRequest("Anonymous", sipUri, m_sipClientUri, m_instanceId, m_contactUri, ByteBuffer.wrap(body)); m_transportLayer.invite(request, m_ioSession, listener); } catch (final Throwable t) { m_log.error("Unexpected throwable", t); } } };
public void onData(final InetSocketAddress remoteAddress, final IoSession session, final byte[] data) { m_log.debug("Received data message"); final IoSession localSession = onRemoteAddressOpened(remoteAddress, session); final ByteBuffer dataBuf = ByteBuffer.wrap(data); localSession.write(dataBuf); m_log.debug("Local bytes written: {}", localSession.getWrittenBytes()); }
@Override public void write(final byte[] b, final int off, final int len) throws IOException { write(ByteBuffer.wrap(b.clone(), off, len)); }
@Override public void write(byte[] b, int off, int len) throws IOException { write(ByteBuffer.wrap(b.clone(), off, len)); }
@Override public void messageReceived(final IoSession session, final Object message) { m_log.debug("Received message on TCP frame: {}", message); m_log.debug("TCP frames received: {}", session.getReadMessages()); m_log.debug("TCP frame bytes received: {}", session.getReadBytes()); final TcpFrame frame = (TcpFrame) message; final byte[] data = frame.getData(); if (m_log.isDebugEnabled()) { //m_log.debug("Received data:\n{}", new String(data)); } super.messageReceived(session, ByteBuffer.wrap(data)); }
@Override public void write(final byte[] b, final int off, final int len) throws IOException { // This override is key because OutputStream typically calls write(byte) // for each byte here. We need to overwrite that because otherwise // we'd wrap every single byte in a TCP frame, so this takes care of // most cases. Most code will generally use the bulk write methods, // so we should be in fairly good shape. final byte[] subArray = MinaUtils.toByteArray(ByteBuffer.wrap(b, off, len)); if (m_log.isDebugEnabled()) { //final String dataString = new String(subArray, "US-ASCII"); //m_log.debug("Sending data:\n{}", dataString); m_log.debug("Data length is: "+subArray.length); m_rawBytesWritten += subArray.length; m_log.debug("Raw bytes written: {}", m_rawBytesWritten); } write(new TcpFrame(subArray)); }
private void readInvites(final Socket sock) throws IOException, SAXException { final InputStream is = sock.getInputStream(); log.info("Reading streams from remote address: {}", sock.getRemoteSocketAddress()); log.info("Reading answerer invites on input stream: {}", is); while (true) { // This will parse the full XML/XMPP message and extract the // SDP from it. log.info("Trying to read next offer on control socket..."); final Document doc = XmlUtils.toDoc(is, "</message>"); log.info("Got XML INVITE: {}", XmlUtils.toString(doc)); final String sdp = XmppUtils.extractSdp(doc); final String from = XmppUtils.extractFrom(doc); //final String key = XmppUtils.extractKey(doc); final ByteBuffer offer = ByteBuffer.wrap(Base64.decodeBase64(sdp)); processInviteOverControlSocket(offer, sock, from); } } }
private static UUID createTransactionId() { final UUID id = UUID.randomUUID(); final byte[] idBytes = id.getRawBytes(); final ByteBuffer idBuf = ByteBuffer.wrap(idBytes); // Lower the limit to make room for the magic cookie. idBuf.limit(idBytes.length - 4); final ByteBuffer newIdBuf = ByteBuffer.allocate(16); MinaUtils.putUnsignedInt(newIdBuf, MAGIC_COOKIE); newIdBuf.put(idBuf); newIdBuf.flip(); return new UUID(MinaUtils.toByteArray(newIdBuf)); }