本文整理了Java中java.nio.Buffer.reset()
方法的一些代码示例,展示了Buffer.reset()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.reset()
方法的具体详情如下:
包路径:java.nio.Buffer
类名称:Buffer
方法名:reset
[英]Resets the position of this buffer to the mark
.
[中]将此缓冲区的位置重置为mark
。
代码示例来源:origin: wildfly/wildfly
/**
* Reset the buffer.
*
* @see Buffer#reset()
* @param <T> the buffer type
* @param buffer the buffer to reset
* @return the buffer instance
*/
public static <T extends Buffer> T reset(T buffer) {
buffer.reset();
return buffer;
}
代码示例来源: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.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: spring-projects/spring-framework
buffer.reset();
代码示例来源: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
/**
* Reset the buffer.
*
* @see Buffer#reset()
* @param <T> the buffer type
* @param buffer the buffer to reset
* @return the buffer instance
*/
public static <T extends Buffer> T reset(T buffer) {
buffer.reset();
return buffer;
}
代码示例来源:origin: apache/jackrabbit-oak
public Buffer reset() {
((java.nio.Buffer) buffer).reset();
return this;
}
代码示例来源:origin: org.springframework/spring-messaging
buffer.reset();
代码示例来源:origin: com.metsci.glimpse/glimpse-util
public Buffer reset( )
{
return _buffer.reset( );
}
代码示例来源:origin: org.apache.tomcat/tomcat-catalina
private void toReadMode(Buffer buffer) {
buffer.limit(buffer.position())
.reset();
}
代码示例来源:origin: org.ops4j.pax.tipi/org.ops4j.pax.tipi.tomcat-embed-core
private void toReadMode(Buffer buffer) {
buffer.limit(buffer.position())
.reset();
}
代码示例来源:origin: stackoverflow.com
ByteBuffer buf = ByteBuffer.allocate(1024); // just allocate enough, can be reused later;
buf.reset(); // in case this is reused, you need reset()
SocketChannel channel = socket.getChannel();
channel.read(buf);
short mId = buf.order(ByteOrder.LITTLE_ENDIAN).getShort();
byte[] otherBytes = new byte[....];
buf.get(otherBytes);
代码示例来源: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: com.ardor3d/ardor3d-core
/**
* @see Buffer#reset();
*/
public void reset() {
getBuffer().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: Renanse/Ardor3D
/**
* @see Buffer#reset();
*/
public void reset() {
getBuffer().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: net.java.dev.jna/jna-platform
protected static List<String> decodeStringSequence(ByteBuffer bb) {
List<String> names = new ArrayList<String>();
bb.mark(); // first key starts from here
while (bb.hasRemaining()) {
if (bb.get() == 0) {
ByteBuffer nameBuffer = (ByteBuffer) bb.duplicate().limit(bb.position() - 1).reset();
if (nameBuffer.hasRemaining()) {
names.add(decodeString(nameBuffer));
}
bb.mark(); // next key starts from here
}
}
return names;
}
代码示例来源: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: 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();
}
内容来源于网络,如有侵权,请联系作者删除!