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.binding.lametrictime.internal.api.impl;
16 import java.io.IOException;
17 import java.nio.file.Files;
18 import java.nio.file.Path;
20 import javax.activation.MimetypesFileTypeMap;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * Implementation class for file icons.
29 * @author Gregory Moyer - Initial contribution
32 public class FileIcon extends AbstractDataIcon {
33 private final Logger logger = LoggerFactory.getLogger(FileIcon.class);
35 private final MimetypesFileTypeMap mimeTypeMap = new MimetypesFileTypeMap();
37 private final Path path;
39 public FileIcon(File file) {
43 public FileIcon(Path path) {
45 mimeTypeMap.addMimeTypes("image/png png PNG");
49 protected void populateFields() {
50 setType(mimeTypeMap.getContentType(path.toFile()));
52 setData(Files.readAllBytes(path));
53 } catch (IOException e) {
54 logger.warn("Failed reading icon content.", e);