Here you can find the source of fillHlaBuffer(ByteBuffer buf)
public static ByteBuffer fillHlaBuffer(ByteBuffer buf)
//package com.java2s; //License from project: Apache License import java.nio.ByteBuffer; public class Main { public static final int MAX_BUFFER_SIZE = 150; public static final boolean hlaOk = true; public static final int hlaValue = 66; public static final String hlaName = "Command"; public static ByteBuffer fillHlaBuffer(ByteBuffer buf) { // Actually, format of SUPPORTED_CLASS topic is: // a boolean (ok) // an int (value) // a String (name) String name = hlaName;/*w ww . j a v a 2s .co m*/ // Check size of message. Must be less than the MAX_BUFFER_SIZE int messageLength = 1 + 4 + 4 + 2 * name.length(); if (messageLength > MAX_BUFFER_SIZE) { int extraMessageLength = messageLength - MAX_BUFFER_SIZE; // Remove extra length / 2 char from the name variable name = name.substring(0, name.length() - (extraMessageLength / 2)); } // Rewind the buffer buf.rewind(); // Put every value into the buffer // A boolean buf.put((byte) (hlaOk ? 1 : 0)); // An integer buf.putInt(hlaValue); // A String. 1/ size of the string, 2/ array of char buf.putInt(name.length()); for (int i = 0; i < name.length(); i++) { buf.putChar(name.charAt(i)); } buf.rewind(); //Don't forget to rewind the buffer. The interface processor won't do it... return buf; } }