Simon Hunt | 8dd716a | 2015-05-14 18:51:52 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Simon Hunt | 8dd716a | 2015-05-14 18:51:52 -0700 | [diff] [blame] | 3 | * |
| 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 | |
| 18 | package org.onosproject.cord.gui; |
| 19 | |
| 20 | import org.apache.commons.io.IOUtils; |
| 21 | |
| 22 | import java.io.IOException; |
| 23 | import java.io.InputStream; |
| 24 | |
| 25 | /** |
| 26 | * Provides support for fake data. |
| 27 | */ |
| 28 | public 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 Hunt | 3e59c60 | 2015-05-18 15:29:42 -0700 | [diff] [blame] | 40 | String result = null; |
Simon Hunt | 8dd716a | 2015-05-14 18:51:52 -0700 | [diff] [blame] | 41 | InputStream is = CL.getResourceAsStream(ROOT_PATH + path); |
Simon Hunt | 3e59c60 | 2015-05-18 15:29:42 -0700 | [diff] [blame] | 42 | if (is != null) { |
| 43 | try { |
| 44 | result = IOUtils.toString(is, UTF_8); |
| 45 | } catch (IOException e) { |
| 46 | e.printStackTrace(); |
| 47 | } |
Simon Hunt | 8dd716a | 2015-05-14 18:51:52 -0700 | [diff] [blame] | 48 | } |
| 49 | return result; |
| 50 | } |
| 51 | } |