@@ -358,95 +358,6 @@ public void setUp() throws Exception {
358358 }
359359 }
360360
361- @ Test
362- public void test_openInputStream_exists () throws Exception {
363- final File file = new File (tempDirFile , "test.txt" );
364- TestUtils .createLineFileUtf8 (file , new String []{"Hello" });
365- try (FileInputStream in = FileUtils .openInputStream (file )) {
366- assertEquals ('H' , in .read ());
367- }
368- }
369-
370- @ Test
371- public void test_openInputStream_existsButIsDirectory () {
372- final File directory = new File (tempDirFile , "subdir" );
373- directory .mkdirs ();
374- assertThrows (IOException .class , () -> FileUtils .openInputStream (directory ));
375- }
376-
377- @ Test
378- public void test_openInputStream_notExists () {
379- final File directory = new File (tempDirFile , "test.txt" );
380- assertThrows (IOException .class , () -> FileUtils .openInputStream (directory ));
381- }
382-
383- @ Test
384- public void test_openOutputStream_exists () throws Exception {
385- final File file = new File (tempDirFile , "test.txt" );
386- TestUtils .createLineFileUtf8 (file , new String []{"Hello" });
387- try (FileOutputStream out = FileUtils .openOutputStream (file )) {
388- out .write (0 );
389- }
390- assertTrue (file .exists ());
391- }
392-
393- @ Test
394- public void test_openOutputStream_existsButIsDirectory () {
395- final File directory = new File (tempDirFile , "subdir" );
396- directory .mkdirs ();
397- assertThrows (IllegalArgumentException .class , () -> FileUtils .openOutputStream (directory ));
398- }
399-
400- /**
401- * Requires admin privileges on Windows.
402- *
403- * @throws Exception For example java.nio.file.FileSystemException:
404- * C:\Users\you\AppData\Local\Temp\junit2324629522183300191\FileUtilsTest8613879743106252609\symlinked-dir: A required privilege is
405- * not held by the client.
406- */
407- @ Test
408- public void test_openOutputStream_intoExistingSymlinkedDir () throws Exception {
409- final Path symlinkedDir = createTempSymbolicLinkedRelativeDir ().getLeft ();
410- final File file = symlinkedDir .resolve ("test.txt" ).toFile ();
411- try (FileOutputStream out = FileUtils .openOutputStream (file )) {
412- out .write (0 );
413- }
414- assertTrue (file .exists ());
415- }
416-
417- @ Test
418- public void test_openOutputStream_noParentCreateFile () throws Exception {
419- openOutputStream_noParent (true );
420- }
421-
422- @ Test
423- public void test_openOutputStream_noParentNoFile () throws Exception {
424- openOutputStream_noParent (false );
425- }
426-
427- @ Test
428- public void test_openOutputStream_notExists () throws Exception {
429- final File file = new File (tempDirFile , "a/test.txt" );
430- try (FileOutputStream out = FileUtils .openOutputStream (file )) {
431- out .write (0 );
432- }
433- assertTrue (file .exists ());
434- }
435-
436- @ Test
437- public void test_openOutputStream_notExistsCannotCreate () {
438- // according to Wikipedia, most filing systems have a 256 limit on filename
439- final String longStr =
440- "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
441- "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
442- "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
443- "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
444- "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
445- "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" ; // 300 chars
446- final File file = new File (tempDirFile , "a/" + longStr + "/test.txt" );
447- assertThrows (IOException .class , () -> FileUtils .openOutputStream (file ));
448- }
449-
450361 // byteCountToDisplaySize
451362 @ Test
452363 public void testByteCountToDisplaySizeBigInteger () {
@@ -2765,6 +2676,95 @@ public void testMoveToDirectory_Errors() throws Exception {
27652676
27662677 }
27672678
2679+ @ Test
2680+ public void testOpenInputStream_exists () throws Exception {
2681+ final File file = new File (tempDirFile , "test.txt" );
2682+ TestUtils .createLineFileUtf8 (file , new String []{"Hello" });
2683+ try (FileInputStream in = FileUtils .openInputStream (file )) {
2684+ assertEquals ('H' , in .read ());
2685+ }
2686+ }
2687+
2688+ @ Test
2689+ public void testOpenInputStream_existsButIsDirectory () {
2690+ final File directory = new File (tempDirFile , "subdir" );
2691+ directory .mkdirs ();
2692+ assertThrows (IOException .class , () -> FileUtils .openInputStream (directory ));
2693+ }
2694+
2695+ @ Test
2696+ public void testOpenInputStream_notExists () {
2697+ final File directory = new File (tempDirFile , "test.txt" );
2698+ assertThrows (IOException .class , () -> FileUtils .openInputStream (directory ));
2699+ }
2700+
2701+ @ Test
2702+ public void testOpenOutputStream_exists () throws Exception {
2703+ final File file = new File (tempDirFile , "test.txt" );
2704+ TestUtils .createLineFileUtf8 (file , new String []{"Hello" });
2705+ try (FileOutputStream out = FileUtils .openOutputStream (file )) {
2706+ out .write (0 );
2707+ }
2708+ assertTrue (file .exists ());
2709+ }
2710+
2711+ @ Test
2712+ public void testOpenOutputStream_existsButIsDirectory () {
2713+ final File directory = new File (tempDirFile , "subdir" );
2714+ directory .mkdirs ();
2715+ assertThrows (IllegalArgumentException .class , () -> FileUtils .openOutputStream (directory ));
2716+ }
2717+
2718+ /**
2719+ * Requires admin privileges on Windows.
2720+ *
2721+ * @throws Exception For example java.nio.file.FileSystemException:
2722+ * C:\Users\you\AppData\Local\Temp\junit2324629522183300191\FileUtilsTest8613879743106252609\symlinked-dir: A required privilege is
2723+ * not held by the client.
2724+ */
2725+ @ Test
2726+ public void testOpenOutputStream_intoExistingSymlinkedDir () throws Exception {
2727+ final Path symlinkedDir = createTempSymbolicLinkedRelativeDir ().getLeft ();
2728+ final File file = symlinkedDir .resolve ("test.txt" ).toFile ();
2729+ try (FileOutputStream out = FileUtils .openOutputStream (file )) {
2730+ out .write (0 );
2731+ }
2732+ assertTrue (file .exists ());
2733+ }
2734+
2735+ @ Test
2736+ public void testOpenOutputStream_noParentCreateFile () throws Exception {
2737+ openOutputStream_noParent (true );
2738+ }
2739+
2740+ @ Test
2741+ public void testOpenOutputStream_noParentNoFile () throws Exception {
2742+ openOutputStream_noParent (false );
2743+ }
2744+
2745+ @ Test
2746+ public void testOpenOutputStream_notExists () throws Exception {
2747+ final File file = new File (tempDirFile , "a/test.txt" );
2748+ try (FileOutputStream out = FileUtils .openOutputStream (file )) {
2749+ out .write (0 );
2750+ }
2751+ assertTrue (file .exists ());
2752+ }
2753+
2754+ @ Test
2755+ public void testOpenOutputStream_notExistsCannotCreate () {
2756+ // according to Wikipedia, most filing systems have a 256 limit on filename
2757+ final String longStr =
2758+ "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
2759+ "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
2760+ "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
2761+ "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
2762+ "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
2763+ "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" ; // 300 chars
2764+ final File file = new File (tempDirFile , "a/" + longStr + "/test.txt" );
2765+ assertThrows (IOException .class , () -> FileUtils .openOutputStream (file ));
2766+ }
2767+
27682768 @ Test
27692769 public void testReadFileToByteArray () throws Exception {
27702770 final File file = new File (tempDirFile , "read.txt" );
0 commit comments