blob: 70f068a27702c6796a02526d1aebc5cb1f024c1d [file] [log] [blame]
Simon Hunt8dd716a2015-05-14 18:51:52 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Simon Hunt8dd716a2015-05-14 18:51:52 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18package org.onosproject.cord.gui;
19
20import org.apache.commons.io.IOUtils;
21
22import java.io.IOException;
23import java.io.InputStream;
24
25/**
26 * Provides support for fake data.
27 */
28public class FakeUtils {
29 private static final ClassLoader CL = FakeUtils.class.getClassLoader();
30 private static final String ROOT_PATH = "/org/onosproject/cord/gui/";
31 private static final String UTF_8 = "UTF-8";
32
33 /**
34 * Returns the contents of a local file as a string.
35 *
36 * @param path file path name
37 * @return contents of file as a string
38 */
39 public static String slurp(String path) {
Simon Hunt3e59c602015-05-18 15:29:42 -070040 String result = null;
Simon Hunt8dd716a2015-05-14 18:51:52 -070041 InputStream is = CL.getResourceAsStream(ROOT_PATH + path);
Simon Hunt3e59c602015-05-18 15:29:42 -070042 if (is != null) {
43 try {
44 result = IOUtils.toString(is, UTF_8);
45 } catch (IOException e) {
46 e.printStackTrace();
47 }
Simon Hunt8dd716a2015-05-14 18:51:52 -070048 }
49 return result;
50 }
51}