/*
 * Copyright 2017 University of Ulm
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.uniulm.omi.cloudiator.util;

import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Properties;

/**
 * Created by daniel on 13.06.17.
 */
public class PropertiesLoader {

  private final static String ERROR_MESSAGE = "Could not read properties file at location %s";

  private PropertiesLoader() {
    throw new AssertionError("Do not instantiate " + this);
  }

  public static Properties loadPropertiesFrom(String fileName) throws IOException {

    final URL resource = PropertiesLoader.class.getClassLoader().getResource(fileName);

    if (resource == null) {
      throw new IOException(String.format(ERROR_MESSAGE, fileName));
    }

    try {
      final InputStream inputStream = Files
          .newInputStream(Paths.get(resource.toURI()), StandardOpenOption.READ);
      Properties properties = new Properties();
      properties.load(inputStream);
      return properties;
    } catch (URISyntaxException | IOException e) {
      throw new IOException(
          String.format(ERROR_MESSAGE, resource));
    }
  }

}

@@ -691,16 +691,37 @@
 Stream;%0A
+import java.net.URI;%0A
 import j
@@ -794,17 +794,22 @@
 ile.File
-s
+System
 ;%0Aimport
@@ -823,20 +823,54 @@
 io.file.
-Path
+FileSystems;%0Aimport java.nio.file.File
 s;%0Aimpor
@@ -901,24 +901,54 @@
 OpenOption;%0A
+import java.util.Collections;%0A
 import java.
@@ -1520,16 +1520,187 @@
   try %7B%0A
+      final String%5B%5D array = resource.toURI().toString().split(%22!%22);%0A      final FileSystem fs = FileSystems.newFileSystem(URI.create(array%5B0%5D), Collections.emptyMap());%0A%0A
       fi
@@ -1765,34 +1765,27 @@
 eam(
-Path
+f
 s.get
-(resource.toURI()
+Path(array%5B1%5D
 ), S

load files from within jar file.