本文整理了Java中io.vertx.core.buffer.Buffer.appendByte()
方法的一些代码示例,展示了Buffer.appendByte()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.appendByte()
方法的具体详情如下:
包路径:io.vertx.core.buffer.Buffer
类名称:Buffer
方法名:appendByte
[英]Appends the specified byte to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.
Returns a reference to this so multiple operations can be appended together.
[中]将指定的字节追加到缓冲区的末尾。缓冲区将根据需要扩展以容纳写入的任何字节。
返回对此的引用,以便可以将多个操作附加在一起。
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public void encodeToWire(Buffer buffer, Byte b) {
buffer.appendByte(b);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public void encodeToWire(Buffer buffer, ReplyException body) {
buffer.appendByte((byte)body.failureType().toInt());
buffer.appendInt(body.failureCode());
if (body.getMessage() == null) {
buffer.appendByte((byte)0);
} else {
buffer.appendByte((byte)1);
byte[] encoded = body.getMessage().getBytes(CharsetUtil.UTF_8);
buffer.appendInt(encoded.length);
buffer.appendBytes(encoded);
}
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public void encodeToWire(Buffer buffer, MyReplyException body) {
buffer.appendInt(body.failureCode());
if (body.getMessage() == null) {
buffer.appendByte((byte)0);
} else {
buffer.appendByte((byte)1);
byte[] encoded = body.getMessage().getBytes(CharsetUtil.UTF_8);
buffer.appendInt(encoded.length);
buffer.appendBytes(encoded);
}
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public void encodeToWire(Buffer buffer, Boolean b) {
buffer.appendByte((byte)(b ? 0 : 1));
}
代码示例来源:origin: io.vertx/vertx-core
@Override
public void encodeToWire(Buffer buffer, ReplyException body) {
buffer.appendByte((byte)body.failureType().toInt());
buffer.appendInt(body.failureCode());
if (body.getMessage() == null) {
buffer.appendByte((byte)0);
} else {
buffer.appendByte((byte)1);
byte[] encoded = body.getMessage().getBytes(CharsetUtil.UTF_8);
buffer.appendInt(encoded.length);
buffer.appendBytes(encoded);
}
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
/*
Test parsing with delimiters
*/
public void testDelimited() {
delimited(Buffer.buffer().appendByte((byte)'\n'));
delimited(Buffer.buffer().appendByte((byte) '\r').appendByte((byte) '\n'));
delimited(Buffer.buffer(new byte[]{0, 3, 2, 5, 6, 4, 6}));
}
代码示例来源:origin: io.vertx/vertx-core
@Override
public void encodeToWire(Buffer buffer, MyReplyException body) {
buffer.appendInt(body.failureCode());
if (body.getMessage() == null) {
buffer.appendByte((byte)0);
} else {
buffer.appendByte((byte)1);
byte[] encoded = body.getMessage().getBytes(CharsetUtil.UTF_8);
buffer.appendInt(encoded.length);
buffer.appendBytes(encoded);
}
}
代码示例来源:origin: eclipse-vertx/vert.x
public Buffer encodeToWire() {
int length = 1024; // TODO make this configurable
Buffer buffer = Buffer.buffer(length);
buffer.appendInt(0);
buffer.appendByte(WIRE_PROTOCOL_VERSION);
byte systemCodecID = messageCodec.systemCodecID();
buffer.appendByte(systemCodecID);
if (systemCodecID == -1) {
// User codec
writeString(buffer, messageCodec.name());
}
buffer.appendByte(send ? (byte)0 : (byte)1);
writeString(buffer, address);
if (replyAddress != null) {
writeString(buffer, replyAddress);
} else {
buffer.appendInt(0);
}
buffer.appendInt(sender.port);
writeString(buffer, sender.host);
encodeHeaders(buffer);
writeBody(buffer);
buffer.setInt(0, buffer.length() - 4);
return buffer;
}
代码示例来源:origin: vert-x3/vertx-examples
@Override
public BatchStream write(Batch batch) {
if (batch == null) {
if (exceptionHandler != null) {
exceptionHandler.handle(new NullPointerException());
}
} else {
Buffer protocol = Buffer.buffer();
protocol.appendInt(0);
protocol.appendByte((byte) batch.getType());
protocol.appendBuffer(batch.getRaw());
protocol.setInt(0, protocol.length() - 4);
writeStream.write(protocol);
}
return this;
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testReportProtocolViolationOnServer() {
server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)).websocketHandler(ws -> {
AtomicReference<Throwable> failure = new AtomicReference<>();
ws.closeHandler(v -> {
assertNotNull(failure.get());
testComplete();
});
ws.exceptionHandler(failure::set);
});
server.listen(ar -> {
assertTrue(ar.succeeded());
handshake(sock -> {
// Let's write an invalid frame
Buffer buff = Buffer.buffer();
buff.appendByte((byte)(0x8)).appendByte((byte)0); // Violates protocol with V13 (final control frame)
sock.write(buff);
});
});
await();
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testReportProtocolViolationOnClient() {
server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)).requestHandler(req -> {
NetSocket sock = getUpgradedNetSocket(req, "/some/path");
// Let's write an invalid frame
Buffer buff = Buffer.buffer();
buff.appendByte((byte)(0x8)).appendByte((byte)0); // Violates protocol with V13 (final control frame)
sock.write(buff);
});
server.listen(ar -> {
assertTrue(ar.succeeded());
client.websocketStream(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/some/path", null, WebsocketVersion.V13).
handler(ws -> {
AtomicReference<Throwable> failure = new AtomicReference<>();
ws.closeHandler(v -> {
assertNotNull(failure.get());
testComplete();
});
ws.exceptionHandler(failure::set);
});
});
await();
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testAppendByte() throws Exception {
int bytesLen = 100;
byte[] bytes = TestUtils.randomByteArray(bytesLen);
Buffer b = Buffer.buffer();
for (int i = 0; i < bytesLen; i++) {
b.appendByte(bytes[i]);
}
assertEquals(b.length(), bytes.length);
assertTrue(TestUtils.byteArraysEqual(bytes, b.getBytes()));
for (int i = 0; i < bytesLen; i++) {
b.appendByte(bytes[i]);
}
assertEquals(b.length(), 2 * bytes.length);
}
代码示例来源:origin: eclipse-vertx/vert.x
buff.appendByte((byte) 0x01); // Incomplete Text frame
buff.appendByte((byte) firstFrame.length());
buff.appendString(firstFrame);
sock.write(buff);
buff.appendByte((byte) (0x00 | 0x80)); // Complete continuation frame
buff.appendByte((byte) continuationFrame.length());
buff.appendString(continuationFrame);
sock.write(buff);
代码示例来源:origin: eclipse-vertx/vert.x
@Test
// Let's manually handle the websocket handshake and write a frame to the client
public void testHandleWSManually() throws Exception {
String path = "/some/path";
String message = "here is some text data";
server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)).requestHandler(req -> {
NetSocket sock = getUpgradedNetSocket(req, path);
// Let's write a Text frame raw
Buffer buff = Buffer.buffer();
buff.appendByte((byte)129); // Text frame
buff.appendByte((byte)message.length());
buff.appendString(message);
sock.write(buff);
});
server.listen(ar -> {
assertTrue(ar.succeeded());
client.websocketStream(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, path).
handler(ws -> {
ws.handler(buff -> {
assertEquals(message, buff.toString("UTF-8"));
testComplete();
});
});
});
await();
}
代码示例来源:origin: io.vertx/vertx-core
@Override
public void encodeToWire(Buffer buffer, Byte b) {
buffer.appendByte(b);
}
代码示例来源:origin: io.vertx/vertx-core
@Override
public void encodeToWire(Buffer buffer, Boolean b) {
buffer.appendByte((byte)(b ? 0 : 1));
}
代码示例来源:origin: eclipse-vertx/vert.x
Buffer authReply = Buffer.buffer(new byte[] { 1, (byte) username.length() });
authReply.appendString(username);
authReply.appendByte((byte) username.length());
authReply.appendString(username);
if (!buffer3.equals(authReply)) {
代码示例来源:origin: resteasy/Resteasy
@Override
public void write(int b) throws IOException
{
if (buffer.length() >= chunkSize - 1)
{
flush();
}
buffer.appendByte((byte) b);
}
代码示例来源:origin: io.vertx/vertx-core
@Test
/*
Test parsing with delimiters
*/
public void testDelimited() {
delimited(Buffer.buffer().appendByte((byte)'\n'));
delimited(Buffer.buffer().appendByte((byte) '\r').appendByte((byte) '\n'));
delimited(Buffer.buffer(new byte[]{0, 3, 2, 5, 6, 4, 6}));
}
代码示例来源:origin: io.vertx/vertx-core
@Test
public void testAppendByte() throws Exception {
int bytesLen = 100;
byte[] bytes = TestUtils.randomByteArray(bytesLen);
Buffer b = Buffer.buffer();
for (int i = 0; i < bytesLen; i++) {
b.appendByte(bytes[i]);
}
assertEquals(b.length(), bytes.length);
assertTrue(TestUtils.byteArraysEqual(bytes, b.getBytes()));
for (int i = 0; i < bytesLen; i++) {
b.appendByte(bytes[i]);
}
assertEquals(b.length(), 2 * bytes.length);
}
内容来源于网络,如有侵权,请联系作者删除!