]> git.basschouten.com Git - openhab-addons.git/blob
026a5223e2391a10071a4aae9fed20a213325b48
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.lametrictime.internal.api.impl;
14
15 import java.net.URI;
16
17 import javax.ws.rs.client.Client;
18 import javax.ws.rs.client.ClientBuilder;
19 import javax.ws.rs.core.Response;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22
23 /**
24  * Implementation class for http icons.
25  *
26  * @author Gregory Moyer - Initial contribution
27  */
28 @NonNullByDefault
29 public class HTTPIcon extends AbstractDataIcon {
30     private final URI uri;
31
32     public HTTPIcon(String uri) {
33         this(URI.create(uri));
34     }
35
36     public HTTPIcon(URI uri) {
37         this.uri = uri;
38     }
39
40     @Override
41     protected void populateFields() {
42         Client client = ClientBuilder.newBuilder().build();
43         Response response = client.target(uri).request().get();
44
45         setType(response.getMediaType().toString());
46         setData(response.readEntity(byte[].class));
47     }
48 }