SVNKit を使用する。ファイルの比較、保存等には Apache Commons IO を使用。
(コード例)
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | /** SVNテスト. */ static void testSvn() throws Exception {   String user   = "user";   String passwd = "pass";   String url    = "http://xxxx/svn/repos/";   DAVRepositoryFactory.setup();       // urlが http, https   //SVNRepositoryFactoryImpl.setup(); // urlが svn, svn+ssh   //FSRepositoryFactory.setup();      // urlが file   // url   SVNURL svnUrl = SVNURL.parseURIDecoded(url);   // 認証情報   ISVNAuthenticationManager authManager =     SVNWCUtil.createDefaultAuthenticationManager(user, passwd);   // リポジトリ   SVNRepository repository = DAVRepositoryFactory.create(svnUrl);   repository.setAuthenticationManager(authManager);   // ノードの種類を取得   SVNNodeKind nodeKind = repository.checkPath("", -1);   if (SVNNodeKind.NONE == nodeKind) {     System.err.println("none.");     return;   } else if (SVNNodeKind.FILE == nodeKind) {     System.err.println("file.");     return;   }   // リポジトリルートパス取得   String repoRoot = repository.getRepositoryRoot(true).toString();   // リポジトリUUID取得   String repoUUID = repository.getRepositoryUUID(true);   // ファイルのリスト取得   List filePathList = new ArrayList();   setEntries(repository, "", filePathList);   for (String filePath : filePathList) {     System.out.println(filePath);   }   // 以下、例として一番目のファイルを使用する   String filePath = filePathList.get(0);   String fileName = filePath.substring(     filePath.lastIndexOf("/") + 1);   // ファイルを取得   SVNProperties properties = new SVNProperties();   ByteArrayOutputStream baos = new ByteArrayOutputStream();   repository.getFile(filePathList.get(0), -1, properties, baos);   InputStream input1 = new ByteArrayInputStream(baos.toByteArray());   // ファイルを比較   InputStream input2 = new FileInputStream(localPath + fileName);   boolean result = IOUtils.contentEquals(input1, input2);   System.out.println(result);   if (!result) {     // ファイルをローカルに保存     FileOutputStream fos =       new FileOutputStream(localPath + fileName);     fos.write(baos.toByteArray());     fos.close();   } } /** ファイル一覧の取得. */ @SuppressWarnings("unchecked") private void setEntries(SVNRepository repository,     String path, List entriesList)     throws SVNException, UnsupportedEncodingException {   Collection entries =     (Collection) repository.getDir(         path, -1, null, (Collection) null);   Iterator iterator = entries.iterator();   while (iterator.hasNext()) {     SVNDirEntry entry = iterator.next();     if (SVNNodeKind.DIR == entry.getKind()) {       // ディレクトリの場合、再帰処理       setEntries(repository,         (path.length() < 1 ? path : path + "/")           + entry.getName(),         entriesList);     } else if (SVNNodeKind.NONE == entry.getKind()) {       // 処理無し     } else {       // ファイルの場合、パス追加       entriesList.add(         (path.length() < 1 ? path : path + "/")           + entry.getName());     }   } } | 
