Example usage for io.vertx.core.buffer Buffer getBytes

List of usage examples for io.vertx.core.buffer Buffer getBytes

Introduction

In this page you can find the example usage for io.vertx.core.buffer Buffer getBytes.

Prototype

@GenIgnore(GenIgnore.PERMITTED_TYPE)
@Fluent
Buffer getBytes(byte[] dst, int dstIndex);

Source Link

Document

Transfers the content of the Buffer into a byte[] at the specific destination.

Usage

From source file:co.runrightfast.vertx.core.eventbus.ProtobufMessageCodec.java

License:Apache License

@Override
public MSG decodeFromWire(final int pos, final Buffer buffer) {
    try {/*from w  w  w.ja v a2s  . c  om*/
        return (MSG) defaultInstance.getParserForType().parseFrom(buffer.getBytes(pos, buffer.length()));
    } catch (final InvalidProtocolBufferException ex) {
        throw new ApplicationException(ex);
    }
}

From source file:com.hubrick.vertx.s3.client.S3Client.java

License:Apache License

private static void logDebugResponse(Buffer buffer) {
    if (log.isDebugEnabled()) {
        if (buffer.length() > MAX_LOG_OUTPUT) {
            log.debug("Response: {}",
                    new String(buffer.getBytes(0, MAX_LOG_OUTPUT), Charsets.UTF_8) + "\nRest truncated......");
        } else {/*from  w  ww.j ava2  s  .c om*/
            log.debug("Response: {}", new String(buffer.getBytes(), Charsets.UTF_8));
        }
    }
}

From source file:com.hubrick.vertx.s3.client.S3Client.java

License:Apache License

private static void logInfoResponse(Buffer buffer) {
    if (log.isInfoEnabled()) {
        if (buffer.length() > MAX_LOG_OUTPUT) {
            log.info("Response: {}",
                    new String(buffer.getBytes(0, MAX_LOG_OUTPUT), Charsets.UTF_8) + "\nRest truncated......");
        } else {// w  ww.j  av  a  2 s  .c om
            log.info("Response: {}", new String(buffer.getBytes(), Charsets.UTF_8));
        }
    }
}

From source file:com.hubrick.vertx.s3.client.S3ClientRequest.java

License:Apache License

private void logBody(Buffer body) {
    if (log.isDebugEnabled()) {
        if (body.length() > MAX_LOG_OUTPUT) {
            log.debug("Request Body: {}",
                    new String(body.getBytes(0, MAX_LOG_OUTPUT), Charsets.UTF_8) + "\nRest truncated......");
        } else {//from   www . ja  v a2  s  .c om
            log.debug("Request Body: {}", new String(body.getBytes(), Charsets.UTF_8));
        }
    }
}

From source file:io.flowly.core.codecs.FlowInstanceCodec.java

License:Open Source License

@Override
public FlowInstance decodeFromWire(int pos, Buffer buffer) {
    // Same as decoding a JsonObject.
    int length = buffer.getInt(pos);
    pos += 4;//from  w  w  w.  j  a  va  2 s  . c o m
    byte[] encoded = buffer.getBytes(pos, pos + length);
    String str = new String(encoded, CharsetUtil.UTF_8);
    return new FlowInstance(str);
}

From source file:io.flowly.core.codecs.FlowMetadataCodec.java

License:Open Source License

@Override
public FlowMetadata decodeFromWire(int pos, Buffer buffer) {
    // Same as decoding a JsonObject.
    int length = buffer.getInt(pos);
    pos += 4;//ww  w . j a  v  a  2s . c o m
    byte[] encoded = buffer.getBytes(pos, pos + length);
    String str = new String(encoded, CharsetUtil.UTF_8);
    return new FlowMetadata(str);
}

From source file:microservicerx.dht.routing.SerializableCodec.java

@Override
public KLASS decodeFromWire(int position, Buffer buffer) {
    int _pos = position;
    // get length of byte[]
    int length = buffer.getInt(_pos);

    // Get JSON string by it`s length
    // Jump 4 because getInt() == 4 bytes
    byte[] data = buffer.getBytes(_pos += 4, _pos += length);

    return Serializer.deserialize(data);
}

From source file:org.pac4j.vertx.auth.Pac4jUser.java

License:Apache License

@Override
public int readFromBuffer(int pos, Buffer buffer) {
    pos = super.readFromBuffer(pos, buffer);
    final int jsonByteCount = buffer.getInt(pos);
    pos += 4;/*from w  w  w .  j  a  va2  s  .c o  m*/
    final byte[] jsonBytes = buffer.getBytes(pos, pos + jsonByteCount);
    pos += jsonByteCount;
    final String json = new String(jsonBytes, StandardCharsets.UTF_8);
    final UserProfile userProfile = (UserProfile) DefaultJsonConverter.getInstance().decodeObject(json);
    setUserProfile(userProfile);
    return pos;
}

From source file:org.sfs.io.Block.java

License:Apache License

public static Optional<Frame<byte[]>> decodeFrame(Buffer buffer, boolean validateChecksum) {
    int length = buffer.length();

    final byte[] frame;
    final byte[] expectedChecksum;
    try {//from   w  ww  .java 2  s  .  c om
        int frameSize = buffer.getInt(FRAME_LENGTH_OFFSET);
        Preconditions.checkArgument(frameSize >= 0 && frameSize < length, "Frame size was %s, expected 0 to %s",
                frameSize, length);
        frame = buffer.getBytes(FRAME_DATA_OFFSET, FRAME_DATA_OFFSET + frameSize);
        expectedChecksum = buffer.getBytes(FRAME_HASH_OFFSET, FRAME_HASH_OFFSET + FRAME_HASH_SIZE);
    } catch (Throwable e) {
        return Optional.absent();
    }

    Frame<byte[]> f = new Frame<byte[]>(expectedChecksum, frame) {

        @Override
        public boolean isChecksumValid() {
            return Arrays.equals(expectedChecksum, checksum(frame));
        }
    };

    if (validateChecksum) {
        if (!f.isChecksumValid()) {
            Preconditions.checkState(false, "Checksum was %s, expected %s",
                    BaseEncoding.base64().encode(checksum(frame)),
                    BaseEncoding.base64().encode(expectedChecksum));
        }
    }

    return Optional.of(f);
}