本文整理了Java中org.littleshoot.mina.common.ByteBuffer.remaining()
方法的一些代码示例,展示了ByteBuffer.remaining()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuffer.remaining()
方法的具体详情如下:
包路径:org.littleshoot.mina.common.ByteBuffer
类名称:ByteBuffer
方法名:remaining
暂无
代码示例来源:origin: org.littleshoot/mina-port
public int available() {
if (released) {
return 0;
} else {
synchronized (mutex) {
return buf.remaining();
}
}
}
代码示例来源:origin: org.littleshoot/mina-util
public static int remaining(final Collection<ByteBuffer> buffers)
{
int remaining = 0;
for (final ByteBuffer buf : buffers)
{
remaining += buf.remaining();
}
return remaining;
}
代码示例来源:origin: org.littleshoot/mina-port
@Override
public int available() {
return ByteBuffer.this.remaining();
}
代码示例来源:origin: org.littleshoot/mina-port
/**
* @see java.nio.Buffer#hasRemaining()
*/
public boolean hasRemaining() {
return remaining() > 0;
}
代码示例来源:origin: org.littleshoot/mina-util
public int available()
{
if (m_released)
{
return 0;
}
else
{
synchronized (m_mutex)
{
return m_buf.remaining();
}
}
}
代码示例来源:origin: org.littleshoot/mina-port
public int remaining() {
return buf.remaining();
}
代码示例来源:origin: org.littleshoot/mina-port
@Override
public long skip(long n) {
int bytes;
if (n > Integer.MAX_VALUE) {
bytes = ByteBuffer.this.remaining();
} else {
bytes = Math.min(ByteBuffer.this.remaining(), (int) n);
}
ByteBuffer.this.skip(bytes);
return bytes;
}
};
代码示例来源:origin: org.littleshoot/mina-port
public void messageReceived(NextFilter nextFilter, IoSession session,
Object message) throws Exception {
if (message instanceof ByteBuffer) {
release(session, ((ByteBuffer) message).remaining());
}
nextFilter.messageReceived(session, message);
}
}
代码示例来源:origin: org.littleshoot/mina-util
/**
* Copies the specified buffer to a byte array.
*
* @param buf The buffer to copy.
* @return The byte array.
*/
public static byte[] toByteArray(final ByteBuffer buf)
{
final byte[] bytes = new byte[buf.remaining()];
buf.get(bytes);
return bytes;
}
代码示例来源:origin: org.littleshoot/mina-port
@Override
public int read(byte[] b, int off, int len) {
int remaining = ByteBuffer.this.remaining();
if (remaining > 0) {
int readBytes = Math.min(remaining, len);
ByteBuffer.this.get(b, off, readBytes);
return readBytes;
} else {
return -1;
}
}
代码示例来源:origin: org.littleshoot/mina-port
public void messageReceived(NextFilter nextFilter, IoSession session,
Object message) throws Exception {
if (message instanceof ByteBuffer) {
add(session, ((ByteBuffer) message).remaining());
}
nextFilter.messageReceived(session, message);
}
}
代码示例来源: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
public int read(byte[] b, int off, int len) throws IOException {
synchronized (mutex) {
if (!waitForData()) {
return -1;
}
int readBytes;
if (len > buf.remaining()) {
readBytes = buf.remaining();
} else {
readBytes = len;
}
buf.get(b, off, readBytes);
return readBytes;
}
}
代码示例来源:origin: org.littleshoot/mina-port
public int compareTo(ByteBuffer that) {
int n = this.position() + Math.min(this.remaining(), that.remaining());
for (int i = this.position(), j = that.position(); i < n; i++, j++) {
byte v1 = this.get(i);
byte v2 = that.get(j);
if (v1 == v2) {
continue;
}
if (v1 < v2) {
return -1;
}
return +1;
}
return this.remaining() - that.remaining();
}
代码示例来源:origin: org.littleshoot/mina-port
/**
* Clears this buffer and fills its content with <tt>NUL</tt>.
* The position is set to zero, the limit is set to the capacity,
* and the mark is discarded.
*/
public ByteBuffer sweep() {
clear();
return fillAndReset(remaining());
}
代码示例来源:origin: org.littleshoot/mina-port
/**
* Clears this buffer and fills its content with <tt>value</tt>.
* The position is set to zero, the limit is set to the capacity,
* and the mark is discarded.
*/
public ByteBuffer sweep(byte value) {
clear();
return fillAndReset(value, remaining());
}
代码示例来源:origin: org.littleshoot/mina-util
public DecodingState decode(final ByteBuffer in,
final ProtocolDecoderOutput out) throws Exception
{
if (in.remaining() > 1)
{
final int decoded = in.getUnsignedShort();
return finishDecode(decoded, out);
}
else
{
return this;
}
}
代码示例来源:origin: org.littleshoot/mina-util
public DecodingState decode(final ByteBuffer in,
final ProtocolDecoderOutput out) throws Exception
{
if (in.remaining() > 3)
{
final long decoded = in.getUnsignedInt();
return finishDecode(decoded, out);
}
else
{
return this;
}
}
代码示例来源: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 void append(ByteBuffer in) {
if (overflowPosition != 0) {
discard(in);
} else if (buf.position() > maxLineLength - in.remaining()) {
overflowPosition = buf.position();
buf.clear();
discard(in);
} else {
getBuffer().put(in);
}
}
内容来源于网络,如有侵权,请联系作者删除!