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

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

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

Buffer.arrayOffset介绍

[英]Returns the offset within this buffer's backing array of the first element of the buffer (optional operation). If this buffer is backed by an array then buffer position p corresponds to array index p + arrayOffset(). Invoke the hasArray method before invoking this method in order to ensure that this buffer has an accessible backing array.
[中]返回缓冲区第一个元素在此缓冲区的备份数组中的偏移量(可选操作)。如果此缓冲区由数组支持,则缓冲区位置p对应于数组索引p+arrayOffset()。在调用此方法之前调用hasArray方法,以确保此缓冲区具有可访问的后备数组。

代码示例

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

public static Buffer put(final MemoryManager memoryManager,
             Buffer dstBuffer,
             final byte[] tempBuffer,
             final String s) {
  final int size = s.length();
  dstBuffer = checkAndResizeIfNeeded(memoryManager, dstBuffer, size);
  if (dstBuffer.hasArray()) {
    @SuppressWarnings("MismatchedReadAndWriteOfArray")
    final byte[] array = dstBuffer.array();
    final int arrayOffs = dstBuffer.arrayOffset();
    int pos = arrayOffs + dstBuffer.position();
    // Make sure custom Strings do not contain service symbols
    for (int i = 0; i < size; i++) {
      byte b = (byte) (s.charAt(i));
      array[pos++] = isNonPrintableUsAscii(b) ? Constants.SP : b;
    }
    dstBuffer.position(pos - arrayOffs);
  } else {
    fastAsciiEncode(s, tempBuffer, dstBuffer);
  }
  return dstBuffer;
}

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

public static Buffer put(final MemoryManager memoryManager,
             Buffer dstBuffer,
             final byte[] tempBuffer,
             final String s) {
  final int size = s.length();
  dstBuffer = checkAndResizeIfNeeded(memoryManager, dstBuffer, size);
  if (dstBuffer.hasArray()) {
    @SuppressWarnings("MismatchedReadAndWriteOfArray")
    final byte[] array = dstBuffer.array();
    final int arrayOffs = dstBuffer.arrayOffset();
    int pos = arrayOffs + dstBuffer.position();
    // Make sure custom Strings do not contain service symbols
    for (int i = 0; i < size; i++) {
      byte b = (byte) (s.charAt(i));
      array[pos++] = isNonPrintableUsAscii(b) ? Constants.SP : b;
    }
    dstBuffer.position(pos - arrayOffs);
  } else {
    fastAsciiEncode(s, tempBuffer, dstBuffer);
  }
  return dstBuffer;
}

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

public static Buffer put(final MemoryManager memoryManager,
             Buffer dstBuffer,
             final byte[] tempBuffer,
             final String s) {
  final int size = s.length();
  dstBuffer = checkAndResizeIfNeeded(memoryManager, dstBuffer, size);
  if (dstBuffer.hasArray()) {
    @SuppressWarnings("MismatchedReadAndWriteOfArray")
    final byte[] array = dstBuffer.array();
    final int arrayOffs = dstBuffer.arrayOffset();
    int pos = arrayOffs + dstBuffer.position();
    // Make sure custom Strings do not contain service symbols
    for (int i = 0; i < size; i++) {
      byte b = (byte) (s.charAt(i));
      array[pos++] = isNonPrintableUsAscii(b) ? Constants.SP : b;
    }
    dstBuffer.position(pos - arrayOffs);
  } else {
    fastAsciiEncode(s, tempBuffer, dstBuffer);
  }
  return dstBuffer;
}

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

public static Buffer put(final MemoryManager memoryManager,
             Buffer dstBuffer,
             final byte[] tempBuffer,
             final String s) {
  final int size = s.length();
  dstBuffer = checkAndResizeIfNeeded(memoryManager, dstBuffer, size);
  if (dstBuffer.hasArray()) {
    @SuppressWarnings("MismatchedReadAndWriteOfArray")
    final byte[] array = dstBuffer.array();
    final int arrayOffs = dstBuffer.arrayOffset();
    int pos = arrayOffs + dstBuffer.position();
    // Make sure custom Strings do not contain service symbols
    for (int i = 0; i < size; i++) {
      byte b = (byte) (s.charAt(i));
      array[pos++] = isNonPrintableUsAscii(b) ? Constants.SP : b;
    }
    dstBuffer.position(pos - arrayOffs);
  } else {
    fastAsciiEncode(s, tempBuffer, dstBuffer);
  }
  return dstBuffer;
}

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

public static Buffer put(final MemoryManager memoryManager,
             Buffer dstBuffer,
             final byte[] tempBuffer,
             final String s) {
  final int size = s.length();
  dstBuffer = checkAndResizeIfNeeded(memoryManager, dstBuffer, size);
  if (dstBuffer.hasArray()) {
    @SuppressWarnings("MismatchedReadAndWriteOfArray")
    final byte[] array = dstBuffer.array();
    final int arrayOffs = dstBuffer.arrayOffset();
    int pos = arrayOffs + dstBuffer.position();
    // Make sure custom Strings do not contain service symbols
    for (int i = 0; i < size; i++) {
      byte b = (byte) (s.charAt(i));
      array[pos++] = isNonPrintableUsAscii(b) ? Constants.SP : b;
    }
    dstBuffer.position(pos - arrayOffs);
  } else {
    fastAsciiEncode(s, tempBuffer, dstBuffer);
  }
  return dstBuffer;
}

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

public static Buffer put(final MemoryManager memoryManager,
             Buffer dstBuffer,
             final byte[] tempBuffer,
             final String s) {
  final int size = s.length();
  dstBuffer = checkAndResizeIfNeeded(memoryManager, dstBuffer, size);
  if (dstBuffer.hasArray()) {
    @SuppressWarnings("MismatchedReadAndWriteOfArray")
    final byte[] array = dstBuffer.array();
    final int arrayOffs = dstBuffer.arrayOffset();
    int pos = arrayOffs + dstBuffer.position();
    // Make sure custom Strings do not contain service symbols
    for (int i = 0; i < size; i++) {
      byte b = (byte) (s.charAt(i));
      array[pos++] = isNonPrintableUsAscii(b) ? Constants.SP : b;
    }
    dstBuffer.position(pos - arrayOffs);
  } else {
    fastAsciiEncode(s, tempBuffer, dstBuffer);
  }
  return dstBuffer;
}

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

public static Buffer put(final MemoryManager memoryManager,
             Buffer dstBuffer,
             final byte[] tempBuffer,
             final String s) {
  final int size = s.length();
  dstBuffer = checkAndResizeIfNeeded(memoryManager, dstBuffer, size);
  if (dstBuffer.hasArray()) {
    @SuppressWarnings("MismatchedReadAndWriteOfArray")
    final byte[] array = dstBuffer.array();
    final int arrayOffs = dstBuffer.arrayOffset();
    int pos = arrayOffs + dstBuffer.position();
    // Make sure custom Strings do not contain service symbols
    for (int i = 0; i < size; i++) {
      byte b = (byte) (s.charAt(i));
      array[pos++] = isNonPrintableUsAscii(b) ? Constants.SP : b;
    }
    dstBuffer.position(pos - arrayOffs);
  } else {
    fastAsciiEncode(s, tempBuffer, dstBuffer);
  }
  return dstBuffer;
}

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

public static Buffer put(final MemoryManager memoryManager,
             Buffer dstBuffer,
             final byte[] tempBuffer,
             final String s) {
  final int size = s.length();
  dstBuffer = checkAndResizeIfNeeded(memoryManager, dstBuffer, size);
  if (dstBuffer.hasArray()) {
    @SuppressWarnings("MismatchedReadAndWriteOfArray")
    final byte[] array = dstBuffer.array();
    final int arrayOffs = dstBuffer.arrayOffset();
    int pos = arrayOffs + dstBuffer.position();
    // Make sure custom Strings do not contain service symbols
    for (int i = 0; i < size; i++) {
      byte b = (byte) (s.charAt(i));
      array[pos++] = isNonPrintableUsAscii(b) ? Constants.SP : b;
    }
    dstBuffer.position(pos - arrayOffs);
  } else {
    fastAsciiEncode(s, tempBuffer, dstBuffer);
  }
  return dstBuffer;
}

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

public static Buffer put(final MemoryManager memoryManager,
             Buffer dstBuffer,
             final byte[] tempBuffer,
             final String s) {
  final int size = s.length();
  dstBuffer = checkAndResizeIfNeeded(memoryManager, dstBuffer, size);
  if (dstBuffer.hasArray()) {
    @SuppressWarnings("MismatchedReadAndWriteOfArray")
    final byte[] array = dstBuffer.array();
    final int arrayOffs = dstBuffer.arrayOffset();
    int pos = arrayOffs + dstBuffer.position();
    // Make sure custom Strings do not contain service symbols
    for (int i = 0; i < size; i++) {
      byte b = (byte) (s.charAt(i));
      array[pos++] = isNonPrintableUsAscii(b) ? Constants.SP : b;
    }
    dstBuffer.position(pos - arrayOffs);
  } else {
    fastAsciiEncode(s, tempBuffer, dstBuffer);
  }
  return dstBuffer;
}

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

public static Buffer put(final MemoryManager memoryManager,
             Buffer dstBuffer,
             final byte[] tempBuffer,
             final String s) {
  final int size = s.length();
  dstBuffer = checkAndResizeIfNeeded(memoryManager, dstBuffer, size);
  if (dstBuffer.hasArray()) {
    @SuppressWarnings("MismatchedReadAndWriteOfArray")
    final byte[] array = dstBuffer.array();
    final int arrayOffs = dstBuffer.arrayOffset();
    int pos = arrayOffs + dstBuffer.position();
    // Make sure custom Strings do not contain service symbols
    for (int i = 0; i < size; i++) {
      byte b = (byte) (s.charAt(i));
      array[pos++] = isNonPrintableUsAscii(b) ? Constants.SP : b;
    }
    dstBuffer.position(pos - arrayOffs);
  } else {
    fastAsciiEncode(s, tempBuffer, dstBuffer);
  }
  return dstBuffer;
}

代码示例来源:origin: eclipse-ee4j/tyrus

@Override
  public NextAction handleRead(FilterChainContext ctx) throws IOException {
    // Get the parsed HttpContent (we assume prev. filter was HTTP)
    HttpContent message = ctx.getMessage();
    Socket tunnelSocket = tunnelSockets.get(ctx.getConnection());
    if (tunnelSocket == null) {
      // handle connection procedure
      return GrizzlyModProxy.this.handleConnect(ctx, message);
    }
    if (message.getContent().hasRemaining()) {
      // relay the content to the tunnel connection
      Buffer buffer = message.getContent();
      message.recycle();
      tunnelSocket.getOutputStream().write(buffer.array(), buffer.arrayOffset(), buffer.remaining());
    }
    return ctx.getStopAction();
  }
}

代码示例来源:origin: org.glassfish.tyrus.tests/tyrus-test-tools

@Override
  public NextAction handleRead(FilterChainContext ctx) throws IOException {
    // Get the parsed HttpContent (we assume prev. filter was HTTP)
    HttpContent message = ctx.getMessage();
    Socket tunnelSocket = tunnelSockets.get(ctx.getConnection());
    if (tunnelSocket == null) {
      // handle connection procedure
      return GrizzlyModProxy.this.handleConnect(ctx, message);
    }
    if (message.getContent().hasRemaining()) {
      // relay the content to the tunnel connection
      Buffer buffer = message.getContent();
      message.recycle();
      tunnelSocket.getOutputStream().write(buffer.array(), buffer.arrayOffset(), buffer.remaining());
    }
    return ctx.getStopAction();
  }
}

代码示例来源:origin: org.mule.services/mule-service-http

public void sendInputStreamChunk() throws IOException {
 final Buffer buffer = memoryManager.allocate(bufferSize);
 final byte[] bufferByteArray = buffer.array();
 final int offset = buffer.arrayOffset();
 final int length = buffer.remaining();
 int bytesRead = inputStream.read(bufferByteArray, offset, length);
 final HttpContent content;
 if (bytesRead == -1) {
  content = httpResponsePacket.httpTrailerBuilder().build();
  isDone = true;
 } else {
  buffer.limit(bytesRead);
  content = httpResponsePacket.httpContentBuilder().content(buffer).build();
 }
 ctx.write(content, this);
}

代码示例来源:origin: org.mule.modules/mule-module-http

public void sendInputStreamChunk() throws IOException
{
  final Buffer buffer = memoryManager.allocate(8 * 1024);
  final byte[] bufferByteArray = buffer.array();
  final int offset = buffer.arrayOffset();
  final int length = buffer.remaining();
  int bytesRead = inputStream.read(bufferByteArray, offset, length);
  final HttpContent content;
  if (bytesRead == -1)
  {
    content = httpResponsePacket.httpTrailerBuilder().build();
    isDone = true;
  }
  else
  {
    buffer.limit(bytesRead);
    content = httpResponsePacket.httpContentBuilder().content(buffer).build();
  }
  ctx.write(content, this);
}

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

final int offset = buffer.arrayOffset();
final int length = buffer.remaining();

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

parsingState.arrayOffset = inputBuffer.arrayOffset();
final int end = parsingState.arrayOffset + inputBuffer.limit();

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

parsingState.arrayOffset = inputBuffer.arrayOffset();
final int end = parsingState.arrayOffset + inputBuffer.limit();

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

parsingState.arrayOffset = inputBuffer.arrayOffset();
final int end = parsingState.arrayOffset + inputBuffer.limit();

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

parsingState.arrayOffset = inputBuffer.arrayOffset();
final int end = parsingState.arrayOffset + inputBuffer.limit();

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

parsingState.arrayOffset = inputBuffer.arrayOffset();
final int end = parsingState.arrayOffset + inputBuffer.limit();

相关文章