示例#1
0
 @Override
 public byte[] getRawFile(String path) throws SVNException {
   org.tmatesoft.svn.core.io.SVNRepository repository = getSVNRepository();
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   repository.getFile(path, -1l, null, baos);
   return baos.toByteArray();
 }
示例#2
0
  private ObjectNode fileAsJson(String path, org.tmatesoft.svn.core.io.SVNRepository repository)
      throws SVNException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    SVNProperties prop = new SVNProperties();
    repository.getFile(path, -1l, prop, baos);
    long size = repository.info(path, -1l).getSize();
    boolean isBinary;
    String mimeType;
    String data = null;
    if (size > MAX_FILE_SIZE_CAN_BE_VIEWED) {
      isBinary = true;
      mimeType = "application/octet-stream";
    } else {
      byte[] bytes = baos.toByteArray();
      isBinary = FileUtil.isBinary(bytes);
      if (!isBinary) {
        data = new String(bytes);
      }
      mimeType = new Tika().detect(bytes, path);
    }
    String author = prop.getStringValue(SVNProperty.LAST_AUTHOR);
    User user = User.findByLoginId(author);

    ObjectNode result = Json.newObject();
    result.put("type", "file");
    result.put("revisionNo", prop.getStringValue(SVNProperty.COMMITTED_REVISION));
    result.put("author", author);
    result.put("avatar", getAvatar(user));
    result.put("userName", user.name);
    result.put("userLoginId", user.loginId);
    result.put("createdDate", prop.getStringValue(SVNProperty.COMMITTED_DATE));
    result.put("size", size);
    result.put("isBinary", isBinary);
    result.put("mimeType", mimeType);
    result.put("data", data);

    return result;
  }
示例#3
0
  @Override
  public String getPatch(String commitId) throws SVNException {
    // Prepare required arguments.
    SVNURL svnURL = SVNURL.fromFile(new File(getRepoPrefix() + ownerName + "/" + projectName));
    long rev = Integer.parseInt(commitId);

    // Get diffClient.
    SVNClientManager clientManager = SVNClientManager.newInstance();
    SVNDiffClient diffClient = clientManager.getDiffClient();

    // Using diffClient, write the changes by commitId into
    // byteArrayOutputStream, as unified format.
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    diffClient.doDiff(
        svnURL,
        null,
        SVNRevision.create(rev - 1),
        SVNRevision.create(rev),
        SVNDepth.INFINITY,
        true,
        byteArrayOutputStream);

    return byteArrayOutputStream.toString();
  }