16a41d9adb65c5786039bc3d7cf4615cfcfcc2e8
[controller.git] / opendaylight / config / yang-test-plugin / src / main / java / org / opendaylight / controller / config / yang / test / plugin / Util.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.config.yang.test.plugin;
10
11 import java.io.BufferedReader;
12 import java.io.File;
13 import java.io.FileInputStream;
14 import java.io.IOException;
15 import java.io.InputStream;
16 import java.io.InputStreamReader;
17 import java.util.regex.Matcher;
18
19 public class Util {
20
21     public static String replaceDots(String path) {
22         path = path.replace(".", Matcher.quoteReplacement(File.separator));
23         return path;
24     }
25
26     public static String loadHeader() throws IOException {
27         StringBuffer header = new StringBuffer();
28         InputStream headIn = Util.class.getClassLoader().getResourceAsStream("Header.txt");
29         BufferedReader headBuf = new BufferedReader(new InputStreamReader(headIn));
30         String line = null;
31         while ((line = headBuf.readLine()) != null) {
32             header.append(line).append(System.lineSeparator());
33         }
34         headBuf.close();
35         return header.toString();
36     }
37
38     public static String loadStubFile(String fileName) throws IOException {
39         InputStream stubIn = new FileInputStream(fileName);
40         BufferedReader stubBuf = new BufferedReader(new InputStreamReader(stubIn));
41
42         StringBuffer stubLines = new StringBuffer();
43         String stubLine = null;
44         while ((stubLine = stubBuf.readLine()) != null) {
45             stubLines.append(stubLine).append(System.lineSeparator());
46         }
47         stubBuf.close();
48         return stubLines.toString();
49     }
50 }