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

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

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

Buffer.array介绍

[英]Returns the byte array that backs this buffer (optional operation). Modifications to this buffer's content will cause the returned array's content to be modified, and vice versa. Invoke the hasArray method before invoking this method in order to ensure that this buffer has an accessible backing array.
[中]返回支持此缓冲区的字节数组(可选操作)。修改此缓冲区的内容将导致修改返回数组的内容,反之亦然。在调用此方法之前调用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: javaee/grizzly

final Buffer buffer = bufferChunk.getBuffer();
if (buffer.hasArray() && buffer.array().length == length) {
  return buffer.array();

代码示例来源: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

final Buffer buffer = bufferChunk.getBuffer();
if (buffer.hasArray() && buffer.array().length == length) {
  return buffer.array();

代码示例来源: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

final Buffer buffer = bufferChunk.getBuffer();
if (buffer.hasArray() && buffer.array().length == length) {
  return buffer.array();

代码示例来源: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: 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: 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.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 byte[] bufferByteArray = buffer.array();
final int offset = buffer.arrayOffset();
final int length = buffer.remaining();

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

final int end = parsingState.arrayOffset + inputBuffer.limit();
final byte[] input = inputBuffer.array();

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

final int end = parsingState.arrayOffset + inputBuffer.limit();
final byte[] input = inputBuffer.array();

相关文章