本文整理了Java中org.vertx.java.core.buffer.Buffer
类的一些代码示例,展示了Buffer
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer
类的具体详情如下:
包路径:org.vertx.java.core.buffer.Buffer
类名称:Buffer
[英]A Buffer represents a sequence of zero or more bytes that can be written to or read from, and which expands as necessary to accomodate any bytes written to it.
There are two ways to write data to a Buffer: The first method involves methods that take the form setXXX. These methods write data into the buffer starting at the specified position. The position does not have to be inside data that has already been written to the buffer; the buffer will automatically expand to encompass the position plus any data that needs to be written. All positions are measured in bytes and start with zero.
The second method involves methods that take the form appendXXX; these methods append data at the end of the buffer.
Methods exist to both set and append all primitive types, java.lang.String, java.nio.ByteBuffer and other instances of Buffer.
Data can be read from a buffer by invoking methods which take the form getXXX. These methods take a parameter representing the position in the Buffer from where to read data.
Once a buffer has been written to a socket or other write stream, the same buffer instance can't be written again to another WriteStream.
[中]缓冲区表示可以写入或读取的零个或多个字节的序列,并根据需要扩展以容纳写入它的任何字节。
将数据写入缓冲区有两种方法:第一种方法涉及采用setXXX形式的方法。这些方法从指定位置开始将数据写入缓冲区。该位置不必位于已写入缓冲区的数据内部;缓冲区将自动扩展以包含位置和任何需要写入的数据。所有位置都以字节为单位,以零开始。
第二种方法涉及采用appendXXX形式的方法;这些方法将数据追加到缓冲区的末尾。
方法既可用于设置也可用于附加所有基元类型java。字符串,java。尼奥。ByteBuffer和其他缓冲区实例。
可以通过调用getXXX格式的方法从缓冲区读取数据。这些方法采用一个参数,该参数表示缓冲区中读取数据的位置。
一旦缓冲区写入套接字或其他写入流,同一缓冲区实例就不能再写入另一个WriteStream。
代码示例来源:origin: io.fabric8/gateway-core
static public Buffer encode(String value) {
int size = value.length();
Buffer rc = new Buffer(size);
for (int i = 0; i < size; i++) {
rc.appendByte((byte) (value.charAt(i) & 0xFF));
}
return rc;
}
代码示例来源:origin: io.fabric8.jube.images.fabric8/fabric8-mq
static public Buffer trimFront(Buffer self) {
int length = self.length();
int pos = 0;
while ((pos < length) && (self.getByte(pos) <= ' ')) {
pos++;
}
return (pos == 0) ? self : self.getBuffer(pos, length);
}
代码示例来源:origin: org.vert-x/vertx-core
protected void readBody(int pos, Buffer readBuff) {
boolean isNull = readBuff.getByte(pos) == (byte)0;
if (!isNull) {
pos++;
int buffLength = readBuff.getInt(pos);
pos += 4;
byte[] bytes = readBuff.getBytes(pos, pos + buffLength);
body = new Buffer(bytes);
}
}
代码示例来源:origin: org.vert-x/vertx-core
protected void writeBody(Buffer buff) {
if (body == null) {
buff.appendByte((byte)0);
} else {
buff.appendByte((byte)1);
buff.appendInt(body.length());
buff.appendBuffer(body);
}
}
代码示例来源:origin: org.vert-x/vertx-core
protected void writeBody(Buffer buff) {
if (body == null) {
buff.appendByte((byte)0);
} else {
buff.appendByte((byte)1);
buff.appendInt(encoded.length);
buff.appendBytes(encoded);
}
}
代码示例来源:origin: org.vert-x/vertx-core
/**
* Returns a copy of a sub-sequence the Buffer as a {@link Buffer} starting at position {@code start}
* and ending at position {@code end - 1}
*/
public Buffer getBuffer(int start, int end) {
return new Buffer(getBytes(start, end));
}
代码示例来源:origin: io.fabric8.ipaas.apps/fabric8mq
static public boolean matches(Buffer self, int pos, Buffer needle) {
int needleLength = needle.length();
for (int i = 0; i < needleLength; i++) {
if (self.getByte(pos + i) != needle.getByte(i)) {
return false;
}
}
return true;
}
代码示例来源:origin: io.fabric8/gateway-core
public AmqpHeader(){
this(new Buffer(new byte[]{
'A', 'M', 'Q', 'P', 0, 1, 0, 0
}));
}
代码示例来源:origin: org.vert-x/vertx-core
protected void readBody(int pos, Buffer readBuff) {
boolean isNull = readBuff.getByte(pos) == (byte)0;
if (!isNull) {
pos++;
int buffLength = readBuff.getInt(pos);
pos += 4;
body = readBuff.getBytes(pos, pos + buffLength);
}
}
代码示例来源:origin: io.fabric8.jube.images.fabric8/fabric8-mq
private void process(Buffer event) {
if (!isStopped() && !isStopping()) {
try {
int length = event.length();
org.fusesource.hawtbuf.DataByteArrayInputStream dataIn = new org.fusesource.hawtbuf.DataByteArrayInputStream(event.getBytes());
codec.parse(dataIn, length);
} catch (Throwable e) {
transport.handleException(e);
}
}
}
代码示例来源:origin: io.fabric8.ipaas.apps/fabric8mq
public StompFrame apply() throws IOException {
Buffer line = readUntil((byte) '\n', StompProtocol.maxCommandLength, "The maximum command length was exceeded");
if (line != null) {
Buffer action = BufferSupport.chomp(line);
if (trim) {
action = BufferSupport.trim(action);
}
if (action.length() > 0) {
StompFrame frame = new StompFrame(action.toString());
nextDecodeAction = read_headers(frame);
return nextDecodeAction.apply();
}
}
return null;
}
};
代码示例来源:origin: io.fabric8/gateway-core
@Override
public String toString() {
return buffer.toString();
}
}
代码示例来源:origin: org.vert-x/vertx-core
public void fillInRequest(HttpClientRequest req, String hostHeader) throws Exception {
req.headers().put(HttpHeaders.Names.CONNECTION, "Upgrade");
req.headers().put(HttpHeaders.Names.UPGRADE, "WebSocket");
req.headers().put(HttpHeaders.Names.HOST, hostHeader);
req.headers().put(HttpHeaders.Names.SEC_WEBSOCKET_KEY1, this.challenge.getKey1String());
req.headers().put(HttpHeaders.Names.SEC_WEBSOCKET_KEY2, this.challenge.getKey2String());
Buffer buff = new Buffer(6);
buff.appendBytes(challenge.getKey3());
buff.appendByte((byte) '\r');
buff.appendByte((byte) '\n');
req.write(buff);
}
代码示例来源:origin: com.englishtown/vertx-mod-jersey
/**
* {@inheritDoc}
*/
@Override
public void flush() throws IOException {
checkState();
// Only flush to underlying very.x response if the content-length has been set
if (buffer.length() > 0 && response.headers().contains(HttpHeaders.CONTENT_LENGTH)) {
response.write(buffer);
buffer = new Buffer();
}
}
代码示例来源:origin: io.fabric8.jube.images.fabric8/fabric8-mq
@Override
public void handle(Buffer buffer) {
if (encryptedReadBuffer == null) {
encryptedReadBuffer = buffer;
} else {
encryptedReadBuffer.appendBuffer(buffer);
}
encryptedReadBufferUnderflow = false;
pumpReads();
}
});
代码示例来源:origin: com.englishtown/vertx-mod-jersey
/**
* {@inheritDoc}
*/
@Override
public void write(byte[] b, int off, int len) throws IOException {
checkState();
Buffer buffer = new Buffer();
if (off == 0 && len == b.length) {
buffer.appendBytes(b);
} else {
buffer.appendBytes(Arrays.copyOfRange(b, off, off + len));
}
response.write(buffer);
}
代码示例来源:origin: org.vert-x/vertx-core
public Void action() throws Exception {
Files.write(target, data.getBytes());
return null;
}
};
代码示例来源:origin: com.englishtown/vertx-mod-jersey
public void handle(Buffer buff) {
body.appendBuffer(buff);
if (body.length() > maxBodySize) {
throw new RuntimeException("The input stream has exceeded the max allowed body size "
+ maxBodySize + ".");
}
}
});
代码示例来源:origin: io.fabric8.jube.images.fabric8/fabric8-mq
static void append(Buffer self, MQTTFrame value) {
self.appendByte(value.header());
int remaining = 0;
for (org.fusesource.hawtbuf.Buffer buffer : value.buffers) {
remaining += buffer.length;
}
do {
byte digit = (byte) (remaining & 0x7F);
remaining >>>= 7;
if (remaining > 0) {
digit |= 0x80;
}
self.appendByte(digit);
} while (remaining > 0);
for (org.fusesource.hawtbuf.Buffer buffer : value.buffers) {
// TODO: see if we avoid the byte[] conversion.
self.appendBytes(buffer.toByteArray());
}
}
代码示例来源:origin: org.vert-x/vertx-core
protected void readBody(int pos, Buffer readBuff) {
boolean isNull = readBuff.getByte(pos) == (byte)0;
if (!isNull) {
body = readBuff.getDouble(++pos);
}
}
内容来源于网络,如有侵权,请联系作者删除!