本文整理了Java中org.littleshoot.mina.common.ByteBuffer.wrap()
方法的一些代码示例,展示了ByteBuffer.wrap()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuffer.wrap()
方法的具体详情如下:
包路径:org.littleshoot.mina.common.ByteBuffer
类名称:ByteBuffer
方法名:wrap
[英]Wraps the specified NIO java.nio.ByteBuffer into MINA buffer.
[中]包装指定的NIO java。尼奥。把它放进MINA缓冲区。
代码示例来源:origin: org.littleshoot/xmpp
@Override
public ByteBuffer getBody() {
return ByteBuffer.wrap(body);
}
};
代码示例来源:origin: org.littleshoot/xmpp
@Override
public ByteBuffer getBody() {
return ByteBuffer.wrap(body);
}
};
代码示例来源:origin: org.littleshoot/xmpp
@Override
public ByteBuffer getBody() {
return ByteBuffer.wrap(sdpBytes);
}
};
代码示例来源:origin: org.littleshoot/xmpp
@Override
public ByteBuffer getBody() {
return ByteBuffer.wrap(sdpBytes);
}
};
代码示例来源:origin: org.littleshoot/mina-port
/**
* 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));
}
代码示例来源:origin: org.littleshoot/mina-port
/**
* Wraps the specified byte array into MINA heap buffer.
*/
public static ByteBuffer wrap(byte[] byteArray) {
return wrap(java.nio.ByteBuffer.wrap(byteArray));
}
代码示例来源:origin: org.littleshoot/mina-port
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);
}
代码示例来源:origin: org.littleshoot/stun-stack
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();
}
代码示例来源:origin: org.littleshoot/stun-stack
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();
}
}
代码示例来源:origin: org.littleshoot/sip-stack
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);
}
代码示例来源:origin: org.littleshoot/tcp-framing
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));
}
代码示例来源:origin: org.littleshoot/mina-util
/**
* 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);
}
}
代码示例来源:origin: org.littleshoot/sip-client
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);
}
}
};
代码示例来源:origin: org.littleshoot/turn-http-server
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());
}
代码示例来源:origin: org.littleshoot/mina-util
@Override
public void write(final byte[] b, final int off,
final int len) throws IOException
{
write(ByteBuffer.wrap(b.clone(), off, len));
}
代码示例来源:origin: org.littleshoot/mina-port
@Override
public void write(byte[] b, int off, int len) throws IOException {
write(ByteBuffer.wrap(b.clone(), off, len));
}
代码示例来源:origin: org.littleshoot/tcp-framing
@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));
}
代码示例来源:origin: org.littleshoot/tcp-framing
@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));
}
代码示例来源:origin: org.littleshoot/xmpp
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);
}
}
}
代码示例来源:origin: org.littleshoot/stun-stack
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));
}
内容来源于网络,如有侵权,请联系作者删除!