本文整理了Java中io.vertx.core.buffer.Buffer.appendBytes()
方法的一些代码示例,展示了Buffer.appendBytes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.appendBytes()
方法的具体详情如下:
包路径:io.vertx.core.buffer.Buffer
类名称:Buffer
方法名:appendBytes
[英]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, String s) {
byte[] strBytes = s.getBytes(CharsetUtil.UTF_8);
buffer.appendInt(strBytes.length);
buffer.appendBytes(strBytes);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public void encodeToWire(Buffer buffer, byte[] byteArray) {
buffer.appendInt(byteArray.length);
buffer.appendBytes(byteArray);
}
代码示例来源:origin: eclipse-vertx/vert.x
private void writeString(Buffer buff, String str) {
byte[] strBytes = str.getBytes(CharsetUtil.UTF_8);
buff.appendInt(strBytes.length);
buff.appendBytes(strBytes);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public void writeToBuffer(Buffer buffer) {
String encoded = encode();
byte[] bytes = encoded.getBytes(StandardCharsets.UTF_8);
buffer.appendInt(bytes.length);
buffer.appendBytes(bytes);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public void writeToBuffer(Buffer buffer) {
String encoded = encode();
byte[] bytes = encoded.getBytes();
buffer.appendInt(bytes.length);
buffer.appendBytes(bytes);
}
代码示例来源:origin: vert-x3/vertx-examples
public Image(Vertx vertx, String name) {
try {
final BufferedImage raster = ImageIO.read(((VertxInternal) vertx).resolveFile(name));
width = raster.getWidth();
height = raster.getHeight();
data = raster.getRGB(0, 0, width, height, null, 0, width);
for (int pixel : data)
if (!colorMap.containsKey(pixel)) {
BufferedImage offlineImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = offlineImage.createGraphics();
g2.setPaint(new Color(pixel, true));
g2.fillRect(0, 0, 1, 1);
ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageIO.write(offlineImage, "PNG", out);
colorMap.put(pixel, Buffer.buffer().appendBytes(out.toByteArray()));
out.close();
g2.dispose();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public void encodeToWire(Buffer buffer, MyPOJO myPOJO) {
byte[] bytes = myPOJO.getStr().getBytes(CharsetUtil.UTF_8);
buffer.appendInt(bytes.length);
buffer.appendBytes(bytes);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public void encodeToWire(Buffer buffer, MyPOJO myPOJO) {
byte[] bytes = myPOJO.getStr().getBytes(CharsetUtil.UTF_8);
buffer.appendInt(bytes.length);
buffer.appendBytes(bytes);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testAppendBytes() throws Exception {
int bytesLen = 100;
byte[] bytes = TestUtils.randomByteArray(bytesLen);
Buffer b = Buffer.buffer();
b.appendBytes(bytes);
assertEquals(b.length(), bytes.length);
assertTrue(TestUtils.byteArraysEqual(bytes, b.getBytes()));
b.appendBytes(bytes);
assertEquals(b.length(), 2 * bytes.length);
assertNullPointerException(() -> b.appendBytes(null));
}
代码示例来源: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
@Test
public void testAppendBytesWithOffsetAndLen() throws Exception {
int bytesLen = 100;
byte[] bytes = TestUtils.randomByteArray(bytesLen);
int len = bytesLen - 2;
Buffer b = Buffer.buffer();
b.appendBytes(bytes, 1, len);
assertEquals(b.length(), len);
byte[] copy = new byte[len];
System.arraycopy(bytes, 1, copy, 0, len);
assertTrue(TestUtils.byteArraysEqual(copy, b.getBytes()));
b.appendBytes(bytes, 1, len);
assertEquals(b.length(), 2 * len);
assertNullPointerException(() -> b.appendBytes(null, 1, len));
}
代码示例来源: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: io.vertx/vertx-core
private void writeString(Buffer buff, String str) {
byte[] strBytes = str.getBytes(CharsetUtil.UTF_8);
buff.appendInt(strBytes.length);
buff.appendBytes(strBytes);
}
代码示例来源:origin: io.vertx/vertx-core
@Override
public void encodeToWire(Buffer buffer, byte[] byteArray) {
buffer.appendInt(byteArray.length);
buffer.appendBytes(byteArray);
}
代码示例来源:origin: io.vertx/vertx-core
@Override
public void writeToBuffer(Buffer buffer) {
String encoded = encode();
byte[] bytes = encoded.getBytes();
buffer.appendInt(bytes.length);
buffer.appendBytes(bytes);
}
代码示例来源:origin: io.vertx/vertx-core
@Override
public void encodeToWire(Buffer buffer, MyPOJO myPOJO) {
byte[] bytes = myPOJO.getStr().getBytes(CharsetUtil.UTF_8);
buffer.appendInt(bytes.length);
buffer.appendBytes(bytes);
}
代码示例来源:origin: io.vertx/vertx-core
@Override
public void encodeToWire(Buffer buffer, MyPOJO myPOJO) {
byte[] bytes = myPOJO.getStr().getBytes(CharsetUtil.UTF_8);
buffer.appendInt(bytes.length);
buffer.appendBytes(bytes);
}
代码示例来源:origin: io.vertx/vertx-core
@Test
public void testAppendBytes() throws Exception {
int bytesLen = 100;
byte[] bytes = TestUtils.randomByteArray(bytesLen);
Buffer b = Buffer.buffer();
b.appendBytes(bytes);
assertEquals(b.length(), bytes.length);
assertTrue(TestUtils.byteArraysEqual(bytes, b.getBytes()));
b.appendBytes(bytes);
assertEquals(b.length(), 2 * bytes.length);
assertNullPointerException(() -> b.appendBytes(null));
}
代码示例来源: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: 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);
}
}
内容来源于网络,如有侵权,请联系作者删除!