RecursiveMergerTest: Open TreeWalk and BufferedReader in try-with-resource
Change-Id: I381d535eb4ed7535ba8541c5320f81ce11d5b173 Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
This commit is contained in:
parent
964da41d52
commit
3adea9ac7f
|
@ -872,32 +872,31 @@ private boolean validateStates(IndexState indexState,
|
||||||
|
|
||||||
private String contentAsString(Repository r, ObjectId treeId, String path)
|
private String contentAsString(Repository r, ObjectId treeId, String path)
|
||||||
throws MissingObjectException, IOException {
|
throws MissingObjectException, IOException {
|
||||||
TreeWalk tw = new TreeWalk(r);
|
AnyObjectId blobId;
|
||||||
tw.addTree(treeId);
|
try (TreeWalk tw = new TreeWalk(r)) {
|
||||||
tw.setFilter(PathFilter.create(path));
|
tw.addTree(treeId);
|
||||||
tw.setRecursive(true);
|
tw.setFilter(PathFilter.create(path));
|
||||||
if (!tw.next())
|
tw.setRecursive(true);
|
||||||
return null;
|
if (!tw.next()) {
|
||||||
AnyObjectId blobId = tw.getObjectId(0);
|
return null;
|
||||||
|
}
|
||||||
|
blobId = tw.getObjectId(0);
|
||||||
|
}
|
||||||
|
|
||||||
StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
BufferedReader br = null;
|
|
||||||
ObjectReader or = r.newObjectReader();
|
ObjectReader or = r.newObjectReader();
|
||||||
try {
|
try (BufferedReader br = new BufferedReader(
|
||||||
br = new BufferedReader(new InputStreamReader(or.open(blobId)
|
new InputStreamReader(or.open(blobId).openStream()))) {
|
||||||
.openStream()));
|
|
||||||
String line;
|
String line;
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
while ((line = br.readLine()) != null) {
|
while ((line = br.readLine()) != null) {
|
||||||
if (!first)
|
if (!first) {
|
||||||
result.append('\n');
|
result.append('\n');
|
||||||
|
}
|
||||||
result.append(line);
|
result.append(line);
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
return result.toString();
|
return result.toString();
|
||||||
} finally {
|
|
||||||
if (br != null)
|
|
||||||
br.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue