-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathFilesConfig.java
More file actions
141 lines (113 loc) · 3.86 KB
/
FilesConfig.java
File metadata and controls
141 lines (113 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package com.files;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FilesConfig {
private static final Logger log = LoggerFactory.getLogger(FilesConfig.class);
private static volatile FilesConfig instance;
private final Properties properties;
protected FilesConfig() {
properties = new Properties();
try (InputStream file = FilesConfig.class.getResourceAsStream("/files-sdk.properties")) {
properties.load(file);
} catch (IOException e) {
log.warn("could not load configurator properties");
} catch (NullPointerException ne) {
log.warn("could not load configurator properties /files-sdk.properties could not be located");
}
}
public static FilesConfig getInstance() {
if (instance == null) {
synchronized (FilesConfig.class) {
if (instance == null) {
instance = new FilesConfig();
}
}
}
return instance;
}
private int intProperty(String key, int defaultValue) {
String strValue = properties.getProperty(key);
if (isNullOrEmpty(strValue)) {
return defaultValue;
} else {
return Integer.valueOf(strValue);
}
}
private boolean boolProperty(String key, boolean defaultValue) {
String strValue = properties.getProperty(key);
if (isNullOrEmpty(strValue)) {
return defaultValue;
} else {
return Boolean.valueOf(strValue);
}
}
public boolean getAllowInsecureBackend(String def) {
return boolProperty("allowInsecureBackend", false);
}
public String getApiBase() {
return properties.getProperty("apiBase", String.format("/api/rest/v1"));
}
public String getApiRoot() {
return properties.getProperty("apiRoot", "https://app.files.com");
}
public String getApiKey() {
return properties.getProperty("apiKey", null);
}
public int getCachedBufferTinySize() {
return intProperty("cachedBufferTinySize", 1024 * 16);
}
public int getCachedBufferSmallSize() {
return intProperty("cachedBufferSmallSize", 1024 * 1024 /* 1 MB */);
}
public int getCachedBufferMediumSize() {
return intProperty("cachedBufferMediumSize", 16777216 /* 16 MB */);
}
public int getCachedBufferLargeSize() {
// must be at least the size of the largest requested upload page
return intProperty("cachedBufferLargeSize", 50331648 /* 48 MB */);
}
public int getCachedBufferMaxBytes() {
return intProperty("cachedBufferMaxBytes", (int) Math.min(Runtime.getRuntime().maxMemory() / 5,
1610612736 /* 1.5 GB */));
}
public boolean getHttpLoggingEnabled() {
return boolProperty("httpLoggingEnabled", true);
}
public int getInitialRetryDelayMillis() {
return intProperty("initialRetryDelayMillis", 500);
}
public int getMaximumRetrySeconds() {
return intProperty("maximumRetrySeconds", 10);
}
public String getSdkVersion() {
return properties.getProperty("sdkVersion", "0.0.1");
}
public String getUserAgent() {
String defaultUserAgent = String.format("Files.com Java SDK v%s", this.getSdkVersion());
return properties.getProperty("userAgent", defaultUserAgent);
}
public boolean getUpstreamHttp2Enabled() {
return boolProperty("upstreamHttp2Enabled", true);
}
public boolean getUpstreamInsecureAllowed() {
return boolProperty("upstreamInsecureAllowed", false);
}
public int getUpstreamMaxAttempts() {
return intProperty("upstreamMaxAttempts", 5);
}
public int getUpstreamMaxConnections() {
return intProperty("upstreamMaxConnections", 500);
}
public int getUpstreamTimeout() {
return intProperty("upstreamTimeout", 5000);
}
public void setProperty(String property, String value) {
properties.setProperty(property, value);
}
private boolean isNullOrEmpty(final String input) {
return input == null || input.isEmpty();
}
}