9
9
import java .io .InputStream ;
10
10
import java .io .IOException ;
11
11
import java .io .UnsupportedEncodingException ;
12
- import java .nio .charset .StandardCharsets ;
13
12
import java .util .Arrays ;
14
13
import java .util .ArrayList ;
15
14
import java .util .Enumeration ;
30
29
import org .apache .log4j .Appender ;
31
30
import org .apache .log4j .Level ;
32
31
import org .apache .log4j .Logger ;
32
+ import org .apache .commons .lang3 .CharEncoding ;
33
33
import org .apache .commons .io .FileUtils ;
34
34
import org .apache .commons .io .filefilter .WildcardFileFilter ;
35
35
import org .datadog .jmxfetch .reporter .Reporter ;
@@ -156,7 +156,7 @@ private static void clearInstances(List<Instance> instances) {
156
156
}
157
157
158
158
private String get_sd_name (String config ){
159
- String [] splitted = config .split (System .lineSeparator ( ), 2 );
159
+ String [] splitted = config .split (System .getProperty ( "line.separator" ), 2 );
160
160
161
161
return SERVICE_DISCOVERY_PREFIX + splitted [0 ].substring (2 , splitted [0 ].length ());
162
162
}
@@ -166,8 +166,8 @@ private boolean process_service_discovery(byte[] buffer) {
166
166
String [] discovered ;
167
167
168
168
try {
169
- String configs = new String (buffer , "UTF-8" );
170
- discovered = configs .split (App .SD_CONFIG_SEP + System .lineSeparator ( ));
169
+ String configs = new String (buffer , CharEncoding . UTF_8 );
170
+ discovered = configs .split (App .SD_CONFIG_SEP + System .getProperty ( "line.separator" ));
171
171
} catch (UnsupportedEncodingException e ) {
172
172
LOGGER .debug ("Unable to parse byte buffer to UTF-8 String." );
173
173
return false ;
@@ -178,14 +178,18 @@ private boolean process_service_discovery(byte[] buffer) {
178
178
continue ;
179
179
}
180
180
181
- String name = get_sd_name (config );
182
- LOGGER .debug ("Attempting to apply config. Name: " + name + "\n config: \n " + config );
183
- InputStream stream = new ByteArrayInputStream (config .getBytes (StandardCharsets .UTF_8 ));
184
- YamlParser yaml = new YamlParser (stream );
185
-
186
- if (this .addConfig (name , yaml )){
187
- reinit = true ;
188
- LOGGER .debug ("Configuration added succesfully reinit in order" );
181
+ try {
182
+ String name = get_sd_name (config );
183
+ LOGGER .debug ("Attempting to apply config. Name: " + name + "\n config: \n " + config );
184
+ InputStream stream = new ByteArrayInputStream (config .getBytes (CharEncoding .UTF_8 ));
185
+ YamlParser yaml = new YamlParser (stream );
186
+
187
+ if (this .addConfig (name , yaml )){
188
+ reinit = true ;
189
+ LOGGER .debug ("Configuration added succesfully reinit in order" );
190
+ }
191
+ } catch (UnsupportedEncodingException e ) {
192
+ LOGGER .debug ("Unable to parse byte buffer to UTF-8 String." );
189
193
}
190
194
}
191
195
@@ -362,7 +366,8 @@ public boolean addConfig(String name, YamlParser config) {
362
366
return false ;
363
367
}
364
368
365
- String check = matcher .group ("check" );
369
+ // Java 6 doesn't allow name matching - group 1 is "check"
370
+ String check = matcher .group (1 );
366
371
if (this .configs .containsKey (check )) {
367
372
// there was already a file config for the check.
368
373
return false ;
0 commit comments