Skip to content

Commit

Permalink
Merge branch 'master' of github.com:p6spy/p6spy
Browse files Browse the repository at this point in the history
  • Loading branch information
typekpb committed Dec 23, 2019
2 parents 89ed173 + 04a6bf5 commit 26a5142
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/main/java/com/p6spy/engine/spy/option/SpyDotProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,44 +22,49 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.util.Map;
import java.util.Properties;

public class SpyDotProperties implements P6OptionsSource {

public static final String OPTIONS_FILE_PROPERTY = "spy.properties";
public static final String OPTIONS_FILE_CHARSET_PROPERTY = OPTIONS_FILE_PROPERTY.concat(".charset");
public static final String DEFAULT_OPTIONS_FILE = OPTIONS_FILE_PROPERTY;

private final long lastModified;

private SpyDotPropertiesReloader reloader;

private final Map<String, String> options;

/**
* Creates a new instance and loads the properties file if found.
*
*
* @throws IOException
*/
public SpyDotProperties() throws IOException {
URL url = locate();

if (null == url) {
// no config file preset => skip props loading
lastModified = -1;
options = null;
return;
}

lastModified = lastModified();

InputStream in = null;
try {
in = url.openStream();
final Properties properties = new Properties();
properties.load(in);

String charsetName = System.getProperty(OPTIONS_FILE_CHARSET_PROPERTY, Charset.defaultCharset().name());
properties.load(new InputStreamReader(in, charsetName));
options = P6Util.getPropertiesMap(properties);
} finally {
if (null != in) {
Expand All @@ -74,20 +79,20 @@ public SpyDotProperties() throws IOException {

/**
* Determines if the file has been modified since it was loaded
*
*
* @return true if modified, false otherwise
*/
public boolean isModified() {
return lastModified() != lastModified;
}

private long lastModified() {
long lastMod = -1;
URLConnection con = null;
URL url = locate();
if( url != null ) {
try {
con = url.openConnection();
con = url.openConnection();
lastMod = con.getLastModified();
} catch (IOException e) {
// ignore
Expand Down

0 comments on commit 26a5142

Please sign in to comment.