|
|
@ -145,7 +145,12 @@ public class ConfigTreePropertySource extends EnumerablePropertySource<Path> imp
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Convert file and directory names to lowercase.
|
|
|
|
* Convert file and directory names to lowercase.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
USE_LOWERCASE_NAMES
|
|
|
|
USE_LOWERCASE_NAMES,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Automatically attempt trim trailing new-line characters.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
AUTO_TRIM_TRAILING_NEW_LINE
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -173,17 +178,22 @@ public class ConfigTreePropertySource extends EnumerablePropertySource<Path> imp
|
|
|
|
|
|
|
|
|
|
|
|
private final PropertyFileContent cachedContent;
|
|
|
|
private final PropertyFileContent cachedContent;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final boolean autoTrimTrailingNewLine;
|
|
|
|
|
|
|
|
|
|
|
|
private PropertyFile(Path path, Set<Option> options) {
|
|
|
|
private PropertyFile(Path path, Set<Option> options) {
|
|
|
|
this.path = path;
|
|
|
|
this.path = path;
|
|
|
|
this.resource = new PathResource(path);
|
|
|
|
this.resource = new PathResource(path);
|
|
|
|
this.origin = new TextResourceOrigin(this.resource, START_OF_FILE);
|
|
|
|
this.origin = new TextResourceOrigin(this.resource, START_OF_FILE);
|
|
|
|
|
|
|
|
this.autoTrimTrailingNewLine = options.contains(Option.AUTO_TRIM_TRAILING_NEW_LINE);
|
|
|
|
this.cachedContent = options.contains(Option.ALWAYS_READ) ? null
|
|
|
|
this.cachedContent = options.contains(Option.ALWAYS_READ) ? null
|
|
|
|
: new PropertyFileContent(path, this.resource, this.origin, true);
|
|
|
|
: new PropertyFileContent(path, this.resource, this.origin, true, this.autoTrimTrailingNewLine);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PropertyFileContent getContent() {
|
|
|
|
PropertyFileContent getContent() {
|
|
|
|
return (this.cachedContent != null) ? this.cachedContent
|
|
|
|
if (this.cachedContent != null) {
|
|
|
|
: new PropertyFileContent(this.path, this.resource, this.origin, false);
|
|
|
|
return this.cachedContent;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return new PropertyFileContent(this.path, this.resource, this.origin, false, this.autoTrimTrailingNewLine);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Origin getOrigin() {
|
|
|
|
Origin getOrigin() {
|
|
|
@ -247,17 +257,21 @@ public class ConfigTreePropertySource extends EnumerablePropertySource<Path> imp
|
|
|
|
|
|
|
|
|
|
|
|
private final Resource resource;
|
|
|
|
private final Resource resource;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Origin origin;
|
|
|
|
|
|
|
|
|
|
|
|
private final boolean cacheContent;
|
|
|
|
private final boolean cacheContent;
|
|
|
|
|
|
|
|
|
|
|
|
private volatile byte[] content;
|
|
|
|
private final boolean autoTrimTrailingNewLine;
|
|
|
|
|
|
|
|
|
|
|
|
private final Origin origin;
|
|
|
|
private volatile byte[] content;
|
|
|
|
|
|
|
|
|
|
|
|
private PropertyFileContent(Path path, Resource resource, Origin origin, boolean cacheContent) {
|
|
|
|
private PropertyFileContent(Path path, Resource resource, Origin origin, boolean cacheContent,
|
|
|
|
|
|
|
|
boolean autoTrimTrailingNewLine) {
|
|
|
|
this.path = path;
|
|
|
|
this.path = path;
|
|
|
|
this.resource = resource;
|
|
|
|
this.resource = resource;
|
|
|
|
this.origin = origin;
|
|
|
|
this.origin = origin;
|
|
|
|
this.cacheContent = cacheContent;
|
|
|
|
this.cacheContent = cacheContent;
|
|
|
|
|
|
|
|
this.autoTrimTrailingNewLine = autoTrimTrailingNewLine;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -282,7 +296,28 @@ public class ConfigTreePropertySource extends EnumerablePropertySource<Path> imp
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
public String toString() {
|
|
|
|
return new String(getBytes());
|
|
|
|
String string = new String(getBytes());
|
|
|
|
|
|
|
|
if (this.autoTrimTrailingNewLine) {
|
|
|
|
|
|
|
|
string = autoTrimTrailingNewLine(string);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return string;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String autoTrimTrailingNewLine(String string) {
|
|
|
|
|
|
|
|
if (!string.endsWith("\n")) {
|
|
|
|
|
|
|
|
return string;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int numberOfLines = 0;
|
|
|
|
|
|
|
|
for (char ch : string.toCharArray()) {
|
|
|
|
|
|
|
|
if (ch == '\n') {
|
|
|
|
|
|
|
|
numberOfLines++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numberOfLines > 1) {
|
|
|
|
|
|
|
|
return string;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return (string.endsWith("\r\n")) ? string.substring(0, string.length() - 2)
|
|
|
|
|
|
|
|
: string.substring(0, string.length() - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|