本文整理了Java中org.littleshoot.mina.common.ByteBuffer.limit()
方法的一些代码示例,展示了ByteBuffer.limit()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuffer.limit()
方法的具体详情如下:
包路径:org.littleshoot.mina.common.ByteBuffer
类名称:ByteBuffer
方法名:limit
暂无
代码示例来源:origin: org.littleshoot/mina-port
public ByteBuffer limit(int newLimit) {
buf.limit(newLimit);
return this;
}
代码示例来源:origin: org.littleshoot/mina-port
public int limit() {
return buf.limit();
}
代码示例来源:origin: org.littleshoot/mina-port
/**
* @see java.nio.Buffer#remaining()
*/
public int remaining() {
return limit() - position();
}
代码示例来源:origin: org.littleshoot/mina-util
final int limit = buffer.limit();
buffer.limit(totalSent + chunkSize);
buffers.add(createBuffer(buffer));
totalSent += chunkSize;
buffer.limit(limit);
buffers.add(createBuffer(buffer));
return buffers;
代码示例来源:origin: org.littleshoot/mina-util
final int originalLimit = buffer.limit();
buffer.limit(totalSent + chunkSize);
buffers.add(createBuffer(buffer));
totalSent += chunkSize;
buffer.limit(originalLimit);
buffers.add(createBuffer(buffer));
return buffers;
代码示例来源:origin: org.littleshoot/mina-util
public IoSessionInputStream(final IoSession ioSession,
final int readTimeout)
{
m_ioSession = ioSession;
m_readTimeout = readTimeout;
m_buf = ByteBuffer.allocate(16);
m_buf.setAutoExpand(true);
m_buf.limit(0);
}
代码示例来源:origin: org.littleshoot/mina-port
@Override
public String toString() {
StringBuffer buf = new StringBuffer();
if (isDirect()) {
buf.append("DirectBuffer");
} else {
buf.append("HeapBuffer");
}
buf.append("[pos=");
buf.append(position());
buf.append(" lim=");
buf.append(limit());
buf.append(" cap=");
buf.append(capacity());
buf.append(": ");
buf.append(getHexDump());
buf.append(']');
return buf.toString();
}
代码示例来源:origin: org.littleshoot/mina-port
public IoSessionInputStream() {
buf = ByteBuffer.allocate(16);
buf.setAutoExpand(true);
buf.limit(0);
}
代码示例来源:origin: org.littleshoot/mina-port
@Override
public int hashCode() {
int h = 1;
int p = position();
for (int i = limit() - 1; i >= p; i--) {
h = 31 * h + get(i);
}
return h;
}
代码示例来源:origin: org.littleshoot/mina-util
/**
* Useful for debugging. Turns the given buffer into an ASCII string.
* This does not affect the position or the limit of the buffer (it resets
* them to their original values when done).
*
* @param buf The buffer to convert to a string.
* @return The string.
*/
public static String toAsciiString(final ByteBuffer buf)
{
DECODER.reset();
final int position = buf.position();
final int limit = buf.limit();
try
{
return buf.getString(DECODER);
}
catch (final CharacterCodingException e)
{
LOG.error("Could not decode: "+buf, e);
return StringUtils.EMPTY;
}
finally
{
buf.position(position);
buf.limit(limit);
}
}
代码示例来源:origin: org.littleshoot/mina-util
/**
* Returns the buffer as a string while preserving the buffer position
* and limit.
*
* @param buffer The buffer to create a string from.
* @return The buffer string.
*/
public static String toString(final ByteBuffer buffer)
{
final int position = buffer.position();
final int limit = buffer.limit();
final byte[] data = new byte[buffer.remaining()];
buffer.get(data);
final String dataString = new String(data);
buffer.position(position);
buffer.limit(limit);
return dataString;
}
}
代码示例来源:origin: org.littleshoot/mina-port
private void discard(ByteBuffer in) {
if (Integer.MAX_VALUE - in.remaining() < overflowPosition) {
overflowPosition = Integer.MAX_VALUE;
} else {
overflowPosition += in.remaining();
}
in.position(in.limit());
}
}
代码示例来源:origin: org.littleshoot/mina-port
@Override
public boolean equals(Object o) {
if (!(o instanceof ByteBuffer)) {
return false;
}
ByteBuffer that = (ByteBuffer) o;
if (this.remaining() != that.remaining()) {
return false;
}
int p = this.position();
for (int i = this.limit() - 1, j = that.limit() - 1; i >= p; i--, j--) {
byte v1 = this.get(i);
byte v2 = that.get(j);
if (v1 != v2) {
return false;
}
}
return true;
}
代码示例来源:origin: org.littleshoot/mina-port
public Object readObject() throws ClassNotFoundException, IOException {
int objectSize = in.readInt();
if (objectSize <= 0) {
throw new StreamCorruptedException("Invalid objectSize: "
+ objectSize);
}
if (objectSize > maxObjectSize) {
throw new StreamCorruptedException("ObjectSize too big: "
+ objectSize + " (expected: <= " + maxObjectSize + ')');
}
ByteBuffer buf = ByteBuffer.allocate(objectSize + 4, false);
buf.putInt(objectSize);
in.readFully(buf.array(), 4, objectSize);
buf.position(0);
buf.limit(objectSize + 4);
Object answer = buf.getObject(classLoader);
buf.release();
return answer;
}
代码示例来源:origin: org.littleshoot/mina-util
private static ByteBuffer createBuffer(final ByteBuffer buffer)
{
final ByteBuffer data = ByteBuffer.allocate(
buffer.limit() - buffer.position());
LOG.trace("Created buffer with capacity: "+data.capacity());
data.put(buffer);
data.rewind();
return data;
}
代码示例来源:origin: org.littleshoot/mina-util
private static ByteBuffer createBuffer(final ByteBuffer buffer)
{
// We calculate this here because the final split buffer will not
// necessarily have a size equal to the chunk size -- it will
// usually be smaller.
final ByteBuffer data = ByteBuffer.allocate(
buffer.limit() - buffer.position());
data.put(buffer);
data.flip();
return data;
}
代码示例来源:origin: org.littleshoot/mina-util
public DecodingState decode(ByteBuffer in, ProtocolDecoderOutput out)
throws Exception
{
final int beginPos = in.position();
final int limit = in.limit();
for (int i = beginPos; i < limit; i++)
{
final byte b = in.get(i);
if (b != m_byteToSkip)
{
in.position(i);
return finishDecode();
}
else
{
}
}
in.position(limit);
return this;
}
代码示例来源: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));
}
代码示例来源:origin: org.littleshoot/mina-port
private void readSession(DatagramSessionImpl session) {
ByteBuffer readBuf = ByteBuffer.allocate(session.getReadBufferSize());
try {
int readBytes = session.getChannel().read(readBuf.buf());
if (readBytes > 0) {
readBuf.flip();
ByteBuffer newBuf = ByteBuffer.allocate(readBuf.limit());
newBuf.put(readBuf);
newBuf.flip();
session.increaseReadBytes(readBytes);
session.getFilterChain().fireMessageReceived(session, newBuf);
}
} catch (IOException e) {
session.getFilterChain().fireExceptionCaught(session, e);
} finally {
readBuf.release();
}
}
代码示例来源:origin: org.littleshoot/mina-port
private void readSession(DatagramChannel channel, RegistrationRequest req)
throws Exception {
ByteBuffer readBuf = ByteBuffer
.allocate(((DatagramSessionConfig) req.config
.getSessionConfig()).getReceiveBufferSize());
try {
SocketAddress remoteAddress = channel.receive(readBuf.buf());
if (remoteAddress != null) {
DatagramSessionImpl session = (DatagramSessionImpl) newSession(
remoteAddress, req.address);
readBuf.flip();
ByteBuffer newBuf = ByteBuffer.allocate(readBuf.limit());
newBuf.put(readBuf);
newBuf.flip();
session.increaseReadBytes(newBuf.remaining());
session.getFilterChain().fireMessageReceived(session, newBuf);
}
} finally {
readBuf.release();
}
}
内容来源于网络,如有侵权,请联系作者删除!