Example usage for java.nio ByteBuffer wrap

List of usage examples for java.nio ByteBuffer wrap

Introduction

In this page you can find the example usage for java.nio ByteBuffer wrap.

Prototype

public static ByteBuffer wrap(byte[] array) 

Source Link

Document

Creates a new byte buffer by wrapping the given byte array.

Usage

From source file:haxball.util.Serializer.java

public static int byteArrayToInt(@NonNull byte data[]) {
    return ByteBuffer.wrap(data).getInt();
}

From source file:Main.java

public static ByteBuffer wrap(final String s) {
    return ByteBuffer.wrap(EncodingUtils.getAsciiBytes(s));
}

From source file:net.kazyx.wirespider.TestUtil.java

public static ByteBuffer asByteBuffer(String data) {
    try {/* ww  w. j a  va  2s  . c  om*/
        return ByteBuffer.wrap(data.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new UnsupportedOperationException(e);
    }
}

From source file:info.gehrels.flockDBClient.ByteHelper.java

static ByteBuffer asByteBuffer(long... destinationIds) {
    ByteBuffer buf = null;/*from  w w  w  .j  a  v  a2  s .  c  om*/
    buf = ByteBuffer.wrap(new byte[destinationIds.length * (Long.SIZE / 8)]);
    buf.order(ByteOrder.LITTLE_ENDIAN);
    for (long destinationId : destinationIds) {
        buf.putLong(destinationId);
    }
    buf.rewind();
    return buf;
}

From source file:net.sf.jml.util.DigestUtils.java

public static String md5(String s) {
    byte[] result = md5(s.getBytes());
    return NumberUtils.toHexValue(ByteBuffer.wrap(result));
}

From source file:io.reactivesocket.FramePerf.java

public static Frame utf8EncodedFrame(final int streamId, final FrameType type, final String data) {
    final byte[] bytes = data.getBytes();
    final ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
    final Payload payload = new Payload() {
        public ByteBuffer getData() {
            return byteBuffer;
        }//from   www.  j  a  v a  2 s .  co  m

        public ByteBuffer getMetadata() {
            return Frame.NULL_BYTEBUFFER;
        }
    };

    return Frame.Response.from(streamId, type, payload);
}

From source file:Main.java

public static boolean processReadySet(Set readySet) throws Exception {
    Iterator iterator = readySet.iterator();
    while (iterator.hasNext()) {
        SelectionKey key = (SelectionKey) iterator.next();
        iterator.remove();//from   w  w w.  j av  a 2 s. c o  m
        if (key.isConnectable()) {
            boolean connected = processConnect(key);
            if (!connected) {
                return true; // Exit
            }
        }
        if (key.isReadable()) {
            String msg = processRead(key);
            System.out.println("[Server]: " + msg);
        }
        if (key.isWritable()) {
            System.out.print("Please enter a message(Bye to quit):");
            String msg = userInputReader.readLine();

            if (msg.equalsIgnoreCase("bye")) {
                return true; // Exit
            }
            SocketChannel sChannel = (SocketChannel) key.channel();
            ByteBuffer buffer = ByteBuffer.wrap(msg.getBytes());
            sChannel.write(buffer);
        }
    }
    return false; // Not done yet
}

From source file:com.scf.utils.UUIDUtilies.java

public static String decodeBase64Uuid(String compressedUuid) {

    byte[] byUuid = Base64.decodeBase64(compressedUuid);

    ByteBuffer bb = ByteBuffer.wrap(byUuid);
    UUID uuid = new UUID(bb.getLong(), bb.getLong());
    return uuid.toString();
}

From source file:com.strategicgains.docussandra.ParseUtils.java

/**
 * Converts a base64 encoded string to a ByteBuffer.
 *
 * @param in Base64 encoded string./*from w  w  w.ja va 2  s .  c  om*/
 * @return A ByteBuffer containing the decoded string.
 */
public static ByteBuffer parseBase64StringAsByteBuffer(String in) {
    return ByteBuffer.wrap(Base64.decodeBase64(in.getBytes()));
}

From source file:com.hengyi.japp.tools.UuidUtils.java

protected static String base58Uuid(UUID uuid) {
    ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
    bb.putLong(uuid.getMostSignificantBits());
    bb.putLong(uuid.getLeastSignificantBits());
    return Base58.encode(bb.array());
}