/**
* Tests create-delete-create-a-file sequence on the same file system.
*/
public void testAppendContent() throws Exception
{
final FileObject scratchFolder = createScratchFolder();
// Create direct child of the test folder
final FileObject file = scratchFolder.resolveFile("file1.txt");
assertTrue(!file.exists());
// Create the source file
final String content = "Here is some sample content for the file. Blah Blah Blah.";
final String contentAppend = content + content;
final OutputStream os = file.getContent().getOutputStream();
try
{
os.write(content.getBytes("utf-8"));
}
finally
{
os.close();
}
assertSameContent(content, file);
// Append to the new file
final OutputStream os2 = file.getContent().getOutputStream(true);
try
{
os2.write(content.getBytes("utf-8"));
}
finally
{
os2.close();
}
assertSameContent(contentAppend, file);
// Make sure we can copy the new file to another file on the same filesystem
FileObject fileCopy = scratchFolder.resolveFile("file1copy.txt");
assertTrue(!fileCopy.exists());
fileCopy.copyFrom(file, Selectors.SELECT_SELF);
assertSameContent(contentAppend, fileCopy);
// Delete the file.
assertTrue(fileCopy.exists());
assertTrue(fileCopy.delete());
}