I am writing a storage for articles and I have decided to use GridFS from MongoDB. I have found and tested some code, but I am not sure that it is a best one. Could you advice me how to make it better?
private GridFS gridFs;
public String getPostContent(String name) {
GridFSDBFile file = gridFs.findOne(name + ".html");
if (file == null) {
return "There is no text for this article.";
}
return getStringFromInputStream(file.getInputStream());
}
private static String getStringFromInputStream(InputStream is) {
BufferedReader bufferedReader = null;
StringBuilder builder = new StringBuilder();
String line;
try {
bufferedReader = new BufferedReader(new InputStreamReader(is));
while ((line = bufferedReader.readLine()) != null) {
builder.append(System.getProperty("line.separator")).append(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return builder.toString();
}
I will appreciate any suggestions even regarding chosen approach.