java.nio.Buffer.mark()方法的使用及代码示例

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

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

Buffer.mark介绍

[英]Mark is where position will be set when reset() is called. Mark is not set by default. Mark is always no less than zero and no greater than position.
[中]标记是调用reset()时设置位置的位置。默认情况下不设置标记。标记始终不小于零且不大于position

代码示例

代码示例来源:origin: wildfly/wildfly

/**
 * Set the buffer mark.
 *
 * @see Buffer#mark()
 * @param <T> the buffer type
 * @param buffer the buffer to mark
 * @return the buffer instance
 */
public static <T extends Buffer> T mark(T buffer) {
  buffer.mark();
  return buffer;
}

代码示例来源:origin: org.mongodb/mongo-java-driver

/**
 * Fill with zeros the remaining of the supplied buffer. This method does
 * not change the buffer position.
 * <p>
 * Typically used for security reasons, with buffers that contains
 * now-unused plaintext.
 */
public void zeroRemaining() {
  ((Buffer) buffer).mark();
  buffer.put(ZEROS, 0, buffer.remaining());
  ((Buffer) buffer).reset();
}

代码示例来源:origin: org.mongodb/mongo-java-driver

/**
 * Fill the buffer with zeros. This method does not change the buffer position.
 * <p>
 * Typically used for security reasons, with buffers that contains
 * now-unused plaintext.
 */
public void zero() {
  ((Buffer) buffer).mark();
  ((Buffer) buffer).position(0);
  buffer.put(ZEROS, 0, buffer.remaining());
  ((Buffer) buffer).reset();
}

代码示例来源:origin: org.jsoup/jsoup

private static BomCharset detectCharsetFromBom(final ByteBuffer byteData) {
  final Buffer buffer = byteData; // .mark and rewind used to return Buffer, now ByteBuffer, so cast for backward compat
  buffer.mark();
  byte[] bom = new byte[4];
  if (byteData.remaining() >= bom.length) {
    byteData.get(bom);
    buffer.rewind();
  }
  if (bom[0] == 0x00 && bom[1] == 0x00 && bom[2] == (byte) 0xFE && bom[3] == (byte) 0xFF || // BE
    bom[0] == (byte) 0xFF && bom[1] == (byte) 0xFE && bom[2] == 0x00 && bom[3] == 0x00) { // LE
    return new BomCharset("UTF-32", false); // and I hope it's on your system
  } else if (bom[0] == (byte) 0xFE && bom[1] == (byte) 0xFF || // BE
    bom[0] == (byte) 0xFF && bom[1] == (byte) 0xFE) {
    return new BomCharset("UTF-16", false); // in all Javas
  } else if (bom[0] == (byte) 0xEF && bom[1] == (byte) 0xBB && bom[2] == (byte) 0xBF) {
    return new BomCharset("UTF-8", true); // in all Javas
    // 16 and 32 decoders consume the BOM to determine be/le; utf-8 should be consumed here
  }
  return null;
}

代码示例来源:origin: spring-projects/spring-framework

buffer.mark();

代码示例来源:origin: intel-hadoop/HiBench

public String printBuffer(Buffer buf) {
    String info =
        buf.toString() +
        "< " + buf.position() +
        ", " + buf.mark() +
        ", " + buf.limit() + 
        ", " + buf.capacity() + " >";
    return info;
  }
/*

代码示例来源:origin: stackoverflow.com

Charset utf8 = Charset.forName("UTF-8");
CharsetEncoder encoder = utf8.newEncoder();
CharBuffer input = //allocate in some way, or pass as parameter
ByteBuffer output = ByteBuffer.allocate(10);

int limit = input.limit();
while(input.position() < limit) {
  output.clear();
  input.mark();
  input.limit(Math.max(input.position() + 2, input.capacity()));
  if (Character.isHighSurrogate(input.get()) && !Character.isLowSurrogate(input.get())) {
    //Malformed surrogate pair; do something!
  }
  input.limit(input.position());
  input.reset();
  encoder.encode(input, output, false);
  int encodedLen = output.position();
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

/**
 * Set the buffer mark.
 *
 * @see Buffer#mark()
 * @param <T> the buffer type
 * @param buffer the buffer to mark
 * @return the buffer instance
 */
public static <T extends Buffer> T mark(T buffer) {
  buffer.mark();
  return buffer;
}

代码示例来源:origin: org.springframework/spring-messaging

buffer.mark();

代码示例来源:origin: apache/jackrabbit-oak

public Buffer mark() {
  ((java.nio.Buffer) buffer).mark();
  return this;
}

代码示例来源:origin: com.metsci.glimpse/glimpse-util

public Buffer mark( )
{
  return _buffer.mark( );
}

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

private void toWriteMode(Buffer buffer) {
  buffer.mark()
     .position(buffer.limit())
     .limit(buffer.capacity());
}

代码示例来源:origin: org.mongodb/mongodb-driver-core

/**
 * Fill the buffer with zeros. This method does not change the buffer position.
 * <p>
 * Typically used for security reasons, with buffers that contains
 * now-unused plaintext.
 */
public void zero() {
  ((Buffer) buffer).mark();
  ((Buffer) buffer).position(0);
  buffer.put(ZEROS, 0, buffer.remaining());
  ((Buffer) buffer).reset();
}

代码示例来源:origin: org.mongodb/mongodb-driver-core

/**
 * Fill with zeros the remaining of the supplied buffer. This method does
 * not change the buffer position.
 * <p>
 * Typically used for security reasons, with buffers that contains
 * now-unused plaintext.
 */
public void zeroRemaining() {
  ((Buffer) buffer).mark();
  buffer.put(ZEROS, 0, buffer.remaining());
  ((Buffer) buffer).reset();
}

代码示例来源:origin: stackoverflow.com

public static String calculateEtag(final String s) throws java.security.NoSuchAlgorithmException {
  final java.nio.ByteBuffer buf = java.nio.charset.StandardCharsets.UTF_8.encode(s);
  final java.security.MessageDigest digest = java.security.MessageDigest.getInstance("SHA1");
  buf.mark();
  digest.update(buf);
  buf.reset();
  return String.format("W/\"%s\"", javax.xml.bind.DatatypeConverter.printHexBinary(digest.digest()));
}

代码示例来源:origin: org.ops4j.pax.tipi/org.ops4j.pax.tipi.tomcat-embed-core

private void toWriteMode(Buffer buffer) {
  buffer.mark()
     .position(buffer.limit())
     .limit(buffer.capacity());
}

代码示例来源:origin: stackoverflow.com

File file = new File("fileChannelTest.log");
 FileOutputStream fos = new FileOutputStream(file);
 FileChannel fileChannel = fos.getChannel();
 ByteBuffer bb1 = ByteBuffer.wrap("This is a log line to test!\n".getBytes());
 ByteBuffer bb2 = ByteBuffer.allocateDirect(bb1.remaining());
 bb2.put(bb1).flip();
 bb2.mark();
 long freeMemory = Runtime.getRuntime().freeMemory();
 for (int i = 0; i < 1000000; i++) {
   bb2.reset();
   fileChannel.write(bb2);
 }
 System.out.println("Memory allocated: " + (freeMemory - Runtime.getRuntime().freeMemory()));

代码示例来源:origin: org.bytedeco/javacv

void findPairs(Mat objectDescriptors, Mat imageDescriptors) {
  int size = imageDescriptors.cols();
  ByteBuffer objectBuf = objectDescriptors.createBuffer();
  ByteBuffer imageBuf = imageDescriptors.createBuffer();
  for (int i = 0; i * size < objectBuf.capacity(); i++) {
    ByteBuffer descriptor = (ByteBuffer)objectBuf.position(i * size).limit((i + 1) * size).mark();
    int nearestNeighbor = naiveNearestNeighbor(descriptor, imageBuf);
    if (nearestNeighbor >= 0) {
      ptpairs.add(i);
      ptpairs.add(nearestNeighbor);
    }
  }
}

代码示例来源:origin: poqudrof/PapARt

void findPairs(Mat objectDescriptors, Mat imageDescriptors) {
  int size = imageDescriptors.cols();
  ByteBuffer objectBuf = objectDescriptors.createBuffer();
  ByteBuffer imageBuf = imageDescriptors.createBuffer();
  for (int i = 0; i * size < objectBuf.capacity(); i++) {
    ByteBuffer descriptor = (ByteBuffer) objectBuf.position(i * size).limit((i + 1) * size).mark();
    int nearestNeighbor = naiveNearestNeighbor(descriptor, imageBuf);
    if (nearestNeighbor >= 0) {
      ptpairs.add(i);
      ptpairs.add(nearestNeighbor);
    }
  }
}

代码示例来源:origin: stackoverflow.com

ByteBuffer buffer = ByteBuffer.allocate(Resource.MEMORY_ALLOC_SIZE);
while (fic.read(buffer) >= 0) {
  buffer.flip();

  buffer.mark();
  while (buffer.hasRemaining()) {
    channel2.write(buffer);
  }

  buffer.reset():
  while (buffer.hasRemaining()) {
    channel.write(buffer);
  }

  buffer.clear();
}

相关文章