@Test public void overwriteFile() throws IOException { ContentFileTransactionContext context = new ContentFileTransactionContext(contentDir, deletedTmpDir); InputStream is = IOUtils.toInputStream("content of file"); File oldFile = new File(contentDir, "oldFile.txt"); oldFile.createNewFile(); contentFileOperationPerformer.overwriteFile(context, is, "file.txt", "oldFile.txt"); assertFileInContentDirectory("file.txt", "content of file"); assertFileInDeletedTmpDirectory("oldFile.txt", ""); assertEquals(1, context.getAddedFiles().size()); assertEquals("file.txt", context.getAddedFiles().peek()); }
public void overwriteFile(ContentFileTransactionContext context, InputStream inputStream, String path, String oldPath) throws IOException { Preconditions.checkNotNull(context); Preconditions.checkNotNull(inputStream); Preconditions.checkNotNull(path); Preconditions.checkNotNull(oldPath); File contentDirectory = context.getContentDirectory(); File deletedTmpDirectory = context.getDeletedTmpDirectory(); File oldFile = new File(contentDirectory, oldPath); FileUtils.copyFile(oldFile, new File(deletedTmpDirectory, oldPath)); oldFile.delete(); FileUtils.copyInputStreamToFile(inputStream, new File(contentDirectory, path)); context.addAddedFile(path); }
ContentFileOperationPerformer { public void overwriteFile(ContentFileTransactionContext context, InputStream inputStream, String path, String oldPath) throws IOException { Preconditions.checkNotNull(context); Preconditions.checkNotNull(inputStream); Preconditions.checkNotNull(path); Preconditions.checkNotNull(oldPath); File contentDirectory = context.getContentDirectory(); File deletedTmpDirectory = context.getDeletedTmpDirectory(); File oldFile = new File(contentDirectory, oldPath); FileUtils.copyFile(oldFile, new File(deletedTmpDirectory, oldPath)); oldFile.delete(); FileUtils.copyInputStreamToFile(inputStream, new File(contentDirectory, path)); context.addAddedFile(path); } }
ContentFileOperationPerformer { public void overwriteFile(ContentFileTransactionContext context, InputStream inputStream, String path, String oldPath) throws IOException { Preconditions.checkNotNull(context); Preconditions.checkNotNull(inputStream); Preconditions.checkNotNull(path); Preconditions.checkNotNull(oldPath); File contentDirectory = context.getContentDirectory(); File deletedTmpDirectory = context.getDeletedTmpDirectory(); File oldFile = new File(contentDirectory, oldPath); FileUtils.copyFile(oldFile, new File(deletedTmpDirectory, oldPath)); oldFile.delete(); FileUtils.copyInputStreamToFile(inputStream, new File(contentDirectory, path)); context.addAddedFile(path); }  }
ContentFileOperationPerformer { public void overwriteFile(ContentFileTransactionContext context, InputStream inputStream, String path, String oldPath) throws IOException { Preconditions.checkNotNull(context); Preconditions.checkNotNull(inputStream); Preconditions.checkNotNull(path); Preconditions.checkNotNull(oldPath); File contentDirectory = context.getContentDirectory(); File deletedTmpDirectory = context.getDeletedTmpDirectory(); File oldFile = new File(contentDirectory, oldPath); FileUtils.copyFile(oldFile, new File(deletedTmpDirectory, oldPath)); oldFile.delete(); FileUtils.copyInputStreamToFile(inputStream, new File(contentDirectory, path)); context.addAddedFile(path); }  void addFile(ContentFileTransactionContext context, InputStream inputStream, String path); void overwriteFile(ContentFileTransactionContext context, InputStream inputStream, String path, String oldPath); }
ContentFileOperationPerformer { public void overwriteFile(ContentFileTransactionContext context, InputStream inputStream, String path, String oldPath) throws IOException { Preconditions.checkNotNull(context); Preconditions.checkNotNull(inputStream); Preconditions.checkNotNull(path); Preconditions.checkNotNull(oldPath); File contentDirectory = context.getContentDirectory(); File deletedTmpDirectory = context.getDeletedTmpDirectory(); File oldFile = new File(contentDirectory, oldPath); FileUtils.copyFile(oldFile, new File(deletedTmpDirectory, oldPath)); oldFile.delete(); FileUtils.copyInputStreamToFile(inputStream, new File(contentDirectory, path)); context.addAddedFile(path); }  void addFile(ContentFileTransactionContext context, InputStream inputStream, String path); void overwriteFile(ContentFileTransactionContext context, InputStream inputStream, String path, String oldPath);  }