本文整理汇总了Java中org.vertx.java.core.buffer.Buffer.length方法的典型用法代码示例。如果您正苦于以下问题:Java Buffer.length方法的具体用法?Java Buffer.length怎么用?Java Buffer.length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.vertx.java.core.buffer.Buffer
的用法示例。
在下文中一共展示了Buffer.length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decodeHeader
import org.vertx.java.core.buffer.Buffer; //导入方法依赖的package包/类
public static String decodeHeader(Buffer value) {
if (value == null)
return null;
Buffer rc = new Buffer(value.length());
int pos = 0;
int max = value.length();
while (pos < max) {
if (startsWith(value, pos, ESCAPE_ESCAPE_SEQ.toBuffer())) {
rc.appendByte(ESCAPE_BYTE);
pos += 2;
} else if (startsWith(value, pos, COLON_ESCAPE_SEQ.toBuffer())) {
rc.appendByte(COLON_BYTE);
pos += 2;
} else if (startsWith(value, pos, NEWLINE_ESCAPE_SEQ.toBuffer())) {
rc.appendByte(NEWLINE_BYTE);
pos += 2;
} else {
rc.appendByte(value.getByte(pos));
pos += 1;
}
}
return rc.toString();
}
示例2: matches
import org.vertx.java.core.buffer.Buffer; //导入方法依赖的package包/类
@Override
public boolean matches(Buffer buffer) {
if( buffer.length() >= 6 ) {
if( buffer.getByte(0) == 0x16 ) { // content type
return (buffer.getByte(5) == 1) && // Client Hello
( (buffer.getByte(1) == 2) // SSLv2
|| (
buffer.getByte(1)== 3 &&
isSSLVerions(buffer.getByte(2))
)
);
} else {
// We have variable header offset..
return ((buffer.getByte(0) & 0xC0) == 0x80) && // The rest of byte 0 and 1 are holds the record length.
(buffer.getByte(2) == 1) && // Client Hello
( (buffer.getByte(3) == 2) // SSLv2
|| (
(buffer.getByte(3) == 3) && // SSLv3 or TLS
isSSLVerions(buffer.getByte(4))
)
);
}
} else {
return false;
}
}
示例3: split
import org.vertx.java.core.buffer.Buffer; //导入方法依赖的package包/类
static final public Buffer[] split(Buffer self, byte separator) {
ArrayList<Buffer> rc = new ArrayList<Buffer>();
int pos = 0;
int nextStart = pos;
int end = self.length();
while( pos < end ) {
if( self.getByte(pos)==separator ) {
if( nextStart < pos ) {
rc.add(self.getBuffer(nextStart, pos));
}
nextStart = pos+1;
}
pos++;
}
if( nextStart < pos ) {
rc.add(self.getBuffer(nextStart, pos));
}
return rc.toArray(new Buffer[rc.size()]);
}
示例4: flushBuffer
import org.vertx.java.core.buffer.Buffer; //导入方法依赖的package包/类
private int flushBuffer(final Buffer buffer, final NetSocket socket) {
// Write the serialized data
try {
final int bufferLength = buffer.length();
// TODO(vkoskela): Add conditional logging [AINT-552]
//LOGGER.trace(String.format("Writing buffer to socket; length=%s buffer=%s", bufferLength, buffer.toString("utf-8")));
LOGGER.debug()
.setMessage("Writing buffer to socket")
.addData("sink", getName())
.addData("length", bufferLength)
.log();
socket.write(buffer);
return bufferLength;
// CHECKSTYLE.OFF: IllegalCatch - Vertx might not log
} catch (final Exception e) {
// CHECKSTYLE.ON: IllegalCatch
LOGGER.error()
.setMessage("Error writing AggregatedData data to socket")
.addData("sink", getName())
.addData("buffer", buffer)
.setThrowable(e)
.log();
throw e;
}
}
示例5: PersistantBuffer
import org.vertx.java.core.buffer.Buffer; //导入方法依赖的package包/类
public PersistantBuffer(Vertx vertx, Buffer buffer, String id, String destination) {
this.buffer = buffer;
this.vertx = vertx;
this.filePath = destination + File.separator + PersistantBuffer.class.getSimpleName() + "-" + id;
this.length = buffer.length();
if (buffer.length() > persistanceThreshold) {
persist(new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> ar) {
if (ar.failed()) {
log.error("Error persisting buffer", ar.cause());
}
}
});
}
}
示例6: debugMessage
import org.vertx.java.core.buffer.Buffer; //导入方法依赖的package包/类
private String debugMessage(Buffer buffer) {
StringBuilder sb = new StringBuilder();
sb.append("(" + (char) buffer.getByte(0) + ") ");
sb.append("#" + buffer.getInt(1) + ' ');
for (int i = 5, len = buffer.length(); i < len; i++) {
byte b = buffer.getByte(i);
if (b < 32) {
sb.append(Byte.toString(b) + " ");
} else if (b > 128) {
sb.append('?');
} else {
sb.append((char) b);
}
}
sb.append("\n Len:" + buffer.length() + "\n");
return sb.toString();
}
示例7: test
import org.vertx.java.core.buffer.Buffer; //导入方法依赖的package包/类
@Test
public void test() {
Buffer buffer = new Buffer();
buffer.appendByte((byte)'E');
int start = buffer.length();
buffer.appendInt(-1);
buffer.appendByte((byte)'S'); // Severity field type
buffer.appendString("ERROR").appendByte(EOS);
buffer.appendByte((byte)'M'); // human message
buffer.appendString("Unit testing is good for you").appendByte(EOS);
buffer.appendByte(EOS); // last field
buffer.setInt(start, buffer.length() - start); // set size
ErrorResponse err = new ErrorResponse();
err.setBuffer(buffer);
System.out.println(err.toString());
assertTrue(err.toString().contains("good"));
}
示例8: apply
import org.vertx.java.core.buffer.Buffer; //导入方法依赖的package包/类
public StompFrame apply() throws IOException {
Buffer line = readUntil((byte) '\n', StompProtocol.maxCommandLength, "The maximum command length was exceeded");
if (line != null) {
Buffer action = chomp(line);
if (trim) {
action = trim(action);
}
if (action.length() > 0) {
StompFrame frame = new StompFrame(Ascii.ascii(action));
nextDecodeAction = read_headers(frame);
return nextDecodeAction.apply();
}
}
return null;
}
示例9: decode
import org.vertx.java.core.buffer.Buffer; //导入方法依赖的package包/类
static public String decode(Buffer value) {
int size = value.length();
char rc[] = new char[size];
for (int i = 0; i < size; i++) {
rc[i] = (char) (value.getByte(i) & 0xFF);
}
return new String(rc);
}
示例10: matches
import org.vertx.java.core.buffer.Buffer; //导入方法依赖的package包/类
@Override
public boolean matches(Buffer header) {
if (header.length() < PROTOCOL_MAGIC.length()) {
return false;
} else {
return startsWith(header ,PROTOCOL_MAGIC);
}
}
示例11: trimFront
import org.vertx.java.core.buffer.Buffer; //导入方法依赖的package包/类
static public Buffer trimFront(Buffer self) {
int length = self.length();
int pos = 0;
while ((pos < length) && (self.getByte(pos) <= ' ')) {
pos++;
}
return (pos == 0) ? self : self.getBuffer(pos, length);
}
示例12: trimEnd
import org.vertx.java.core.buffer.Buffer; //导入方法依赖的package包/类
static public Buffer trimEnd(Buffer self) {
int length = self.length();
int pos = length;
while ( pos > 0 && (self.getByte(pos-1) <= ' ')) {
pos--;
}
return (pos == length-1) ? self : self.getBuffer(0, pos);
}
示例13: matches
import org.vertx.java.core.buffer.Buffer; //导入方法依赖的package包/类
static public boolean matches(Buffer self, int pos, Buffer needle) {
int needleLength = needle.length();
for (int i = 0; i < needleLength; i++) {
if( self.getByte(pos+i) != needle.getByte(i) ) {
return false;
}
}
return true;
}
示例14: matches
import org.vertx.java.core.buffer.Buffer; //导入方法依赖的package包/类
@Override
public boolean matches(Buffer header) {
if (header.length() < 10) {
return false;
} else {
return BufferSupport.startsWith(header, HEAD_MAGIC) && (
BufferSupport.indexOf(header, 2, MQTT31_TAIL_MAGIC)< 6
||
BufferSupport.indexOf(header, 2, MQTT311_TAIL_MAGIC) < 6
);
}
}
示例15: handle
import org.vertx.java.core.buffer.Buffer; //导入方法依赖的package包/类
@Override
public void handle(Buffer buffer) {
writeStream.write(env, env.wrapJava(buffer.toString()), null);
pumped += buffer.length();
if (writeStream.writeQueueFull(env).toBoolean()) {
readStream.pause(env);
writeStream.drainHandler(env, drainHandlerValue);
}
}