1 16 package org.apache.commons.vfs.test; 17 18 import org.apache.commons.vfs.Capability; 19 import org.apache.commons.vfs.FileObject; 20 import org.apache.commons.vfs.Selectors; 21 22 import java.io.OutputStream ; 23 24 29 public class ProviderWriteAppendTests 30 extends AbstractProviderTestCase 31 { 32 35 protected Capability[] getRequiredCaps() 36 { 37 return new Capability[] 38 { 39 Capability.CREATE, 40 Capability.DELETE, 41 Capability.GET_TYPE, 42 Capability.LIST_CHILDREN, 43 Capability.READ_CONTENT, 44 Capability.WRITE_CONTENT, 45 Capability.APPEND_CONTENT 46 }; 47 } 48 49 52 protected FileObject createScratchFolder() throws Exception 53 { 54 FileObject scratchFolder = getWriteFolder(); 55 56 scratchFolder.delete(Selectors.EXCLUDE_SELF); 58 scratchFolder.createFolder(); 59 60 return scratchFolder; 61 } 62 63 66 public void testAppendContent() throws Exception 67 { 68 final FileObject scratchFolder = createScratchFolder(); 69 70 final FileObject file = scratchFolder.resolveFile("file1.txt"); 72 assertTrue(!file.exists()); 73 74 final String content = "Here is some sample content for the file. Blah Blah Blah."; 76 final String contentAppend = content + content; 77 78 final OutputStream os = file.getContent().getOutputStream(); 79 try 80 { 81 os.write(content.getBytes("utf-8")); 82 } 83 finally 84 { 85 os.close(); 86 } 87 assertSameContent(content, file); 88 89 final OutputStream os2 = file.getContent().getOutputStream(true); 91 try 92 { 93 os2.write(content.getBytes("utf-8")); 94 } 95 finally 96 { 97 os2.close(); 98 } 99 assertSameContent(contentAppend, file); 100 101 FileObject fileCopy = scratchFolder.resolveFile("file1copy.txt"); 103 assertTrue(!fileCopy.exists()); 104 fileCopy.copyFrom(file, Selectors.SELECT_SELF); 105 106 assertSameContent(contentAppend, fileCopy); 107 108 assertTrue(fileCopy.exists()); 110 assertTrue(fileCopy.delete()); 111 } 112 } 113 | Popular Tags |