View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.vfs2;
18  
19  import java.io.OutputStream;
20  import java.nio.charset.StandardCharsets;
21  import java.util.ArrayList;
22  import java.util.HashSet;
23  import java.util.Objects;
24  import java.util.Set;
25  
26  import org.junit.Assert;
27  import org.junit.Test;
28  
29  /**
30   * File system test that check that a file system can be modified.
31   */
32  public class ProviderWriteTests extends AbstractProviderTestCase {
33  
34      /**
35       * A test listener.
36       */
37      private static class TestListener implements FileListener {
38          private static final Object CREATE = "create";
39          private static final Object DELETE = "delete";
40          private static final Object CHANGED = "changed";
41          private final FileObject file;
42          private final ArrayList<Object> events = new ArrayList<>();
43  
44          public TestListener(final FileObject file) {
45              this.file = file;
46          }
47  
48          public void addCreateEvent() {
49              events.add(CREATE);
50          }
51  
52          public void addDeleteEvent() {
53              events.add(DELETE);
54          }
55  
56          public void assertFinished() {
57              assertEquals("Missing event", 0, events.size());
58          }
59  
60          @Override
61          public void fileChanged(final FileChangeEvent event) throws Exception {
62              assertFalse("Unexpected changed event", events.isEmpty());
63              assertSame("Expecting a changed event", CHANGED, events.remove(0));
64              assertEquals(Objects.toString(file), file, event.getFileObject());
65              try {
66                  assertFalse(Objects.toString(file), file.exists());
67              } catch (final FileSystemException e) {
68                  fail();
69              }
70          }
71  
72          /**
73           * Called when a file is created.
74           */
75          @Override
76          public void fileCreated(final FileChangeEvent event) {
77              assertFalse("Unexpected create event", events.isEmpty());
78              assertSame("Expecting a create event", CREATE, events.remove(0));
79              assertEquals(Objects.toString(file), file, event.getFileObject());
80              try {
81                  assertTrue(Objects.toString(file), file.exists());
82              } catch (final FileSystemException e) {
83                  fail();
84              }
85          }
86  
87          /**
88           * Called when a file is deleted.
89           */
90          @Override
91          public void fileDeleted(final FileChangeEvent event) {
92              assertFalse("Unexpected delete event", events.isEmpty());
93              assertSame("Expecting a delete event", DELETE, events.remove(0));
94              assertEquals(Objects.toString(file), file, event.getFileObject());
95              try {
96                  assertFalse(Objects.toString(file), file.exists());
97              } catch (final FileSystemException e) {
98                  fail();
99              }
100         }
101     }
102 
103     /**
104      * Ensures the names of a set of files match an expected set.
105      */
106     private void assertSameFileSet(final Set<String> names, final FileObject[] files) {
107         // Make sure the sets are the same length
108         assertEquals(names.size(), files.length);
109 
110         // Check for unexpected names
111         for (final FileObject file : files) {
112             assertTrue(names.contains(file.getName().getBaseName()));
113         }
114     }
115 
116     /**
117      * Sets up a scratch folder for the test to use.
118      */
119     protected FileObject createScratchFolder() throws Exception {
120         final FileObject scratchFolder = getWriteFolder();
121 
122         // Make sure the test folder is empty
123         scratchFolder.delete(Selectors.EXCLUDE_SELF);
124         scratchFolder.createFolder();
125 
126         return scratchFolder;
127     }
128 
129     protected FileObject getReadFolderDir1() throws FileSystemException {
130         return getReadFolder().resolveFile("dir1");
131     }
132 
133     /**
134      * Returns the capabilities required by the tests of this test case.
135      */
136     @Override
137     protected Capability[] getRequiredCapabilities() {
138         return new Capability[] { Capability.CREATE, Capability.DELETE, Capability.GET_TYPE, Capability.LIST_CHILDREN,
139                 Capability.READ_CONTENT, Capability.WRITE_CONTENT };
140     }
141 
142     /**
143      * Tests overwriting a file on the same file system.
144      */
145     @Test
146     public void testCopyFromOverwriteSameFileSystem() throws Exception {
147         final FileObject scratchFolder = createScratchFolder();
148 
149         // Create direct child of the test folder
150         final FileObject file = scratchFolder.resolveFile("file1.txt");
151         assertFalse(file.exists());
152 
153         // Create the source file
154         final String content = "Here is some sample content for the file.  Blah Blah Blah.";
155         try (OutputStream os = file.getContent().getOutputStream()) {
156             os.write(content.getBytes(StandardCharsets.UTF_8));
157         }
158 
159         assertSameContent(content, file);
160 
161         // Make sure we can copy the new file to another file on the same filesystem
162         final FileObject fileCopy = scratchFolder.resolveFile("file1copy.txt");
163         assertFalse(fileCopy.exists());
164         fileCopy.copyFrom(file, Selectors.SELECT_SELF);
165 
166         assertSameContent(content, fileCopy);
167 
168         // Make sure we can copy the same new file to the same target file on the same filesystem
169         assertTrue(fileCopy.exists());
170         fileCopy.copyFrom(file, Selectors.SELECT_SELF);
171 
172         assertSameContent(content, fileCopy);
173     }
174 
175     /**
176      * Tests file copy to and from the same file system type. This was a problem w/ FTP.
177      */
178     @Test
179     public void testCopySameFileSystem() throws Exception {
180         final FileObject scratchFolder = createScratchFolder();
181 
182         // Create direct child of the test folder
183         final FileObject file = scratchFolder.resolveFile("file1.txt");
184         assertFalse(file.exists());
185 
186         // Create the source file
187         final String content = "Here is some sample content for the file.  Blah Blah Blah.";
188         try (OutputStream os = file.getContent().getOutputStream()) {
189             os.write(content.getBytes(StandardCharsets.UTF_8));
190         }
191 
192         assertSameContent(content, file);
193 
194         // Make sure we can copy the new file to another file on the same filesystem
195         final FileObject fileCopy = scratchFolder.resolveFile("file1copy.txt");
196         assertFalse(fileCopy.exists());
197         fileCopy.copyFrom(file, Selectors.SELECT_SELF);
198 
199         assertSameContent(content, fileCopy);
200     }
201 
202     /**
203      * Tests create-delete-create-a-file sequence on the same file system.
204      */
205     @Test
206     public void testCreateDeleteCreateSameFileSystem() throws Exception {
207         final FileObject scratchFolder = createScratchFolder();
208 
209         // Create direct child of the test folder
210         final FileObject file = scratchFolder.resolveFile("file1.txt");
211         assertFalse(file.exists());
212 
213         // Create the source file
214         final String content = "Here is some sample content for the file.  Blah Blah Blah.";
215         try (OutputStream os = file.getContent().getOutputStream()) {
216             os.write(content.getBytes(StandardCharsets.UTF_8));
217         }
218 
219         assertSameContent(content, file);
220 
221         // Make sure we can copy the new file to another file on the same filesystem
222         final FileObject fileCopy = scratchFolder.resolveFile("file1copy.txt");
223         assertFalse(fileCopy.exists());
224         fileCopy.copyFrom(file, Selectors.SELECT_SELF);
225 
226         assertSameContent(content, fileCopy);
227 
228         // Delete the file.
229         assertTrue(fileCopy.exists());
230         assertTrue(fileCopy.delete());
231 
232         // Make sure we can copy the same new file to the same target file on the same filesystem
233         assertFalse(fileCopy.exists());
234         fileCopy.copyFrom(file, Selectors.SELECT_SELF);
235 
236         assertSameContent(content, fileCopy);
237     }
238 
239     /*
240       Tests concurrent read and write on the same file fails.
241      */
242     /*
243      * imario@apache.org leave this to some sort of LockManager public void testConcurrentReadWrite() throws Exception {
244      * final FileObject scratchFolder = createScratchFolder();
245      *
246      * final FileObject file = scratchFolder.resolveFile("file1.txt"); file.createFile();
247      *
248      * // Start reading from the file final InputStream instr = file.getContent().getInputStream();
249      *
250      * try { // Try to write to the file file.getContent().getOutputStream(); fail(); } catch (final FileSystemException
251      * e) { // Check error message assertSameMessage("vfs.provider/write-in-use.error", file, e); } finally {
252      * instr.close(); } }
253      */
254 
255     /*
256       Tests concurrent writes on the same file fails.
257      */
258     /*
259      * imario@apache.org leave this to some sort of LockManager public void testConcurrentWrite() throws Exception {
260      * final FileObject scratchFolder = createScratchFolder();
261      *
262      * final FileObject file = scratchFolder.resolveFile("file1.txt"); file.createFile();
263      *
264      * // Start writing to the file final OutputStream outstr = file.getContent().getOutputStream(); final String
265      * testContent = "some content"; try { // Write some content to the first stream
266      * outstr.write(testContent.getBytes());
267      *
268      * // Try to open another output stream file.getContent().getOutputStream(); fail(); } catch (final
269      * FileSystemException e) { // Check error message assertSameMessage("vfs.provider/write-in-use.error", file, e); }
270      * finally { outstr.close(); }
271      *
272      * // Make sure that the content written to the first stream is actually applied assertSameContent(testContent,
273      * file); }
274      */
275 
276     /**
277      * Tests deletion
278      */
279     @Test
280     public void testDelete() throws Exception {
281         // Set-up the test structure
282         final FileObject folder = createScratchFolder();
283         folder.resolveFile("file1.txt").createFile();
284         folder.resolveFile("file%25.txt").createFile();
285         folder.resolveFile("emptydir").createFolder();
286         folder.resolveFile("dir1/file1.txt").createFile();
287         folder.resolveFile("dir1/dir2/file2.txt").createFile();
288 
289         // Delete a file
290         FileObject file = folder.resolveFile("file1.txt");
291         assertTrue(file.exists());
292         file.deleteAll();
293         assertFalse(file.exists());
294 
295         // Delete a special name file
296         file = folder.resolveFile("file%25.txt");
297         assertTrue(file.exists());
298         file.deleteAll();
299         assertFalse(file.exists());
300 
301         // Delete an empty folder
302         file = folder.resolveFile("emptydir");
303         assertTrue(file.exists());
304         file.deleteAll();
305         assertFalse(file.exists());
306 
307         // Recursive delete
308         file = folder.resolveFile("dir1");
309         final FileObject file2 = file.resolveFile("dir2/file2.txt");
310         assertTrue(file.exists());
311         assertTrue(file2.exists());
312         file.deleteAll();
313         assertFalse(file.exists());
314         assertFalse(file2.exists());
315 
316         // Delete a file that does not exist
317         file = folder.resolveFile("some-folder/some-file");
318         assertFalse(file.exists());
319         file.deleteAll();
320         assertFalse(file.exists());
321     }
322 
323     /**
324      * Tests deletion
325      */
326     @Test
327     public void testDeleteAllDescendents() throws Exception {
328         // Set-up the test structure
329         final FileObject folder = createScratchFolder();
330         folder.resolveFile("file1.txt").createFile();
331         folder.resolveFile("file%25.txt").createFile();
332         folder.resolveFile("emptydir").createFolder();
333         folder.resolveFile("dir1/file1.txt").createFile();
334         folder.resolveFile("dir1/dir2/file2.txt").createFile();
335 
336         // Delete a file
337         FileObject file = folder.resolveFile("file1.txt");
338         assertTrue(file.exists());
339         file.deleteAll();
340         assertFalse(file.exists());
341 
342         // Delete a special name file
343         file = folder.resolveFile("file%25.txt");
344         assertTrue(file.exists());
345         file.deleteAll();
346         assertFalse(file.exists());
347 
348         // Delete an empty folder
349         file = folder.resolveFile("emptydir");
350         assertTrue(file.exists());
351         file.deleteAll();
352         assertFalse(file.exists());
353 
354         // Recursive delete
355         file = folder.resolveFile("dir1");
356         final FileObject file2 = file.resolveFile("dir2/file2.txt");
357         assertTrue(file.exists());
358         assertTrue(file2.exists());
359         file.deleteAll();
360         assertFalse(file.exists());
361         assertFalse(file2.exists());
362 
363         // Delete a file that does not exist
364         file = folder.resolveFile("some-folder/some-file");
365         assertFalse(file.exists());
366         file.deleteAll();
367         assertFalse(file.exists());
368     }
369 
370     /**
371      * Tests file creation
372      */
373     @Test
374     public void testFileCreate() throws Exception {
375         final FileObject scratchFolder = createScratchFolder();
376 
377         // Create direct child of the test folder
378         FileObject file = scratchFolder.resolveFile("file1.txt");
379         assertFalse(file.exists());
380         file.createFile();
381         assertTrue(file.exists());
382         assertSame(FileType.FILE, file.getType());
383         assertTrue(file.isFile());
384         assertEquals(0, file.getContent().getSize());
385         assertTrue(file.getContent().isEmpty());
386         assertFalse(file.isHidden());
387         assertFalse(file.isSymbolicLink());
388         assertTrue(file.isReadable());
389         assertTrue(file.isWriteable());
390 
391         // Create direct child of the test folder - special name
392         file = scratchFolder.resolveFile("file1%25.txt");
393         assertFalse(file.exists());
394         file.createFile();
395         assertTrue(file.exists());
396         assertSame(FileType.FILE, file.getType());
397         assertTrue(file.isFile());
398         assertEquals(0, file.getContent().getSize());
399         assertFalse(file.isHidden());
400         assertTrue(file.isReadable());
401         assertTrue(file.isWriteable());
402 
403         // Create a descendant, where the intermediate folders don't exist
404         file = scratchFolder.resolveFile("dir1/dir1/file1.txt");
405         assertFalse(file.exists());
406         assertFalse(file.getParent().exists());
407         assertFalse(file.getParent().getParent().exists());
408         file.createFile();
409         assertTrue(file.exists());
410         assertSame(FileType.FILE, file.getType());
411         assertTrue(file.isFile());
412         assertEquals(0, file.getContent().getSize());
413         assertTrue(file.getParent().exists());
414         assertTrue(file.getParent().getParent().exists());
415         assertFalse(file.getParent().isHidden());
416         assertFalse(file.getParent().getParent().isHidden());
417 
418         // Test creating a file that already exists
419         assertTrue(file.exists());
420         file.createFile();
421         assertTrue(file.exists());
422         assertTrue(file.isReadable());
423         assertTrue(file.isWriteable());
424     }
425 
426     /**
427      * Tests file/folder creation with mismatched types.
428      */
429     @Test
430     public void testFileCreateMismatched() throws Exception {
431         final FileObject scratchFolder = createScratchFolder();
432 
433         // Create a test file and folder
434         final FileObject file = scratchFolder.resolveFile("dir1/file1.txt");
435         file.createFile();
436         assertEquals(FileType.FILE, file.getType());
437         assertTrue(file.isFile());
438 
439         final FileObject folder = scratchFolder.resolveFile("dir1/dir2");
440         folder.createFolder();
441         assertEquals(FileType.FOLDER, folder.getType());
442         assertTrue(folder.isFolder());
443 
444         // Attempt to create a file that already exists as a folder
445         try {
446             folder.createFile();
447             fail();
448         } catch (final FileSystemException exc) {
449         }
450 
451         // Attempt to create a folder that already exists as a file
452         try {
453             file.createFolder();
454             fail();
455         } catch (final FileSystemException exc) {
456         }
457 
458         // Attempt to create a folder as a child of a file
459         final FileObject folder2 = file.resolveFile("some-child");
460         try {
461             folder2.createFolder();
462             fail();
463         } catch (final FileSystemException exc) {
464         }
465     }
466 
467     /**
468      * Tests folder creation.
469      */
470     @Test
471     public void testFolderCreate() throws Exception {
472         final FileObject scratchFolder = createScratchFolder();
473 
474         // Create direct child of the test folder
475         FileObject folder = scratchFolder.resolveFile("dir1");
476         assertFalse(folder.exists());
477         folder.createFolder();
478         assertTrue(folder.exists());
479         assertSame(FileType.FOLDER, folder.getType());
480         assertTrue(folder.isFolder());
481         assertEquals(0, folder.getChildren().length);
482 
483         // Create a descendant, where the intermediate folders don't exist
484         folder = scratchFolder.resolveFile("dir2/dir1/dir1");
485         assertFalse(folder.exists());
486         assertFalse(folder.getParent().exists());
487         assertFalse(folder.getParent().getParent().exists());
488         folder.createFolder();
489         assertTrue(folder.exists());
490         assertSame(FileType.FOLDER, folder.getType());
491         assertTrue(folder.isFolder());
492         assertEquals(0, folder.getChildren().length);
493         assertTrue(folder.getParent().exists());
494         assertTrue(folder.getParent().getParent().exists());
495 
496         // Test creating a folder that already exists
497         assertTrue(folder.exists());
498         folder.createFolder();
499     }
500 
501     /**
502      * Tests that test read folder is not hidden.
503      */
504     @Test
505     public void testFolderIsHidden() throws Exception {
506         final FileObject folder = getReadFolderDir1();
507         Assert.assertFalse(folder.isHidden());
508     }
509 
510     /**
511      * Tests that test read folder is readable.
512      */
513     @Test
514     public void testFolderIsReadable() throws Exception {
515         final FileObject folder = getReadFolderDir1();
516         Assert.assertTrue(folder.isReadable());
517     }
518 
519     /**
520      * Tests that test folder iswritable.
521      */
522     @Test
523     public void testFolderIsWritable() throws Exception {
524         final FileObject folder = getWriteFolder().resolveFile("dir1");
525         Assert.assertTrue(folder.isWriteable());
526     }
527 
528     /**
529      * Test that children are handled correctly by create and delete.
530      */
531     @Test
532     public void testListChildren() throws Exception {
533         final FileObject folder = createScratchFolder();
534         final HashSet<String> names = new HashSet<>();
535 
536         // Make sure the folder is empty
537         assertEquals(0, folder.getChildren().length);
538 
539         // Create a child folder
540         folder.resolveFile("dir1").createFolder();
541         names.add("dir1");
542         assertSameFileSet(names, folder.getChildren());
543 
544         // Create a child file
545         folder.resolveFile("file1.html").createFile();
546         names.add("file1.html");
547         assertSameFileSet(names, folder.getChildren());
548 
549         // Create a descendent
550         folder.resolveFile("dir2/file1.txt").createFile();
551         names.add("dir2");
552         assertSameFileSet(names, folder.getChildren());
553 
554         // Create a child file via an output stream
555         final OutputStream outstr = folder.resolveFile("file2.txt").getContent().getOutputStream();
556         outstr.close();
557         names.add("file2.txt");
558         assertSameFileSet(names, folder.getChildren());
559 
560         // Delete a child folder
561         folder.resolveFile("dir1").deleteAll();
562         names.remove("dir1");
563         assertSameFileSet(names, folder.getChildren());
564 
565         // Delete a child file
566         folder.resolveFile("file1.html").deleteAll();
567         names.remove("file1.html");
568         assertSameFileSet(names, folder.getChildren());
569 
570         // Recreate the folder
571         folder.deleteAll();
572         folder.createFolder();
573         assertEquals(0, folder.getChildren().length);
574     }
575 
576     /**
577      * Check listeners are notified of changes.
578      */
579     @Test
580     public void testListener() throws Exception {
581         final FileObject baseFile = createScratchFolder();
582 
583         final FileObject child = baseFile.resolveFile("newfile.txt");
584         assertFalse(child.exists());
585 
586         final FileSystem fs = baseFile.getFileSystem();
587         final TestListener listener = new TestListener(child);
588         fs.addListener(child, listener);
589         try {
590             // Create as a folder
591             listener.addCreateEvent();
592             child.createFolder();
593             listener.assertFinished();
594 
595             // Create the folder again. Should not get an event.
596             child.createFolder();
597 
598             // Delete
599             listener.addDeleteEvent();
600             child.delete();
601             listener.assertFinished();
602 
603             // Delete again. Should not get an event
604             child.delete();
605 
606             // Create as a file
607             listener.addCreateEvent();
608             child.createFile();
609             listener.assertFinished();
610 
611             // Create the file again. Should not get an event
612             child.createFile();
613 
614             listener.addDeleteEvent();
615             child.delete();
616 
617             // Create as a file, by writing to it.
618             listener.addCreateEvent();
619             child.getContent().getOutputStream().close();
620             listener.assertFinished();
621 
622             // Recreate the file by writing to it
623             child.getContent().getOutputStream().close();
624 
625             // Copy another file over the top
626             final FileObject otherChild = baseFile.resolveFile("folder1");
627             otherChild.createFolder();
628             listener.addDeleteEvent();
629             listener.addCreateEvent();
630             child.copyFrom(otherChild, Selectors.SELECT_SELF);
631             listener.assertFinished();
632 
633         } finally {
634             fs.removeListener(child, listener);
635         }
636     }
637 
638     /**
639      * Tests overwriting a file on the same file system.
640      */
641     @Test
642     public void testOverwriteSameFileSystem() throws Exception {
643         final FileObject scratchFolder = createScratchFolder();
644 
645         // Create direct child of the test folder
646         final FileObject file = scratchFolder.resolveFile("file1.txt");
647         assertFalse(file.exists());
648 
649         // Create the source file
650         final String content = "Here is some sample content for the file.  Blah Blah Blah.";
651         try (OutputStream os = file.getContent().getOutputStream()) {
652             os.write(content.getBytes(StandardCharsets.UTF_8));
653         }
654 
655         assertSameContent(content, file);
656 
657         // Make sure we can copy the new file to another file on the same file system
658         final FileObject fileCopy = scratchFolder.resolveFile("file1copy.txt");
659         assertFalse(fileCopy.exists());
660         file.getContent().write(fileCopy);
661 
662         assertSameContent(content, fileCopy);
663 
664         // Make sure we can copy the same new file to the same target file on the same file system
665         assertTrue(fileCopy.exists());
666         file.getContent().write(fileCopy);
667 
668         assertSameContent(content, fileCopy);
669 
670         // Make sure we can copy the same new file to the same target file on the same file system
671         assertTrue(fileCopy.exists());
672         file.getContent().write(fileCopy.getContent());
673 
674         assertSameContent(content, fileCopy);
675 
676         // Make sure we can copy the same new file to the same target file on the same file system
677         assertTrue(fileCopy.exists());
678         OutputStream outputStream = fileCopy.getContent().getOutputStream();
679         try {
680             file.getContent().write(outputStream);
681         } finally {
682             outputStream.close();
683         }
684         assertSameContent(content, fileCopy);
685 
686         // Make sure we can copy the same new file to the same target file on the same file system
687         assertTrue(fileCopy.exists());
688         outputStream = fileCopy.getContent().getOutputStream();
689         try {
690             file.getContent().write(outputStream, 1234);
691         } finally {
692             outputStream.close();
693         }
694         assertSameContent(content, fileCopy);
695     }
696 
697     /**
698      * Tests file write to and from the same file system type
699      */
700     @Test
701     public void testWriteSameFileSystem() throws Exception {
702         final FileObject scratchFolder = createScratchFolder();
703 
704         // Create direct child of the test folder
705         final FileObject fileSource = scratchFolder.resolveFile("file1.txt");
706         assertFalse(fileSource.exists());
707 
708         // Create the source file
709         final String expectedString = "Here is some sample content for the file.  Blah Blah Blah.";
710         try (OutputStream expectedOutputStream = fileSource.getContent().getOutputStream()) {
711             expectedOutputStream.write(expectedString.getBytes(StandardCharsets.UTF_8));
712         }
713 
714         assertSameContent(expectedString, fileSource);
715 
716         // Make sure we can copy the new file to another file on the same filesystem
717         final FileObject fileTarget = scratchFolder.resolveFile("file1copy.txt");
718         assertFalse(fileTarget.exists());
719 
720         final FileContent contentSource = fileSource.getContent();
721         //
722         // Tests FileContent#write(FileContent)
723         contentSource.write(fileTarget.getContent());
724         assertSameContent(expectedString, fileTarget);
725         //
726         // Tests FileContent#write(OutputStream)
727         OutputStream outputStream = fileTarget.getContent().getOutputStream();
728         try {
729             contentSource.write(outputStream);
730         } finally {
731             outputStream.close();
732         }
733         assertSameContent(expectedString, fileTarget);
734         //
735         // Tests FileContent#write(OutputStream, int)
736         outputStream = fileTarget.getContent().getOutputStream();
737         try {
738             contentSource.write(outputStream, 1234);
739         } finally {
740             outputStream.close();
741         }
742         assertSameContent(expectedString, fileTarget);
743     }
744 
745 }