Example usage for org.eclipse.jgit.lib Repository close

List of usage examples for org.eclipse.jgit.lib Repository close

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Repository close.

Prototype

@Override
public void close() 

Source Link

Document

Decrement the use count, and maybe close resources.

Usage

From source file:uk.ac.cam.UROP.twentyfourteen.database.GitDb.java

/**
 * getFileByCommitSHA/*  w  ww. j  a v  a2  s . co  m*/
 *
 * This method will access the git repository given a particular SHA and
 * will attempt to locate a unique file and return a bytearrayoutputstream
 * of the files contents.
 *
 * @param SHA
 *            to search in.
 * @param Full
 *            file path to search for e.g. /src/filename.json
 * @return the ByteArrayOutputStream - which you can extract the file
 *         contents via the toString method.
 * @throws IOException
 * @throws UnsupportedOperationException
 *             - This method is intended to only locate one file at a time.
 *             If your search matches multiple files then this exception
 *             will be thrown.
 */
public ByteArrayOutputStream getFileByCommitSHA(String sha, String fullFilePath)
        throws IOException, UnsupportedOperationException {
    if (null == sha || null == fullFilePath)
        return null;

    ObjectId objectId = this.findGitObject(sha, fullFilePath);

    if (null == objectId) {
        return null;
    }

    Repository repository = gitHandle.getRepository();
    ObjectLoader loader = repository.open(objectId);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    loader.copyTo(out);

    repository.close();
    return out;
}