本文整理了Java中io.vertx.core.buffer.Buffer.getString()
方法的一些代码示例,展示了Buffer.getString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.getString()
方法的具体详情如下:
包路径:io.vertx.core.buffer.Buffer
类名称:Buffer
方法名:getString
[英]Returns a copy of a sub-sequence the Buffer as a String starting at position startand ending at position end - 1 interpreted as a String in UTF-8 encoding
[中]将缓冲区中的子序列的副本作为字符串返回,该字符串从位置START开始,在位置end-1结束,在UTF-8编码中被解释为字符串
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public int readFromBuffer(int pos, Buffer buffer) {
int length = buffer.getInt(pos);
int start = pos + 4;
String encoded = buffer.getString(start, start + length);
fromJson(encoded);
return pos + length + 4;
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public int readFromBuffer(int pos, Buffer buffer) {
int length = buffer.getInt(pos);
int start = pos + 4;
String encoded = buffer.getString(start, start + length);
fromJson(encoded);
return pos + length + 4;
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public int readFromBuffer(int pos, Buffer buffer) {
int length = buffer.getInt(pos);
str = buffer.getString(pos + 4, pos + 4 + length);
return pos + 4 + length;
}
}
代码示例来源:origin: vert-x3/vertx-examples
@Override
public CustomMessage decodeFromWire(int position, Buffer buffer) {
// My custom message starting from this *position* of buffer
int _pos = position;
// Length of JSON
int length = buffer.getInt(_pos);
// Get JSON string by it`s length
// Jump 4 because getInt() == 4 bytes
String jsonStr = buffer.getString(_pos+=4, _pos+=length);
JsonObject contentJson = new JsonObject(jsonStr);
// Get fields
int statusCode = contentJson.getInteger("statusCode");
String resultCode = contentJson.getString("resultCode");
String summary = contentJson.getString("summary");
// We can finally create custom message object
return new CustomMessage(statusCode, resultCode, summary);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testGetString() throws Exception {
String str = TestUtils.randomAlphaString(100);
Buffer b = Buffer.buffer(str, "UTF-8"); // encode ascii as UTF-8 so one byte per char
assertEquals(100, b.length());
String substr = b.getString(10, 20);
assertEquals(str.substring(10, 20), substr);
substr = b.getString(10, 20, "UTF-8");
assertEquals(str.substring(10, 20), substr);
}
代码示例来源:origin: advantageous/qbit
public static String readString(final Buffer buffer, final int[] location) {
final short size = buffer.getShort(location[0]);
int start = location[0] + 2;
int end = start + size;
final String utf_8 = buffer.getString(start, end, StandardCharsets.UTF_8.displayName());
location[0] = end;
return utf_8;
}
代码示例来源:origin: eclipse-vertx/vert.x
throw new IllegalStateException("format error in client request (attribute type domain name), got " + toHex(buffer2));
host = buffer2.getString(5, 5 + stringLen);
port = buffer2.getUnsignedShort(5 + stringLen);
} else {
代码示例来源:origin: eclipse-vertx/vert.x
assertIndexOutOfBoundsException(() -> b.getBytes(-1, -1));
assertIndexOutOfBoundsException(() -> b.getBytes(-100, -100));
assertIndexOutOfBoundsException(() -> b.getString(-1, bytesLen));
assertIndexOutOfBoundsException(() -> b.getString(0, bytesLen + 1));
assertIllegalArgumentException(() -> b.getString(2, 1));
assertIndexOutOfBoundsException(() -> b.getString(-1, bytesLen, "UTF-8"));
assertIndexOutOfBoundsException(() -> b.getString(0, bytesLen + 1, "UTF-8"));
assertIllegalArgumentException(() -> b.getString(2, 1, "UTF-8"));
代码示例来源:origin: io.vertx/vertx-core
@Override
public int readFromBuffer(int pos, Buffer buffer) {
int length = buffer.getInt(pos);
int start = pos + 4;
String encoded = buffer.getString(start, start + length);
fromJson(encoded);
return pos + length + 4;
}
代码示例来源:origin: io.vertx/vertx-core
@Override
public int readFromBuffer(int pos, Buffer buffer) {
int length = buffer.getInt(pos);
int start = pos + 4;
String encoded = buffer.getString(start, start + length);
fromJson(encoded);
return pos + length + 4;
}
代码示例来源:origin: io.vertx/vertx-core
@Override
public int readFromBuffer(int pos, Buffer buffer) {
int length = buffer.getInt(pos);
str = buffer.getString(pos + 4, pos + 4 + length);
return pos + 4 + length;
}
}
代码示例来源:origin: io.vertx/vertx-core
@Test
public void testGetString() throws Exception {
String str = TestUtils.randomAlphaString(100);
Buffer b = Buffer.buffer(str, "UTF-8"); // encode ascii as UTF-8 so one byte per char
assertEquals(100, b.length());
String substr = b.getString(10, 20);
assertEquals(str.substring(10, 20), substr);
substr = b.getString(10, 20, "UTF-8");
assertEquals(str.substring(10, 20), substr);
}
代码示例来源:origin: advantageous/qbit
@Test
public void testWriteString() throws Exception {
Buffer buffer = Buffer.buffer();
BufferUtils.writeString(buffer, "hi mom");
final short size = buffer.getShort(0);
ok = size == 6 || die();
final String utf_8 = buffer.getString(2, size + 2, StandardCharsets.UTF_8.displayName());
puts(utf_8);
ok = utf_8.equals("hi mom") || die();
}
代码示例来源:origin: vert-x3/vertx-rx
/**
* Returns a copy of a sub-sequence the Buffer as a <code>String</code> starting at position <code>start</code>
* and ending at position <code>end - 1</code> interpreted as a String in the specified encoding
* @param start
* @param end
* @param enc
* @return
*/
public String getString(int start, int end, String enc) {
String ret = delegate.getString(start, end, enc);
return ret;
}
代码示例来源:origin: io.vertx/vertx-rx-java
/**
* Returns a copy of a sub-sequence the Buffer as a <code>String</code> starting at position <code>start</code>
* and ending at position <code>end - 1</code> interpreted as a String in the specified encoding
* @param start
* @param end
* @param enc
* @return
*/
public String getString(int start, int end, String enc) {
String ret = delegate.getString(start, end, enc);
return ret;
}
代码示例来源:origin: org.swisspush/gateleen-core
@Override
public void handle(AsyncResult<Message<Buffer>> message) {
Buffer buffer = message.result().body();
int headerLength = buffer.getInt(0);
JsonObject header = new JsonObject(buffer.getString(4, headerLength+4));
doneHandler.handle(header.getInteger("statusCode"));
}
});
代码示例来源:origin: org.swisspush/gateleen-core
@Override
public void handle(AsyncResult<Message<Buffer>> message) {
Buffer buffer = message.result().body();
int headerLength = buffer.getInt(0);
JsonObject header = new JsonObject(buffer.getString(4, headerLength+4));
doneHandler.handle(header.getInteger("statusCode"));
}
});
代码示例来源:origin: io.vertx/vertx-core
throw new IllegalStateException("format error in client request (attribute type domain name), got " + toHex(buffer2));
host = buffer2.getString(5, 5 + stringLen);
port = buffer2.getUnsignedShort(5 + stringLen);
} else {
代码示例来源:origin: org.swisspush/gateleen-core
@Override
public void handle(AsyncResult<Message<Buffer>> message) {
Buffer buffer = message.result().body();
int headerLength = buffer.getInt(0);
JsonObject header = new JsonObject(buffer.getString(4, headerLength+4));
if(header.getInteger("statusCode") == 200) {
bodyHandler.handle(buffer.getBuffer(4+headerLength, buffer.length()));
} else {
bodyHandler.handle(null);
}
}
});
代码示例来源:origin: io.vertx/vertx-core
assertIndexOutOfBoundsException(() -> b.getBytes(-1, -1));
assertIndexOutOfBoundsException(() -> b.getBytes(-100, -100));
assertIndexOutOfBoundsException(() -> b.getString(-1, bytesLen));
assertIndexOutOfBoundsException(() -> b.getString(0, bytesLen + 1));
assertIllegalArgumentException(() -> b.getString(2, 1));
assertIndexOutOfBoundsException(() -> b.getString(-1, bytesLen, "UTF-8"));
assertIndexOutOfBoundsException(() -> b.getString(0, bytesLen + 1, "UTF-8"));
assertIllegalArgumentException(() -> b.getString(2, 1, "UTF-8"));
内容来源于网络,如有侵权,请联系作者删除!