當前位置: 首頁>>代碼示例>>Java>>正文


Java Buffer類代碼示例

本文整理匯總了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);
}
 
開發者ID:rfxlab,項目名稱:analytics-with-rfx,代碼行數:21,代碼來源:NettyHttpClient.java

示例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;
            }
        }
    };
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:18,代碼來源:StompProtocolDecoder.java

示例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();
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:25,代碼來源:StompFrame.java

示例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.
    }
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:27,代碼來源:StompFrame.java

示例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);
        }
    }
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:22,代碼來源:ProtocolDecoder.java

示例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;
    }
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:27,代碼來源:SslProtocol.java

示例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);
        }
    });
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:27,代碼來源:SslSocketWrapper.java

示例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;
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:20,代碼來源:Ascii.java

示例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();
    }
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:27,代碼來源:OpenwireProtocolDecoder.java

示例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;
    }
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:17,代碼來源:AmqpProtocolDecoder.java

示例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()]);
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:20,代碼來源:BufferSupport.java

示例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;
    }
}
 
開發者ID:ArpNetworking,項目名稱:metrics-aggregator-daemon,代碼行數:26,代碼來源:VertxSink.java

示例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;
}
 
開發者ID:ArpNetworking,項目名稱:metrics-aggregator-daemon,代碼行數:28,代碼來源:AggregationMessage.java

示例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]);
    }
}
 
開發者ID:ArpNetworking,項目名稱:metrics-aggregator-daemon,代碼行數:26,代碼來源:AggregationMessageTest.java

示例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();
}
 
開發者ID:clidev,項目名稱:spike.x,代碼行數:27,代碼來源:Ubidots.java


注:本文中的org.vertx.java.core.buffer.Buffer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。