com.hibegin.http.server.config.ConfigKit Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of simplewebserver Show documentation
Show all versions of simplewebserver Show documentation
Simple, flexible, less dependent, more extended. Less memory footprint, can quickly build Web project.
Can quickly run embedded, Android devices
package com.hibegin.http.server.config;
import com.hibegin.common.util.LoggerUtil;
import com.hibegin.http.server.util.PathUtil;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ConfigKit {
private static final Logger LOGGER = LoggerUtil.getLogger(ConfigKit.class);
private static final Properties prop;
static {
prop = new Properties();
try (InputStream inputStream = PathUtil.getConfInputStream("/conf.properties")) {
if(Objects.nonNull(inputStream)){
prop.load(inputStream);
}
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "", e);
}
}
public static Integer getMaxRequestBodySize() {
return getInt("server.maxRequestBodySize", 20971520);
}
public static Integer getServerPort() {
return getInt("server.port", 6058);
}
public static Integer getHttpsServerPort() {
return getInt("server.ssl.port", 6443);
}
public static boolean contains(String key) {
return prop.get(key) != null;
}
public static Object get(String key, Object defaultValue) {
Object obj = prop.get(key);
if (obj != null) {
return obj;
}
return defaultValue;
}
public static int getInt(String key, int defaultValue) {
Object obj = prop.get(key);
if (obj != null) {
return Integer.valueOf(obj + "");
}
return defaultValue;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy