2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.vid.asdc.beans.tosca;
\r
23 import java.io.BufferedReader;
\r
24 import java.io.IOException;
\r
25 import java.io.InputStream;
\r
26 import java.io.InputStreamReader;
\r
27 import java.util.HashMap;
\r
28 import java.util.Map;
\r
30 import org.openecomp.vid.asdc.AsdcCatalogException;
\r
33 * The Class ToscaMeta.
\r
35 public class ToscaMeta {
\r
37 /** The metadata. */
\r
38 private final Map<String, String> metadata;
\r
41 * Instantiates a new tosca meta.
\r
43 * @param builder the builder
\r
44 * @throws IOException Signals that an I/O exception has occurred.
\r
45 * @throws AsdcCatalogException the asdc catalog exception
\r
47 private ToscaMeta(Builder builder) throws IOException, AsdcCatalogException {
\r
48 metadata = new HashMap<String, String> ();
\r
50 read(builder.inputStream);
\r
54 * The Class Builder.
\r
56 public static class Builder {
\r
58 /** The input stream. */
\r
59 private final InputStream inputStream;
\r
62 * Instantiates a new builder.
\r
64 * @param inputStream the input stream
\r
66 public Builder(InputStream inputStream) {
\r
67 this.inputStream = inputStream;
\r
73 * @return the tosca meta
\r
74 * @throws IOException Signals that an I/O exception has occurred.
\r
75 * @throws AsdcCatalogException the asdc catalog exception
\r
77 public ToscaMeta build() throws IOException, AsdcCatalogException {
\r
78 return new ToscaMeta(this);
\r
85 * @param property the property
\r
86 * @return the string
\r
88 public String get(String property) {
\r
89 return metadata.get(property);
\r
95 * @param inputStream the input stream
\r
96 * @throws IOException Signals that an I/O exception has occurred.
\r
97 * @throws AsdcCatalogException the asdc catalog exception
\r
99 private void read(InputStream inputStream) throws IOException, AsdcCatalogException {
\r
101 final BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
\r
106 while ((line = br.readLine()) != null) {
\r
107 if ( line.length() > 0 ) {
\r
108 final String[] entry = line.split(":");
\r
110 if (entry.length != 2) throw new AsdcCatalogException("TOSCA.meta file cannot be parsed (more than 1 colon found on a single line");
\r
111 if (!entry[1].startsWith(" ")) throw new AsdcCatalogException("TOSCA.meta file cannot be parsed (: not immediately followed by ' ')");
\r
113 metadata.put(entry[0], entry[1].substring(1));
\r
116 } catch (IOException e) {
\r
119 } catch (AsdcCatalogException e) {
\r