本文整理汇总了Java中io.vertx.core.buffer.Buffer.length方法的典型用法代码示例。如果您正苦于以下问题:Java Buffer.length方法的具体用法?Java Buffer.length怎么用?Java Buffer.length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.core.buffer.Buffer
的用法示例。
在下文中一共展示了Buffer.length方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
@Override
public void handle(Buffer buff) {
if (failed) {
return;
}
uploadSize += buff.length();
if (bodyLimit != -1 && uploadSize > bodyLimit) {
failed = true;
context.fail(Status.REQUEST_ENTITY_TOO_LARGE.getStatusCode());
} else {
// multipart requests will not end up in the request body
// url encoded should also not, however jQuery by default
// post in urlencoded even if the payload is something else
if (!isMultipart /* && !isUrlEncoded */) {
body.appendBuffer(buff);
}
}
}
示例2: readObject
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
default <T> T readObject(Buffer buffer, ProtobufFeature protobufFeature) throws Exception {
if (buffer == null || buffer.length() == 0) {
// void以及函数入参为null的场景
// 空串时,protobuf至少为编码为1字节
return (T) readFromEmpty();
}
ByteBuffer nioBuffer = buffer.getByteBuf().nioBuffer();
Input input = new ByteBufferInput(nioBuffer, false);
ProtobufFeatureUtils.setProtobufFeature(protobufFeature);
try {
return (T) readObject(input);
} finally {
ProtobufFeatureUtils.removeProtobufFeature();
}
}
示例3: parseHeader
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
/**
* 解析报文头。
*
* @param headerBuffer header Buffer
* @param expectedCommand expectedCommand
* @param expectedBodyLength expectedBodyLength
* @return async result of the length of the packet body
*/
public static Future<Long> parseHeader(Buffer headerBuffer, byte expectedCommand, long expectedBodyLength) {
if (headerBuffer.length() != HEADER_BYTE_LENGTH) {
return Future.failedFuture(new FdfsException("receive packet size" + headerBuffer.length()
+ " is not equal to the expected header size: " + HEADER_BYTE_LENGTH));
}
byte command = headerBuffer.getByte(PROTO_HEADER_CMD_INDEX);
if (command != expectedCommand) {
return Future.failedFuture(new FdfsException(
"receive command: " + command + " is not equal to the expected command: " + expectedCommand));
}
byte status = headerBuffer.getByte(PROTO_HEADER_STATUS_INDEX);
if (status != HEADER_STATUS_SUCCESS) {
return Future.failedFuture(new FdfsException("receive packet errno is: " + status));
}
long bodyLength = headerBuffer.getLong(0);
if (expectedBodyLength > 0 && bodyLength != expectedBodyLength) {
return Future.failedFuture(new FdfsException("receive packet body length: " + bodyLength
+ " is not equal to the expected: " + expectedBodyLength));
}
return Future.succeededFuture(bodyLength);
}
示例4: 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;
}
示例5: parseStorage
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
private Future<FdfsStorageOptions> parseStorage(Buffer bodyBuffer, String charset, boolean hasPathIndex) {
try {
FdfsStorageOptions storageOptions = new FdfsStorageOptions(options);
String group = FdfsUtils
.fdfsTrim(bodyBuffer.getString(0, FdfsProtocol.FDFS_GROUP_NAME_MAX_LEN, options.getCharset()));
String ip = FdfsUtils.fdfsTrim(bodyBuffer.getString(FdfsProtocol.FDFS_GROUP_NAME_MAX_LEN,
FdfsProtocol.FDFS_GROUP_NAME_MAX_LEN + FdfsProtocol.FDFS_IPADDR_SIZE - 1, options.getCharset()));
long port = bodyBuffer.getLong(FdfsProtocol.FDFS_GROUP_NAME_MAX_LEN + FdfsProtocol.FDFS_IPADDR_SIZE - 1);
storageOptions.setGroup(group).setAddress(SocketAddress.inetSocketAddress((int) port, ip));
if (hasPathIndex && bodyBuffer.length() > FdfsProtocol.TRACKER_QUERY_STORAGE_FETCH_BODY_LEN) {
byte storePathIndex = bodyBuffer.getByte(FdfsProtocol.TRACKER_QUERY_STORAGE_FETCH_BODY_LEN);
storageOptions.setStorePathIndex(storePathIndex);
}
return Future.succeededFuture(storageOptions);
} catch (Exception e) {
return Future.failedFuture(e);
}
}
示例6: decodeResponse
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
default Object decodeResponse(Buffer buffer, JavaType type) throws Exception {
if (buffer.length() == 0) {
return null;
}
try (BufferInputStream input = new BufferInputStream(buffer.getByteBuf())) {
return doDecodeResponse(input, type);
}
}
示例7: packFileId
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
/**
* 封装只有fileId的包,下载和删除时使用。
*
* @param command command
* @param fileId fileId
* @param charset charset
* @return the packet buffer
*/
public static Buffer packFileId(byte command, FdfsFileId fileId, String charset) {
Buffer groupBuffer = Buffer.buffer(fileId.group(), charset);
Buffer nameBuffer = Buffer.buffer(fileId.name(), charset);
int bodyLength = FDFS_GROUP_NAME_MAX_LEN + nameBuffer.length();
Buffer headerBuffer = packHeader(command, (byte) 0, bodyLength);
Buffer bodyBuffer = FdfsUtils.newZero(bodyLength);
bodyBuffer.setBuffer(0, groupBuffer);
bodyBuffer.setBuffer(FDFS_GROUP_NAME_MAX_LEN, nameBuffer);
return headerBuffer.appendBuffer(bodyBuffer);
}
示例8: uploadFile
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
private Future<FdfsFileId> uploadFile(byte command, String fileFullPathName, String ext) {
Buffer extBuffer = Buffer.buffer(ext, options.getCharset());
if (extBuffer.length() > FdfsProtocol.FDFS_FILE_EXT_NAME_MAX_LEN) {
return Future.failedFuture("ext is too long ( greater than " + FdfsProtocol.FDFS_FILE_EXT_NAME_MAX_LEN + ")");
}
Future<FdfsFileId> futureFileId = Future.future();
LocalFile.readFile(vertx.fileSystem(), fileFullPathName).setHandler(ar -> {
if (ar.succeeded()) {
LocalFile localFile = ar.result();
uploadFile(command, localFile.getFile(), localFile.getSize(), ext).setHandler(upload -> {
localFile.closeFile();
if (upload.succeeded()) {
futureFileId.complete(upload.result());
} else {
futureFileId.fail(upload.cause());
}
});
} else {
futureFileId.fail(ar.cause());
}
});
return futureFileId;
}
示例9: normalizeLineEndingsFor
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
protected static Buffer normalizeLineEndingsFor(final Buffer buff) {
final int buffLen = buff.length();
final Buffer normalized = Buffer.buffer(buffLen);
for (int i = 0; i < buffLen; i++) {
final short unsignedByte = buff.getUnsignedByte(i);
if (unsignedByte != '\r' || i + 1 == buffLen || buff.getUnsignedByte(i + 1) != '\n') {
normalized.appendUnsignedByte(unsignedByte);
}
}
return normalized;
}
示例10: onReceive
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
private void onReceive(Buffer buffer)
{
if (bufferSize - size - buffer.length() >= 0) {
buffer.getBytes(recvBuffer, size);
} else {
int newSize = bufferSize * (int) Math.ceil((size + buffer.length()) * 1.f / bufferSize);
byte[] newBuffer = new byte[newSize];
System.arraycopy(recvBuffer, 0, newBuffer, 0, size);
buffer.getBytes(newBuffer, size);
recvBuffer = newBuffer;
}
size += buffer.length();
expandPending();
}
示例11: handle
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
public void handle(HttpServerRequest clientRequest, HttpServerResponse clientResponse,
HttpResponse<Buffer> appResponse) {
int statusCode = appResponse.statusCode();
clientResponse.setStatusCode(statusCode);
// clientResponse.setStatusMessage(appResponse.statusMessage());
// System.out.println(appResponse.statusMessage());
MultiMap appHeaders = appResponse.headers();
appHeaders.forEach(entry -> {
String k = entry.getKey();
String v = entry.getValue();
// System.out.println("Header Response:[" + k + "]=" + v);
if ("Location".equalsIgnoreCase(k) && S.isNotBlank(v)) {
String schemal = clientRequest.scheme();
String host = clientRequest.host();
clientResponse.putHeader("Location", v.replaceAll(HTTP_SCHEMAL_HOST_REG, schemal + "://" + host + "/"));
} else
clientResponse.putHeader(k, v);
});
clientResponse.setChunked(true);
Buffer buff = appResponse.bodyAsBuffer();
if (buff != null && buff.length() > 0)
clientResponse.write(buff);
}
示例12: populate
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
public void populate(final Buffer buffer) {
queue.add(buffer);
availableBytes += buffer.length();
}