org.glassfish.grizzly.Buffer.slice()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(120)

本文整理了Java中org.glassfish.grizzly.Buffer.slice()方法的一些代码示例,展示了Buffer.slice()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.slice()方法的具体详情如下:
包路径:org.glassfish.grizzly.Buffer
类名称:Buffer
方法名:slice

Buffer.slice介绍

[英]Creates a new Buffer whose content is a shared subsequence of this buffer's content.

The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.

The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer, and its mark will be undefined. The new buffer will be direct if, and only if, this buffer is direct, and it will be read-only if, and only if, this buffer is read-only.
[中]创建新的Buffer,其内容是此缓冲区内容的共享子序列。
新缓冲区的内容将从此缓冲区的当前位置开始。此缓冲区内容的更改将在新缓冲区中可见,反之亦然;两个缓冲器的位置、极限和标记值将是独立的。
新缓冲区的位置将为零,其容量和限制将是此缓冲区中剩余的字节数,其标记将未定义。当且仅当此缓冲区为直接缓冲区时,新缓冲区将为直接缓冲区;当且仅当此缓冲区为只读缓冲区时,新缓冲区将为只读缓冲区。

代码示例

代码示例来源:origin: javaee/grizzly

private static Buffer parseTrailerCRLF(final HttpPacketParsing httpPacket,
    final Buffer input) {
  final HeaderParsingState parsingState = httpPacket.getHeaderParsingState();
  if (parsingState.state == CHUNK_LENGTH_PARSED_STATE) {
    while (input.hasRemaining()) {
      if (input.get() == Constants.LF) {
        parsingState.recycle();
        if (input.hasRemaining()) {
          return input.slice();
        }
        return null;
      }
    }
    return null;
  }
  return input;
}

代码示例来源:origin: javaee/grizzly

private static Buffer parseTrailerCRLF(final HttpPacketParsing httpPacket,
    final Buffer input) {
  final HeaderParsingState parsingState = httpPacket.getHeaderParsingState();
  if (parsingState.state == CHUNK_LENGTH_PARSED_STATE) {
    while (input.hasRemaining()) {
      if (input.get() == Constants.LF) {
        parsingState.recycle();
        if (input.hasRemaining()) {
          return input.slice();
        }
        return null;
      }
    }
    return null;
  }
  return input;
}

代码示例来源:origin: javaee/grizzly

private static Buffer parseTrailerCRLF(final HttpPacketParsing httpPacket,
    final Buffer input) {
  final HeaderParsingState parsingState = httpPacket.getHeaderParsingState();
  if (parsingState.state == CHUNK_LENGTH_PARSED_STATE) {
    while (input.hasRemaining()) {
      if (input.get() == Constants.LF) {
        parsingState.recycle();
        if (input.hasRemaining()) {
          return input.slice();
        }
        return null;
      }
    }
    return null;
  }
  return input;
}

代码示例来源:origin: javaee/grizzly

private static Buffer parseTrailerCRLF(final HttpPacketParsing httpPacket,
    final Buffer input) {
  final HeaderParsingState parsingState = httpPacket.getHeaderParsingState();
  if (parsingState.state == CHUNK_LENGTH_PARSED_STATE) {
    while (input.hasRemaining()) {
      if (input.get() == Constants.LF) {
        parsingState.recycle();
        if (input.hasRemaining()) {
          return input.slice();
        }
        return null;
      }
    }
    return null;
  }
  return input;
}

代码示例来源:origin: org.glassfish.grizzly/grizzly-websockets-server

private static Buffer parseTrailerCRLF(final HttpPacketParsing httpPacket,
    final Buffer input) {
  final HeaderParsingState parsingState = httpPacket.getHeaderParsingState();
  if (parsingState.state == CHUNK_LENGTH_PARSED_STATE) {
    while (input.hasRemaining()) {
      if (input.get() == Constants.LF) {
        parsingState.recycle();
        if (input.hasRemaining()) {
          return input.slice();
        }
        return null;
      }
    }
    return null;
  }
  return input;
}

代码示例来源:origin: javaee/grizzly

private static Buffer parseTrailerCRLF(final HttpPacketParsing httpPacket,
    final Buffer input) {
  final HeaderParsingState parsingState = httpPacket.getHeaderParsingState();
  if (parsingState.state == CHUNK_LENGTH_PARSED_STATE) {
    while (input.hasRemaining()) {
      if (input.get() == Constants.LF) {
        parsingState.recycle();
        if (input.hasRemaining()) {
          return input.slice();
        }
        return null;
      }
    }
    return null;
  }
  return input;
}

代码示例来源:origin: javaee/grizzly

private static Buffer parseTrailerCRLF(final HttpPacketParsing httpPacket,
    final Buffer input) {
  final HeaderParsingState parsingState = httpPacket.getHeaderParsingState();
  if (parsingState.state == CHUNK_LENGTH_PARSED_STATE) {
    while (input.hasRemaining()) {
      if (input.get() == Constants.LF) {
        parsingState.recycle();
        if (input.hasRemaining()) {
          return input.slice();
        }
        return null;
      }
    }
    return null;
  }
  return input;
}

代码示例来源:origin: javaee/grizzly

@Test
public void testBufferSlice() {
  Buffer b = mm.allocate(10);
  b.putInt(1);
  ByteBuffer bb = b.slice().toByteBuffer().slice();
  bb.rewind();
  bb.putInt(2);
  b.rewind();
  assertEquals(1, b.getInt());
}

代码示例来源:origin: javaee/grizzly

@Override
public void write(Buffer bufferToWrite) throws IOException {
  if (multiBufferWindow == null) {
    multiBufferWindow = CompositeBuffer.newBuffer();
  }
  final boolean isInternalBufferEmpty = buffer == null ||
      (buffer.position() - lastSlicedPosition) == 0;
  
  if (!isInternalBufferEmpty) {
    final Buffer slice =
        buffer.slice(lastSlicedPosition, buffer.position());
    
    multiBufferWindow.append(slice);
    lastSlicedPosition = buffer.position();
  }
  multiBufferWindow.append(bufferToWrite);
  ensureBufferCapacity(0);
}

代码示例来源:origin: javaee/grizzly

@Override
public void write(Buffer bufferToWrite) throws IOException {
  if (multiBufferWindow == null) {
    multiBufferWindow = CompositeBuffer.newBuffer();
  }
  final boolean isInternalBufferEmpty = buffer == null ||
      (buffer.position() - lastSlicedPosition) == 0;
  
  if (!isInternalBufferEmpty) {
    final Buffer slice =
        buffer.slice(lastSlicedPosition, buffer.position());
    
    multiBufferWindow.append(slice);
    lastSlicedPosition = buffer.position();
  }
  multiBufferWindow.append(bufferToWrite);
  ensureBufferCapacity(0);
}

代码示例来源:origin: javaee/grizzly

@Override
public void write(Buffer bufferToWrite) throws IOException {
  if (multiBufferWindow == null) {
    multiBufferWindow = CompositeBuffer.newBuffer();
  }
  final boolean isInternalBufferEmpty = buffer == null ||
      (buffer.position() - lastSlicedPosition) == 0;
  
  if (!isInternalBufferEmpty) {
    final Buffer slice =
        buffer.slice(lastSlicedPosition, buffer.position());
    
    multiBufferWindow.append(slice);
    lastSlicedPosition = buffer.position();
  }
  multiBufferWindow.append(bufferToWrite);
  ensureBufferCapacity(0);
}

代码示例来源:origin: org.mule.glassfish.grizzly/grizzly-framework

@Override
public void write(Buffer bufferToWrite) throws IOException {
  if (multiBufferWindow == null) {
    multiBufferWindow = CompositeBuffer.newBuffer();
  }
  final boolean isInternalBufferEmpty = buffer == null ||
      (buffer.position() - lastSlicedPosition) == 0;
  
  if (!isInternalBufferEmpty) {
    final Buffer slice =
        buffer.slice(lastSlicedPosition, buffer.position());
    
    multiBufferWindow.append(slice);
    lastSlicedPosition = buffer.position();
  }
  multiBufferWindow.append(bufferToWrite);
  ensureBufferCapacity(0);
}

代码示例来源:origin: org.glassfish.grizzly/grizzly-websockets-server

@Override
public void write(Buffer bufferToWrite) throws IOException {
  if (multiBufferWindow == null) {
    multiBufferWindow = CompositeBuffer.newBuffer();
  }
  final boolean isInternalBufferEmpty = buffer == null ||
      (buffer.position() - lastSlicedPosition) == 0;
  
  if (!isInternalBufferEmpty) {
    final Buffer slice =
        buffer.slice(lastSlicedPosition, buffer.position());
    
    multiBufferWindow.append(slice);
    lastSlicedPosition = buffer.position();
  }
  multiBufferWindow.append(bufferToWrite);
  ensureBufferCapacity(0);
}

代码示例来源:origin: javaee/grizzly

@Override
public void write(Buffer bufferToWrite) throws IOException {
  if (multiBufferWindow == null) {
    multiBufferWindow = CompositeBuffer.newBuffer();
  }
  final boolean isInternalBufferEmpty = buffer == null ||
      (buffer.position() - lastSlicedPosition) == 0;
  
  if (!isInternalBufferEmpty) {
    final Buffer slice =
        buffer.slice(lastSlicedPosition, buffer.position());
    
    multiBufferWindow.append(slice);
    lastSlicedPosition = buffer.position();
  }
  multiBufferWindow.append(bufferToWrite);
  ensureBufferCapacity(0);
}

代码示例来源:origin: javaee/grizzly

@Override
public void write(Buffer bufferToWrite) throws IOException {
  if (multiBufferWindow == null) {
    multiBufferWindow = CompositeBuffer.newBuffer();
  }
  final boolean isInternalBufferEmpty = buffer == null ||
      (buffer.position() - lastSlicedPosition) == 0;
  
  if (!isInternalBufferEmpty) {
    final Buffer slice =
        buffer.slice(lastSlicedPosition, buffer.position());
    
    multiBufferWindow.append(slice);
    lastSlicedPosition = buffer.position();
  }
  multiBufferWindow.append(bufferToWrite);
  ensureBufferCapacity(0);
}

代码示例来源:origin: javaee/grizzly

@Override
public void write(Buffer bufferToWrite) throws IOException {
  if (multiBufferWindow == null) {
    multiBufferWindow = CompositeBuffer.newBuffer();
  }
  final boolean isInternalBufferEmpty = buffer == null ||
      (buffer.position() - lastSlicedPosition) == 0;
  
  if (!isInternalBufferEmpty) {
    final Buffer slice =
        buffer.slice(lastSlicedPosition, buffer.position());
    
    multiBufferWindow.append(slice);
    lastSlicedPosition = buffer.position();
  }
  multiBufferWindow.append(bufferToWrite);
  ensureBufferCapacity(0);
}

代码示例来源:origin: org.glassfish.grizzly/grizzly-core

@Override
public void write(Buffer bufferToWrite) throws IOException {
  if (multiBufferWindow == null) {
    multiBufferWindow = CompositeBuffer.newBuffer();
  }
  final boolean isInternalBufferEmpty = buffer == null ||
      (buffer.position() - lastSlicedPosition) == 0;
  
  if (!isInternalBufferEmpty) {
    final Buffer slice =
        buffer.slice(lastSlicedPosition, buffer.position());
    
    multiBufferWindow.append(slice);
    lastSlicedPosition = buffer.position();
  }
  multiBufferWindow.append(bufferToWrite);
  ensureBufferCapacity(0);
}

代码示例来源:origin: javaee/grizzly

@Override
public void write(Buffer bufferToWrite) throws IOException {
  if (multiBufferWindow == null) {
    multiBufferWindow = CompositeBuffer.newBuffer();
  }
  final boolean isInternalBufferEmpty = buffer == null ||
      (buffer.position() - lastSlicedPosition) == 0;
  
  if (!isInternalBufferEmpty) {
    final Buffer slice =
        buffer.slice(lastSlicedPosition, buffer.position());
    
    multiBufferWindow.append(slice);
    lastSlicedPosition = buffer.position();
  }
  multiBufferWindow.append(bufferToWrite);
  ensureBufferCapacity(0);
}

代码示例来源:origin: javaee/grizzly

@Override
public void write(Buffer bufferToWrite) throws IOException {
  if (multiBufferWindow == null) {
    multiBufferWindow = CompositeBuffer.newBuffer();
  }
  final boolean isInternalBufferEmpty = buffer == null ||
      (buffer.position() - lastSlicedPosition) == 0;
  
  if (!isInternalBufferEmpty) {
    final Buffer slice =
        buffer.slice(lastSlicedPosition, buffer.position());
    
    multiBufferWindow.append(slice);
    lastSlicedPosition = buffer.position();
  }
  multiBufferWindow.append(bufferToWrite);
  ensureBufferCapacity(0);
}

代码示例来源:origin: org.glassfish.grizzly/grizzly-http-server-core

@Override
public void write(Buffer bufferToWrite) throws IOException {
  if (multiBufferWindow == null) {
    multiBufferWindow = CompositeBuffer.newBuffer();
  }
  final boolean isInternalBufferEmpty = buffer == null ||
      (buffer.position() - lastSlicedPosition) == 0;
  
  if (!isInternalBufferEmpty) {
    final Buffer slice =
        buffer.slice(lastSlicedPosition, buffer.position());
    
    multiBufferWindow.append(slice);
    lastSlicedPosition = buffer.position();
  }
  multiBufferWindow.append(bufferToWrite);
  ensureBufferCapacity(0);
}

相关文章