Example usage for java.nio ByteBuffer toString

List of usage examples for java.nio ByteBuffer toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a string representing the state of this byte buffer.

Usage

From source file:org.openhab.binding.irtrans.internal.IRtransBinding.java

/**
 * Main method to parse ASCII string received from the IR Transceiver.
 * //w  w w .j a  v  a2s  . co  m
 * @param qualifiedItems
 *            the qualified items, e.g. only those items that have the host:port combination
 *            in its binding configuration string will "receive" the ASCII string from the 
 *            IRTrans device with host:port 
 * @param byteBuffer
 *            the byte buffer
 */
@Override
protected void parseBuffer(String itemName, Command aCommand, Direction theDirection, ByteBuffer byteBuffer) {

    String message = stripByteCount(byteBuffer);

    if (message != null) {

        // IRTrans devices return "RESULT OK" when it succeeds to emit an infrared sequence
        if (message.contains("RESULT OK")) {
            parseOKMessage(itemName, message);
        }

        // IRTrans devices return a string starting with RCV_HEX each time it captures an
        // infrared sequence from a remote control
        if (message.contains("RCV_HEX")) {
            parseHexMessage(itemName, message, aCommand);
        }

        // IRTrans devices return a string starting with RCV_COM each time it captures an
        // infrared sequence from a remote control that is stored in the device's internal dB
        if (message.contains("RCV_COM")) {
            parseIRDBMessage(itemName, message, aCommand);
        }
    } else {
        logger.warn("Received some non-compliant garbage ({})- Parsing is skipped", byteBuffer.toString());
    }

}