Package org.openhab.core.io.bin2json
Class Bin2Json
java.lang.Object
org.openhab.core.io.bin2json.Bin2Json
This class converts binary data to JSON format.
Parser rules follows Java Binary Block Parser syntax.
See details from https://github.com/raydac/java-binary-block-parser
Usage example:
JsonObject json = new Bin2Json("byte a; byte b; ubyte c;").convert("03FAFF");
json.toString() = {"a":3,"b":-6,"c":255}
- Author:
- Pauli Anttila - Initial contribution
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncom.google.gson.JsonObject
convert
(byte[] data) Convert byte array to JSON object.com.google.gson.JsonObject
convert
(InputStream inputStream) Convert data fromInputStream
to JSON object.com.google.gson.JsonObject
ConvertString
in hexadecimal string format to JSON object.
-
Constructor Details
-
Bin2Json
Constructor.- Parameters:
parserRule
- Binary data parser rule.- Throws:
ConversionException
- if parse rule parsing fails.
-
-
Method Details
-
convert
ConvertString
in hexadecimal string format to JSON object.- Parameters:
hexString
- Data in hexadecimal string format. Example data: 03FAFF.- Returns:
- Gson
JsonObject
. - Throws:
ConversionException
- if an error occurs during conversion.
-
convert
Convert byte array to JSON object.- Parameters:
data
- Data in byte array format.- Returns:
- Gson
JsonObject
. - Throws:
ConversionException
- if an error occurs during conversion.
-
convert
Convert data fromInputStream
to JSON object.- Parameters:
inputStream
- input stream where converted data is read.- Returns:
- Gson
JsonObject
. - Throws:
ConversionException
- if an error occurs during conversion.
-