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