2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.transform.bin2json.internal;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.core.transform.TransformationException;
18 import org.openhab.core.transform.TransformationService;
19 import org.osgi.service.component.annotations.Component;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * The implementation of {@link TransformationService} which transforms the
25 * hexa string formatted binary data by Binary Block Parser syntax to JSON format.
27 * @author Pauli Anttila - Initial contribution
30 @Component(property = { "openhab.transform=BIN2JSON" })
31 public class Bin2JsonTransformationService implements TransformationService {
33 private Logger logger = LoggerFactory.getLogger(Bin2JsonTransformationService.class);
36 * Transforms the input <code>source</code> by Java Binary Block Parser syntax.
38 * @param syntax Java Binary Block Parser syntax.
39 * @param source the input to transform
42 public @Nullable String transform(String syntax, String source) throws TransformationException {
43 final long startTime = System.currentTimeMillis();
44 logger.debug("About to transform '{}' by the Bin2Json syntax '{}'", source, syntax);
49 result = String.valueOf(new Bin2Json(syntax).convert(source));
50 logger.debug("transformation resulted '{}'", result);
52 } catch (ConversionException e) {
53 throw new TransformationException("An error occurred while executing the converter. " + e.getMessage(), e);
55 logger.trace("Bin2Json execution elapsed {} ms. Result: {}", System.currentTimeMillis() - startTime,