本文整理汇总了Java中io.vertx.core.buffer.Buffer.toString方法的典型用法代码示例。如果您正苦于以下问题:Java Buffer.toString方法的具体用法?Java Buffer.toString怎么用?Java Buffer.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.core.buffer.Buffer
的用法示例。
在下文中一共展示了Buffer.toString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseMetaData
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
/**
* 解析Buffer为metadata(JsonObject)。
*
* @param buffer buffer
* @param charset charset
* @return JsonObject
*/
public static JsonObject parseMetaData(Buffer buffer, String charset) {
JsonObject json = new JsonObject();
if (buffer == null || buffer.length() == 0) {
return json;
}
String meta = buffer.toString(charset);
if (meta == null || meta.isEmpty()) {
return json;
}
String[] md = meta.split(FDFS_RECORD_SEPERATOR);
for (String item : md) {
String[] kv = item.split(FDFS_FIELD_SEPERATOR);
if (kv.length >= 2) {
json.put(FdfsUtils.fdfsTrim(kv[0]), FdfsUtils.fdfsTrim(kv[1]));
}
}
return json;
}
示例2: parseXml
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
private void parseXml(Buffer buffer, Future<Void> future) {
String xmlFeed = buffer.toString("UTF-8");
final SAXBuilder sax = new SAXBuilder();
try {
Document doc = sax.build(new InputSource(new StringReader(xmlFeed)));
List<JsonObject> entries = RssUtils.toJson(doc);
vertx.eventBus().publish((CommonConstants.VERTX_EVENT_BUS_HE_RSS_JDG_PUT), new JsonArray(entries));
future.complete();
} catch (JDOMException | IOException e) {
future.fail(new RuntimeException("Exception caught when building SAX Document", e));
}
}
示例3: replySuccess
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
private void replySuccess(final HttpServerResponse response,
final HttpClientResponse clientResponse,
final Buffer buffer) {
final String data = buffer.toString();
// Copy header
response.headers().setAll(clientResponse.headers());
response.setStatusCode(clientResponse.statusCode());
response.setStatusMessage(clientResponse.statusMessage());
response.write(data);
response.end();
}
示例4: loadPem
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
private static List<byte[]> loadPem(Buffer data, String delimiter) throws IOException {
String pem = data.toString();
String beginDelimiter = "-----BEGIN " + delimiter + "-----";
String endDelimiter = "-----END " + delimiter + "-----";
List<byte[]> pems = new ArrayList<>();
int index = 0;
while (true) {
index = pem.indexOf(beginDelimiter, index);
if (index == -1) {
break;
}
index += beginDelimiter.length();
int end = pem.indexOf(endDelimiter, index);
if (end == -1) {
throw new RuntimeException("Missing " + endDelimiter + " delimiter");
}
String content = pem.substring(index, end);
content = content.replaceAll("\\s", "");
if (content.length() == 0) {
throw new RuntimeException("Empty pem file");
}
index = end + 1;
pems.add(Base64.getDecoder().decode(content));
}
if (pems.isEmpty()) {
throw new RuntimeException("Missing " + beginDelimiter + " delimiter");
}
return pems;
}
示例5: parseBitcoinPriceLine
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
/**
* One line has the format:
* <pre>
* timestamp,price,volume
* </pre>
* <ul>
* <li>timestamp is unix timestamp in seconds</li>
* <li>price is in USD in double</li>
* <li>volume is in USD in double</li>
* </ul>
*
* @param bufferedLine
*/
private void parseBitcoinPriceLine(final Buffer bufferedLine) {
final String line = bufferedLine.toString();
final int firstDelim = line.indexOf(',');
final int lastDelim = line.lastIndexOf(',');
if (firstDelim != -1 && lastDelim != -1 && firstDelim != lastDelim) {
long timestamp = Long.parseLong(line.substring(0, firstDelim)) * 1000;
double price = Double.parseDouble(line.substring(firstDelim + 1, lastDelim));
this.dataset.put(timestamp, price);
}
}