Refactor DefaultRemoteReader for easier code reuse

Change-Id: I7f326b4fc96198de7b424e15d8329bde7d7b39cf
Signed-off-by: Yuxuan 'fishy' Wang <fishywang@google.com>
This commit is contained in:
Yuxuan 'fishy' Wang 2014-06-10 15:44:15 -07:00
parent 83846d1f6d
commit afa2154e45
1 changed files with 9 additions and 1 deletions

View File

@ -182,6 +182,15 @@ public byte[] readFile(String uri, String ref, String path)
.setURI(uri)
.call()
.getRepository();
try {
return readFileFromRepo(repo, ref, path);
} finally {
FileUtils.delete(dir, FileUtils.RECURSIVE);
}
}
protected byte[] readFileFromRepo(Repository repo,
String ref, String path) throws GitAPIException, IOException {
ObjectReader reader = repo.newObjectReader();
byte[] result;
try {
@ -189,7 +198,6 @@ public byte[] readFile(String uri, String ref, String path)
result = reader.open(oid).getBytes(Integer.MAX_VALUE);
} finally {
reader.release();
FileUtils.delete(dir, FileUtils.RECURSIVE);
}
return result;
}