Пример #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;
  }