Skip to content

Instantly share code, notes, and snippets.

@valtoni
Created April 14, 2015 12:44
Show Gist options
  • Save valtoni/6406a9a28be14331196a to your computer and use it in GitHub Desktop.
Save valtoni/6406a9a28be14331196a to your computer and use it in GitHub Desktop.
Create an property file in memory (Builder like)
static class MemoryPropertyBuilder {
StringBuilder builder = new StringBuilder();
PropertyBuilder add(String param, String value) {
builder.append(param + "=" + value);
return this;
}
Properties properties() {
Properties props = new Properties();
StringBuffer stringBuffer = new StringBuffer(builder);
try {
props.load(new ByteArrayInputStream(stringBuffer.toString().getBytes()));
} catch (IOException e) {
throw new RuntimeException("Error creating property file", e);
}
return props;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment