本文整理了Java中io.vertx.core.buffer.Buffer.getBytes()
方法的一些代码示例,展示了Buffer.getBytes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.getBytes()
方法的具体详情如下:
包路径:io.vertx.core.buffer.Buffer
类名称:Buffer
方法名:getBytes
[英]Returns a copy of the entire Buffer as a byte[]
[中]以字节[]形式返回整个缓冲区的副本
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public String decodeFromWire(int pos, Buffer buffer) {
int length = buffer.getInt(pos);
pos += 4;
byte[] bytes = buffer.getBytes(pos, pos + length);
return new String(bytes, CharsetUtil.UTF_8);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public byte[] decodeFromWire(int pos, Buffer buffer) {
int length = buffer.getInt(pos);
pos += 4;
return buffer.getBytes(pos, pos + length);
}
代码示例来源:origin: eclipse-vertx/vert.x
public Void perform() {
try {
Path target = vertx.resolveFile(path).toPath();
Files.write(target, data.getBytes());
return null;
} catch (IOException e) {
throw new FileSystemException(e);
}
}
};
代码示例来源:origin: eclipse-vertx/vert.x
static void toJson(GoAway obj, java.util.Map<String, Object> json) {
if (obj.getDebugData() != null) {
json.put("debugData", java.util.Base64.getEncoder().encodeToString(obj.getDebugData().getBytes()));
}
json.put("errorCode", obj.getErrorCode());
json.put("lastStreamId", obj.getLastStreamId());
}
}
代码示例来源:origin: eclipse-vertx/vert.x
public static void toJson(JksOptions obj, java.util.Map<String, Object> json) {
if (obj.getPassword() != null) {
json.put("password", obj.getPassword());
}
if (obj.getPath() != null) {
json.put("path", obj.getPath());
}
if (obj.getValue() != null) {
json.put("value", java.util.Base64.getEncoder().encodeToString(obj.getValue().getBytes()));
}
}
}
代码示例来源:origin: eclipse-vertx/vert.x
static void toJson(PfxOptions obj, java.util.Map<String, Object> json) {
if (obj.getPassword() != null) {
json.put("password", obj.getPassword());
}
if (obj.getPath() != null) {
json.put("path", obj.getPath());
}
if (obj.getValue() != null) {
json.put("value", java.util.Base64.getEncoder().encodeToString(obj.getValue().getBytes()));
}
}
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public String decodeFromWire(int pos, Buffer buffer) {
int length = buffer.getInt(pos);
pos += 4;
byte[] bytes = buffer.getBytes(pos, pos + length);
return new String(bytes, CharsetUtil.UTF_8);
}
代码示例来源:origin: eclipse-vertx/vert.x
public static String encodeSettings(io.vertx.core.http.Http2Settings settings) {
Buffer buffer = Buffer.buffer();
fromVertxSettings(settings).forEach((c, l) -> {
buffer.appendUnsignedShort(c);
buffer.appendUnsignedInt(l);
});
return Base64.getUrlEncoder().encodeToString(buffer.getBytes());
}
代码示例来源:origin: eclipse-vertx/vert.x
private byte[] readBytes(int len) throws VertxException {
if (pos + len > in.length()) {
throw new VertxException("Invalid DER: stream too short, missing tag");
}
Buffer s = in.slice(pos, pos + len);
pos += len;
return s.getBytes();
}
代码示例来源:origin: eclipse-vertx/vert.x
private void viaString(Buffer buffer) throws Exception {
int pos = 0;
int length = buffer.getInt(pos);
pos += 4;
byte[] encoded = buffer.getBytes(pos, pos + length);
String str = new String(encoded, CharsetUtil.UTF_8);
consume(new JsonObject(str));
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public MyPOJO decodeFromWire(int pos, Buffer buffer) {
int length = buffer.getInt(pos);
pos += 4;
byte[] bytes = buffer.getBytes(pos, pos + length);
String str = new String(bytes, CharsetUtil.UTF_8);
return new MyPOJO(str);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test(expected = IndexOutOfBoundsException.class)
public void testGetBytesWithTooSmallByteArray() throws Exception {
byte[] bytes = TestUtils.randomByteArray(100);
Buffer b = Buffer.buffer(bytes);
byte[] result = new byte[bytes.length / 4];
b.getBytes(bytes.length / 4, bytes.length / 4 + bytes.length / 2, result);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test(expected = IndexOutOfBoundsException.class)
public void testGetBytesWithBadOffset() throws Exception {
byte[] bytes = TestUtils.randomByteArray(100);
Buffer b = Buffer.buffer(bytes);
byte[] result = new byte[bytes.length / 2];
b.getBytes(bytes.length / 4, bytes.length / 4 + bytes.length / 2, result, -1);
}
代码示例来源:origin: eclipse-vertx/vert.x
private void testSetBytesBuffer(Buffer buff, Function<byte[], Buffer> bufferFactory) throws Exception {
Buffer b = bufferFactory.apply(TestUtils.randomByteArray(100));
buff.setBuffer(50, b);
byte[] b2 = buff.getBytes(50, 150);
assertEquals(b, Buffer.buffer(b2));
byte[] b3 = TestUtils.randomByteArray(100);
buff.setBytes(50, b3);
byte[] b4 = buff.getBytes(50, 150);
assertEquals(Buffer.buffer(b3), Buffer.buffer(b4));
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testGetBytesWithByteArrayFull() throws Exception {
byte[] bytes = TestUtils.randomByteArray(100);
Buffer b = Buffer.buffer(bytes);
byte[] sub = new byte[bytes.length];
System.arraycopy(bytes, bytes.length / 4, sub, 12, bytes.length / 2);
byte[] result = new byte[bytes.length];
b.getBytes(bytes.length / 4, bytes.length / 4 + bytes.length / 2, result, 12);
assertTrue(TestUtils.byteArraysEqual(sub, result));
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testGetBytes2() throws Exception {
byte[] bytes = TestUtils.randomByteArray(100);
Buffer b = Buffer.buffer(bytes);
byte[] sub = new byte[bytes.length / 2];
System.arraycopy(bytes, bytes.length / 4, sub, 0, bytes.length / 2);
assertTrue(TestUtils.byteArraysEqual(sub, b.getBytes(bytes.length / 4, bytes.length / 4 + bytes.length / 2)));
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testGetBytes() throws Exception {
byte[] bytes = TestUtils.randomByteArray(100);
Buffer b = Buffer.buffer(bytes);
assertTrue(TestUtils.byteArraysEqual(bytes, b.getBytes()));
}
代码示例来源:origin: eclipse-vertx/vert.x
private void testSetBytesString(Buffer buff) throws Exception {
String str = TestUtils.randomUnicodeString(100);
buff.setString(50, str);
byte[] b1 = buff.getBytes(50, buff.length());
String str2 = new String(b1, "UTF-8");
assertEquals(str, str2);
assertNullPointerException(() -> Buffer.buffer(150).setString(0, null));
assertNullPointerException(() -> Buffer.buffer(150).setString(0, null, "UTF-8"));
//TODO setString with encoding
}
代码示例来源:origin: eclipse-vertx/vert.x
public void testAppendBuff(Function<byte[], Buffer> bufferFactory) throws Exception {
int bytesLen = 100;
byte[] bytes = TestUtils.randomByteArray(bytesLen);
Buffer toAppend = bufferFactory.apply(bytes);
Buffer b = Buffer.buffer();
b.appendBuffer(toAppend);
assertEquals(b.length(), bytes.length);
assertTrue(TestUtils.byteArraysEqual(bytes, b.getBytes()));
b.appendBuffer(toAppend);
assertEquals(b.length(), 2 * bytes.length);
assertNullPointerException(() -> b.appendBuffer(null));
}
代码示例来源: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));
}
内容来源于网络,如有侵权,请联系作者删除!