Detect file encoding from the first line of the property file. If the first line in the file doesn't contain the comment with the encoding, it uses ISO-8859-1 as default encoding for backwards compatibility.
The specified stream is closed before this method returns.
56 try (BufferedReader br =
new BufferedReader(
new InputStreamReader(in,
DEFAULT_ENCODING))) {
57 String firstLine = br.readLine();
58 if (firstLine != null) {
61 String encoding = matcher.group(1);
62 if (Charset.isSupported(encoding)) {
63 return Charset.forName(encoding);
65 logger.warnv(
"Unsupported encoding: {0}", encoding);
static final Pattern DETECT_ENCODING_PATTERN
Definition: PropertiesUtil.java:37
static final Logger logger
Definition: PropertiesUtil.java:35
static final Charset DEFAULT_ENCODING
Definition: PropertiesUtil.java:40