/*
 * Copyright 1999-2018 Alibaba Group Holding Ltd.
 *
 * 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 com.alibaba.nacos.core.utils;

import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.io.FileInputStream;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

/**
 * @author Nacos
 */
public class PropertyUtil {
    private static Properties properties = new Properties();

    static {
        try {
            URL configURL = PropertyUtil.class
                .getResource("/application.properties");
            if (configURL != null) {
                URI configURI = configURL.toURI();
                File file = new File(configURI);
                properties = new Properties();
                properties.load(new FileInputStream(file));
            }
        } catch (Exception e) {
        }
    }

    public static String getProperty(String key) {
        return properties.getProperty(key);
    }

    public static String getProperty(String key, String defaultValue) {
        return properties.getProperty(key, defaultValue);
    }

    public static List<String> getPropertyList(String key) {
        List<String> valueList = new ArrayList<>();

        for (int i = 0; i < Integer.MAX_VALUE; i++) {
            String value = properties.getProperty(key + "[" + i + "]");
            if (StringUtils.isBlank(value)) {
                break;
            }

            valueList.add(value);
        }

        return valueList;
    }

}

@@ -698,29 +698,65 @@
 ls;%0A
-%0A
 import 
-java.io.File;
+org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A
 %0Aimp
@@ -800,36 +800,22 @@
 ava.
-net.URI;%0Aimport java.net.URL
+io.InputStream
 ;%0Aim
@@ -1011,311 +1011,494 @@
 ();%0A
-%0A    static %7B%0A        try %7B%0A            URL configURL = PropertyUtil.class%0A                .getResource(%22/application.properties%22);%0A            if (configURL != null) %7B%0A                URI configURI = configURL.toURI();%0A                File file = new File(configURI);%0A                properties = new P
+    private static final Logger log = LoggerFactory.getLogger(PropertyUtil.class);%0A%0A    static %7B%0A        try %7B%0A            InputStream inputStream = null;%0A            String baseDir = System.getProperty(%22nacos.home%22);%0A            if (!StringUtils.isBlank(baseDir)) %7B%0A                inputStream = new FileInputStream(baseDir + %22/conf/application.properties%22);%0A            %7D else %7B%0A                inputStream = PropertyUtil.class%0A                    .getResourceAsStream(%22/application.p
 rope
@@ -1502,24 +1502,34 @@
 operties
-(
+%22
 );%0A    
+        %7D%0A
         
@@ -1548,25 +1548,17 @@
 es.load(
-new FileI
+i
 nputStre
@@ -1563,14 +1563,8 @@
 ream
-(file)
 );%0A 
@@ -1570,30 +1570,16 @@
         
-    %7D%0A        
 %7D catch 
@@ -1592,13 +1592,69 @@
 tion
+ e) %7B%0A            log.error(%22read property file error:%22 +
  e)
- %7B
+;
 %0A   

fix read property file error