本文整理汇总了Java中org.vertx.java.core.buffer.Buffer.appendByte方法的典型用法代码示例。如果您正苦于以下问题:Java Buffer.appendByte方法的具体用法?Java Buffer.appendByte怎么用?Java Buffer.appendByte使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.vertx.java.core.buffer.Buffer
的用法示例。
在下文中一共展示了Buffer.appendByte方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: encodeHeader
import org.vertx.java.core.buffer.Buffer; //导入方法依赖的package包/类
public static Ascii encodeHeader(String value) {
if (value == null)
return null;
try {
byte[] data = value.getBytes("UTF-8");
Buffer rc = new Buffer(data.length);
for (byte d : data) {
switch (d) {
case ESCAPE_BYTE:
rc.appendBuffer(ESCAPE_ESCAPE_SEQ.toBuffer());
break;
case COLON_BYTE:
rc.appendBuffer(COLON_ESCAPE_SEQ.toBuffer());
break;
case NEWLINE_BYTE:
rc.appendBuffer(COLON_ESCAPE_SEQ.toBuffer());
break;
default:
rc.appendByte(d);
}
}
return ascii(rc);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e); // not expected.
}
}
示例3: serialize
import org.vertx.java.core.buffer.Buffer; //导入方法依赖的package包/类
/**
* Serialize the message into a <code>Buffer</code>.
*
* @return <code>Buffer</code> containing serialized message.
*/
public Buffer serialize() {
final Buffer b = new Buffer();
b.appendInt(0);
if (_message instanceof Messages.HostIdentification) {
b.appendByte((byte) 0x01);
} else if (_message instanceof Messages.HeartbeatRecord) {
b.appendByte((byte) 0x03);
} else if (_message instanceof Messages.StatisticSetRecord) {
b.appendByte((byte) 0x04);
} else if (_message instanceof Messages.SamplesSupportingData) {
b.appendByte((byte) 0x05);
b.appendByte((byte) 0x01);
} else if (_message instanceof Messages.SparseHistogramSupportingData) {
b.appendByte((byte) 0x05);
b.appendByte((byte) 0x02);
} else {
throw new IllegalArgumentException(String.format("Unsupported message; message=%s", _message));
}
b.appendBytes(_message.toByteArray());
b.setInt(0, b.length());
return b;
}
示例4: 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"));
}
示例5: encode
import org.vertx.java.core.buffer.Buffer; //导入方法依赖的package包/类
static public Buffer encode(String value) {
int size = value.length();
Buffer rc = new Buffer(size);
for (int i = 0; i < size; i++) {
rc.appendByte((byte) (value.charAt(i) & 0xFF));
}
return rc;
}
示例6: toBuffer
import org.vertx.java.core.buffer.Buffer; //导入方法依赖的package包/类
public static Buffer toBuffer(ByteBuffer buff) {
Buffer self = new Buffer(buff.remaining());
while( buff.hasRemaining() ) {
self.appendByte(buff.get());
}
return self;
}
示例7: test
import org.vertx.java.core.buffer.Buffer; //导入方法依赖的package包/类
@Test
public void test() {
Buffer msg = new Buffer();
msg.appendByte((byte)'R');
msg.appendInt(8);
msg.appendInt(3);
AuthenticationRequest ar = new AuthenticationRequest();
ar.setBuffer(msg);
assertTrue(ar.isAuthenticationSupported());
assertTrue(ar.needCleartextPassword());
msg.setInt(5, 0);
ar = new AuthenticationRequest();
ar.setBuffer(msg);
assertTrue(ar.isAuthenticationOk());
msg.setInt(1, 12);
msg.setInt(5, 5);
byte[] salt = { 1,2,3,4 };
msg.appendBytes(salt);
ar = new AuthenticationRequest();
ar.setBuffer(msg);
assertTrue(ar.isAuthenticationSupported());
assertTrue(ar.needMD5Password());
assertTrue(Arrays.equals(salt, ar.salt()));
}
示例8: createDataRowBuffer
import org.vertx.java.core.buffer.Buffer; //导入方法依赖的package包/类
/** Example result with 3 columns: string, int, null
* @throws IOException */
public static Buffer createDataRowBuffer() throws IOException {
Buffer b = new Buffer();
b.appendByte((byte)'D');
int start = b.length();
b.appendInt(0);
b.appendShort((short)3);
byte[] s = "bubu".getBytes("UTF-8");
b.appendInt(s.length);
b.appendBytes(s);
b.appendInt(4);
b.appendInt(42);
b.appendInt(-1);
return b;
}