本文整理匯總了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);
}
}