]> git.basschouten.com Git - openhab-addons.git/blob
5a0b8e6453b25bc71da11afcd4b38b3b91fe5797
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.mpd.internal.protocol;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19
20 /**
21  * Class for parsing a response from a Music Player Daemon.
22  *
23  * @author Stefan Röllin - Initial contribution
24  */
25 @NonNullByDefault
26 public class MPDResponseParser {
27
28     static Map<String, String> responseToMap(MPDResponse response) {
29         Map<String, String> map = new HashMap<String, String>();
30
31         for (String line : response.getLines()) {
32             int offset = line.indexOf(':');
33             if (offset >= 0) {
34                 String key = line.substring(0, offset);
35                 String value = line.substring(offset + 1).trim();
36
37                 map.put(key, value);
38             }
39         }
40
41         return map;
42     }
43 }