本文整理汇总了Java中org.vertx.java.core.buffer.Buffer类的典型用法代码示例。如果您正苦于以下问题:Java Buffer类的具体用法?Java Buffer怎么用?Java Buffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Buffer类属于org.vertx.java.core.buffer包,在下文中一共展示了Buffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.vertx.java.core.buffer.Buffer; //导入依赖的package包/类
public static void main(String[] args) {
// Configure the client.
String adCode3rd = "/?advideo/3.0/78.109/5798044/0//cc=2;vidAS=pre_roll;vidRT=VAST;vidRTV=2.0.1";
HttpClient httpClient = VertxFactory.newVertx().createHttpClient();
httpClient.setHost("adserver.adtech.de");
httpClient.get(adCode3rd, new Handler<HttpClientResponse>() {
@Override
public void handle(HttpClientResponse httpClientResponse) {
httpClientResponse.bodyHandler(new Handler<Buffer>() {
@Override
public void handle(Buffer buffer) {
System.out.println("Response (" + buffer.length() + "): ");
System.out.println(buffer.getString(0, buffer.length()));
}
});
}
});
Utils.sleep(10000);
}
示例2: read_binary_body
import org.vertx.java.core.buffer.Buffer; //导入依赖的package包/类
private Action<StompFrame> read_binary_body(final StompFrame frame, final int contentLength) {
return new Action<StompFrame>() {
public StompFrame apply() throws IOException {
Buffer content = readBytes(contentLength + 1);
if (content != null) {
if (content.getByte(contentLength) != 0) {
throw new IOException("Expected null terminator after " + contentLength + " content bytes");
}
frame.content(chomp(content));
nextDecodeAction = read_action;
return frame;
} else {
return null;
}
}
};
}
示例3: 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();
}
示例4: 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.
}
}
示例5: handle
import org.vertx.java.core.buffer.Buffer; //导入依赖的package包/类
@Override
public void handle(Buffer event) {
if( error==null ) {
if( buff == null ) {
buff = event;
} else {
buff.appendBuffer(event);
}
try {
T rc = read();
while( rc !=null ) {
codecHander.handle(rc);
rc = read();
}
} catch (Exception e) {
if (LOG.isDebugEnabled()) LOG.debug("Protocol decoding failure: "+e, e);
error = e.getMessage();
errorHandler.handle(error);
}
}
}
示例6: 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;
}
}
示例7: init
import org.vertx.java.core.buffer.Buffer; //导入依赖的package包/类
private void init() {
this.next.readStream().dataHandler(new Handler<Buffer>() {
@Override
public void handle(Buffer buffer) {
if( encryptedReadBuffer == null ) {
encryptedReadBuffer = buffer;
} else {
encryptedReadBuffer.appendBuffer(buffer);
}
encryptedReadBufferUnderflow = false;
pumpReads();
}
});
this.next.readStream().endHandler(new Handler<Void>() {
@Override
public void handle(Void x) {
encryptedReadEOF = true;
}
});
this.next.readStream().exceptionHandler(new Handler<Throwable>() {
@Override
public void handle(Throwable error) {
onFailure(error);
}
});
}
示例8: equals
import org.vertx.java.core.buffer.Buffer; //导入依赖的package包/类
@Override
public boolean equals(Object obj) {
if (obj == this)
return true;
if (obj == null)
return false;
Class clazz = obj.getClass();
if( clazz==Ascii.class ) {
return obj.toString().equals(toString());
}
if( clazz==String.class ) {
return obj.equals(toString());
}
if( clazz==Buffer.class ) {
return obj.equals(toBuffer());
}
return false;
}
示例9: apply
import org.vertx.java.core.buffer.Buffer; //导入依赖的package包/类
public Command apply() throws IOException {
Buffer header = peekBytes(4);
if( header==null ) {
return null;
} else {
final int length = header.getInt(0);
if( length > protocol.maxFrameSize ) {
throw new ProtocolException("Max frame size exceeded.");
}
nextDecodeAction = new Action<Command>() {
public Command apply() throws IOException {
Buffer frame = readBytes(4+length) ;
if( frame==null ) {
return null;
} else {
// TODO: avoid this conversion.
org.fusesource.hawtbuf.Buffer buffer = new org.fusesource.hawtbuf.Buffer(frame.getBytes());
Command command = (Command) format.unmarshal(buffer);
nextDecodeAction = read_action;
return command;
}
}
};
return nextDecodeAction.apply();
}
}
示例10: apply
import org.vertx.java.core.buffer.Buffer; //导入依赖的package包/类
public AmqpEvent apply() throws IOException {
Buffer sizeBytes = peekBytes(4);
if (sizeBytes != null) {
int size = sizeBytes.getInt(0);
if (size < 8) {
throw new IOException(String.format("specified frame size %d is smaller than minimum frame size", size));
}
if( size > protocol.maxFrameSize ) {
throw new IOException(String.format("specified frame size %d is larger than maximum frame size", size));
}
nextDecodeAction = readFrame(size);
return nextDecodeAction.apply();
} else {
return null;
}
}
示例11: 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()]);
}
示例12: 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;
}
}
示例13: 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;
}
示例14: testHostIdentification
import org.vertx.java.core.buffer.Buffer; //导入依赖的package包/类
@Test
public void testHostIdentification() {
final GeneratedMessage protobufMessage = Messages.HostIdentification.getDefaultInstance();
final AggregationMessage message = AggregationMessage.create(protobufMessage);
Assert.assertNotNull(message);
Assert.assertSame(protobufMessage, message.getMessage());
final Buffer vertxBuffer = message.serialize();
final byte[] messageBuffer = vertxBuffer.getBytes();
final byte[] protobufBuffer = protobufMessage.toByteArray();
ByteString.fromArray(vertxBuffer.getBytes());
// Assert length
Assert.assertEquals(protobufBuffer.length + 5, messageBuffer.length);
Assert.assertEquals(protobufBuffer.length + 5, vertxBuffer.getInt(0));
Assert.assertEquals(protobufBuffer.length + 5, message.getLength());
// Assert payload type
Assert.assertEquals(1, messageBuffer[4]);
// Assert the payload was not corrupted
for (int i = 0; i < protobufBuffer.length; ++i) {
Assert.assertEquals(protobufBuffer[i], messageBuffer[i + 5]);
}
}
示例15: doRequest
import org.vertx.java.core.buffer.Buffer; //导入依赖的package包/类
@Override
protected void doRequest(final HttpClient client) {
// Build post URI
StringBuilder postUri = new StringBuilder(m_query);
postUri.append(API_KEY_TOKEN);
postUri.append(m_token);
m_logger.trace("Executing post: {} (host: {})",
postUri, getConnection().getAddress());
HttpClientRequest request = doPost(postUri.toString(), m_responseHandler);
m_logger.trace("Posting data: {}", m_data);
byte[] body;
if (m_data.isObject()) {
body = ((JsonObject) m_data).encode().getBytes();
} else {
body = ((JsonArray) m_data).encode().getBytes();
}
request.putHeader(CONTENT_TYPE, "application/json");
request.putHeader(CONTENT_LENGTH, String.valueOf(body.length));
request.exceptionHandler(new DefaultConnectionExceptionHandler(
getConnection()));
request.write(new Buffer(body));
request.end();
}