FileEntryRepository { public void save(User user, FileEntry fileEntry, String encoding) { SVNClientManager svnClientManager = null; ISVNEditor editor = null; String checksum = null; InputStream bais = null; try { svnClientManager = getSVNClientManager(); SVNRepository repo = svnClientManager.createRepository(SVNURL.fromFile(getUserRepoDirectory(user)), true); SVNDirEntry dirEntry = repo.info(fileEntry.getPath(), -1); String fullPath = ""; for (String each : getPathFragment(fileEntry.getPath())) { fullPath = fullPath + "/" + each; SVNDirEntry folderStepEntry = repo.info(fullPath, -1); if (folderStepEntry != null && folderStepEntry.getKind() == SVNNodeKind.FILE) { throw processException("User " + user.getUserId() + " tried to create folder " + fullPath + ". It's file.."); } } editor = repo.getCommitEditor(fileEntry.getDescription(), null, true, null); editor.openRoot(-1); fullPath = ""; for (String each : getPathFragment(fileEntry.getPath())) { fullPath = fullPath + "/" + each; try { editor.addDir(fullPath, null, -1); } catch (Exception e) { noOp(); } } if (fileEntry.getFileType() == FileType.DIR) { editor.addDir(fileEntry.getPath(), null, -1); } else { if (dirEntry == null) { editor.addFile(fileEntry.getPath(), null, -1); } else { editor.openFile(fileEntry.getPath(), -1); } editor.applyTextDelta(fileEntry.getPath(), null); final SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator(); if (fileEntry.getContentBytes() == null && fileEntry.getFileType().isEditable()) { bais = new ByteArrayInputStream(checkNotNull(fileEntry.getContent()).getBytes( encoding == null ? "UTF-8" : encoding)); } else { bais = new ByteArrayInputStream(fileEntry.getContentBytes()); } checksum = deltaGenerator.sendDelta(fileEntry.getPath(), bais, editor, true); } addPropertyValue(editor, fileEntry); editor.closeFile(fileEntry.getPath(), checksum); } catch (Exception e) { abortSVNEditorQuietly(editor); if (e instanceof SVNException && fileEntry.getFileType() == FileType.DIR) { if (SVNErrorCode.FS_ALREADY_EXISTS.equals(((SVNException) e).getErrorMessage().getErrorCode())) { return; } } LOG.error("Error while saving file to SVN", e); throw processException("Error while saving file to SVN", e); } finally { closeSVNEditorQuietly(editor); closeSVNClientManagerQuietly(svnClientManager); IOUtils.closeQuietly(bais); } }  @PostConstruct void init(); File getUserRepoDirectory(User user); List<FileEntry> findAll(User user, final String path, Long revision); List<FileEntry> findAll(User user, final String path, Long revision, boolean recursive); List<FileEntry> findAll(final User user); FileEntry findOne(User user, String path, SVNRevision revision); void save(User user, FileEntry fileEntry, String encoding); void delete(User user, List<String> paths); SVNClientManager getSVNClientManager(); boolean hasOne(User user, String path); void writeContentTo(User user, String path, File toPathDir);  }
@Test public void testRecursiveDirSave() throws IOException { FileEntry fileEntry = new FileEntry(); fileEntry.setContent("HELLO WORLD2"); fileEntry.setEncoding("UTF-8"); fileEntry.setPath("/myworld/www/hello.zip"); fileEntry.setEncoding(null); fileEntry.setFileType(FileType.UNKNOWN); byte[] byteArray = IOUtils.toByteArray(new ClassPathResource("TEST_USER.zip").getInputStream()); fileEntry.setContentBytes(byteArray); repo.save(getTestUser(), fileEntry, null); }