48
48
import java .io .IOException ;
49
49
import java .io .InputStream ;
50
50
import java .io .InputStreamReader ;
51
+ import java .io .PrintWriter ;
52
+ import java .io .StringWriter ;
51
53
import java .net .URI ;
52
54
import java .nio .ByteBuffer ;
53
55
import java .nio .channels .SeekableByteChannel ;
@@ -98,6 +100,13 @@ final class VirtualFileSystemImpl implements FileSystem, AutoCloseable {
98
100
consoleHandler .setFormatter (new SimpleFormatter () {
99
101
@ Override
100
102
public synchronized String format (LogRecord lr ) {
103
+ if (lr .getThrown () != null ) {
104
+ StringWriter sw = new StringWriter ();
105
+ PrintWriter pw = new PrintWriter (sw );
106
+ lr .getThrown ().printStackTrace (pw );
107
+ pw .close ();
108
+ return String .format ("%s: %s\n %s" , lr .getLevel ().getName (), lr .getMessage (), sw .toString ());
109
+ }
101
110
return String .format ("%s: %s\n " , lr .getLevel ().getName (), lr .getMessage ());
102
111
}
103
112
});
@@ -620,12 +629,12 @@ public void checkAccess(Path p, Set<? extends AccessMode> modes, LinkOption... l
620
629
621
630
Path path = toAbsolutePathInternal (p );
622
631
if (!pathIsInVfs (path )) {
623
- boolean passed = false ;
624
632
try {
625
633
delegate .checkAccess (path , modes , linkOptions );
626
- passed = true ;
627
- } finally {
628
- finest ("VFS.checkAccess delegated '%s' %s and " , path , passed ? "passed" : "did not pass" );
634
+ finest ("VFS.checkAccess delegated '%s'" , path );
635
+ } catch (Throwable t ) {
636
+ finest (t , "VFS.checkAccess delegated '%s'" , path );
637
+ throw t ;
629
638
}
630
639
} else {
631
640
if (modes .contains (AccessMode .WRITE )) {
@@ -647,11 +656,12 @@ public void createDirectory(Path d, FileAttribute<?>... attrs) throws IOExceptio
647
656
648
657
Path dir = toAbsolutePathInternal (d );
649
658
if (!pathIsInVfs (dir )) {
650
- boolean passed = false ;
651
659
try {
652
660
delegate .createDirectory (dir , attrs );
653
- } finally {
654
- finest ("VFS.createDirectory delegated '%s' %s" , dir , passed ? "passed" : "did not pass" );
661
+ finest ("VFS.createDirectory delegated '%s'" , dir );
662
+ } catch (Throwable t ) {
663
+ finest (t , "VFS.createDirectory delegated '%s'" , dir );
664
+ throw t ;
655
665
}
656
666
} else {
657
667
throw securityException ("VFS.createDirectory" , String .format ("read-only filesystem, create directory not supported '%s'" , dir ));
@@ -664,11 +674,12 @@ public void delete(Path p) throws IOException {
664
674
665
675
Path path = toAbsolutePathInternal (p );
666
676
if (!pathIsInVfs (path )) {
667
- boolean passed = false ;
668
677
try {
669
678
delegate .delete (path );
670
- } finally {
671
- finest ("VFS.delete delegated '%s' %s" , path , passed ? "passed" : "did not pass" );
679
+ finest ("VFS.delete delegated '%s'" , path );
680
+ } catch (Throwable t ) {
681
+ finest (t , "VFS.delete delegated '%s'" , path );
682
+ throw t ;
672
683
}
673
684
} else {
674
685
throw securityException ("VFS.delete" , String .format ("read-only filesystem, delete not supported: '%s'" , path ));
@@ -683,11 +694,13 @@ public SeekableByteChannel newByteChannel(Path p, Set<? extends OpenOption> opti
683
694
684
695
Path path = toAbsolutePathInternal (p );
685
696
if (!pathIsInVfs (path )) {
686
- boolean passed = false ;
687
697
try {
688
- return delegate .newByteChannel (path , options , attrs );
689
- } finally {
690
- finest ("VFS.newByteChannel delegated '%s' %s" , path , passed ? "passed" : "did not pass" );
698
+ SeekableByteChannel ret = delegate .newByteChannel (path , options , attrs );
699
+ finest ("VFS.newByteChannel delegated '%s'" , path );
700
+ return ret ;
701
+ } catch (Throwable t ) {
702
+ finest (t , "VFS.newByteChannel delegated '%s'" , path );
703
+ throw t ;
691
704
}
692
705
}
693
706
@@ -775,11 +788,13 @@ public DirectoryStream<Path> newDirectoryStream(Path d, DirectoryStream.Filter<?
775
788
Objects .requireNonNull (d );
776
789
Path dir = toAbsolutePathInternal (d );
777
790
if (!pathIsInVfs (dir )) {
778
- boolean passed = false ;
779
791
try {
780
- return delegate .newDirectoryStream (dir , filter );
781
- } finally {
782
- finest ("VFS.newDirectoryStream delegated '%s' %s" , dir , passed ? "passed" : "did not pass" );
792
+ DirectoryStream <Path > ret = delegate .newDirectoryStream (dir , filter );
793
+ finest ("VFS.newDirectoryStream delegated '%s'" , d );
794
+ return ret ;
795
+ } catch (Throwable t ) {
796
+ finest (t , "VFS.newDirectoryStream delegated '%s'" , d );
797
+ throw t ;
783
798
}
784
799
}
785
800
Objects .requireNonNull (filter );
@@ -855,9 +870,14 @@ public Path toRealPath(Path p, LinkOption... linkOptions) throws IOException {
855
870
Path path = toAbsolutePathInternal (p );
856
871
boolean pathIsInVFS = pathIsInVfs (path );
857
872
if (!pathIsInVFS ) {
858
- Path ret = delegate .toRealPath (path , linkOptions );
859
- finest ("VFS.toRealPath delegated '%s' -> '%s'" , path , ret );
860
- return ret ;
873
+ try {
874
+ Path ret = delegate .toRealPath (path , linkOptions );
875
+ finest ("VFS.toRealPath delegated '%s' -> '%s'" , path , ret );
876
+ return ret ;
877
+ } catch (Throwable t ) {
878
+ finest (t , "VFS.toRealPath delegated '%s'" , path );
879
+ throw t ;
880
+ }
861
881
} else {
862
882
Path result = path ;
863
883
if (shouldExtract (path )) {
@@ -878,9 +898,14 @@ public Map<String, Object> readAttributes(Path p, String attributes, LinkOption.
878
898
879
899
Path path = toAbsolutePathInternal (p );
880
900
if (!pathIsInVfs (path )) {
881
- Map <String , Object > ret = delegate .readAttributes (path , attributes , options );
882
- finest ("VFS.readAttributes delegated '%s' -> '%s'" , path , ret );
883
- return ret ;
901
+ try {
902
+ Map <String , Object > ret = delegate .readAttributes (path , attributes , options );
903
+ finest ("VFS.readAttributes delegated '%s' -> '%s'" , path , ret );
904
+ return ret ;
905
+ } catch (Throwable t ) {
906
+ finest (t , "VFS.readAttributes delegated '%s'" , path );
907
+ throw t ;
908
+ }
884
909
}
885
910
BaseEntry entry = getEntry (path );
886
911
if (entry == null ) {
@@ -933,7 +958,13 @@ public void setCurrentWorkingDirectory(Path d) {
933
958
}
934
959
} else {
935
960
if (delegate != null ) {
936
- delegate .setCurrentWorkingDirectory (dir );
961
+ try {
962
+ delegate .setCurrentWorkingDirectory (dir );
963
+ finest ("VFS.setCurrentWorkingDirectory delegated '%s'" , d );
964
+ } catch (Throwable t ) {
965
+ finest (t , "VFS.setCurrentWorkingDirectory delegated '%s'" , d );
966
+ throw t ;
967
+ }
937
968
} else {
938
969
// allow so that we can resolve relative paths pointing from real FS to VFS
939
970
// {cwd}/real/fs/../ ... /../vfs_root
@@ -952,10 +983,16 @@ public void copy(Path s, Path t, CopyOption... options) throws IOException {
952
983
if (pathIsInVfs (target )) {
953
984
throw securityException ("VFS.move" , String .format ("read-only filesystem, can't copy '%s' to '%s'" , source , target ));
954
985
} else {
955
- if (allowHostIO == READ_WRITE && pathIsInVfs (source )) {
956
- FileSystem .super .copy (source , target , options );
957
- } else {
958
- delegate .copy (source , target , options );
986
+ try {
987
+ if (allowHostIO == READ_WRITE && pathIsInVfs (source )) {
988
+ FileSystem .super .copy (source , target , options );
989
+ } else {
990
+ delegate .copy (source , target , options );
991
+ }
992
+ finest ("VFS.copy delegated '%s' '%s'" , source , target );
993
+ } catch (Throwable thr ) {
994
+ finest (thr , "VFS.copy delegated '%s' '%s'" , source , target );
995
+ throw thr ;
959
996
}
960
997
}
961
998
}
@@ -967,7 +1004,12 @@ public void move(Path s, Path t, CopyOption... options) throws IOException {
967
1004
Path source = toAbsolutePathInternal (s );
968
1005
Path target = toAbsolutePathInternal (t );
969
1006
if (!pathIsInVfs (source ) && !pathIsInVfs (target )) {
970
- delegate .move (source , target , options );
1007
+ try {
1008
+ delegate .move (source , target , options );
1009
+ } catch (Throwable thr ) {
1010
+ finest (thr , "VFS.move delegated '%s' '%s'" , source , target );
1011
+ throw thr ;
1012
+ }
971
1013
} else {
972
1014
throw securityException ("VFS.move" , String .format ("read-only filesystem, can't move '%s' to '%s'" , source , target ));
973
1015
}
@@ -978,7 +1020,14 @@ public Charset getEncoding(Path p) {
978
1020
Objects .requireNonNull (p );
979
1021
Path path = toAbsolutePathInternal (p );
980
1022
if (!pathIsInVfs (path )) {
981
- return delegate .getEncoding (path );
1023
+ try {
1024
+ Charset ret = delegate .getEncoding (path );
1025
+ finest ("VFS.getEncoding delegated '%s'" , path );
1026
+ return ret ;
1027
+ } catch (Throwable t ) {
1028
+ finest (t , "VFS.getEncoding delegated '%s'" , path );
1029
+ throw t ;
1030
+ }
982
1031
} else {
983
1032
return null ;
984
1033
}
@@ -991,7 +1040,13 @@ public void createSymbolicLink(Path l, Path t, FileAttribute<?>... attrs) throws
991
1040
Path link = toAbsolutePathInternal (l );
992
1041
Path target = toAbsolutePathInternal (t );
993
1042
if (!pathIsInVfs (link ) && !pathIsInVfs (target )) {
994
- delegate .createSymbolicLink (link , target , attrs );
1043
+ try {
1044
+ delegate .createSymbolicLink (link , target , attrs );
1045
+ finest ("VFS.createSymbolicLink delegated '%s' '%s'" , link , target );
1046
+ } catch (Throwable thr ) {
1047
+ finest (thr , "VFS.createSymbolicLink delegated '%s' '%s'" , link , target );
1048
+ throw thr ;
1049
+ }
995
1050
} else {
996
1051
throw securityException ("VFS.createSymbolicLink" , String .format ("read-only filesystem, can't create symbolic link from '%s' to '%s'" , link , target ));
997
1052
}
@@ -1004,7 +1059,13 @@ public void createLink(Path l, Path e) throws IOException {
1004
1059
Path link = toAbsolutePathInternal (l );
1005
1060
Path existing = toAbsolutePathInternal (e );
1006
1061
if (!pathIsInVfs (link ) && !pathIsInVfs (existing )) {
1007
- delegate .createLink (link , existing );
1062
+ try {
1063
+ delegate .createLink (link , existing );
1064
+ finest ("VFS.createLink delegated '%s' '%s'" , link , existing );
1065
+ } catch (Throwable thr ) {
1066
+ finest (thr , "VFS.createLink delegated '%s' '%s'" , link , existing );
1067
+ throw thr ;
1068
+ }
1008
1069
} else {
1009
1070
throw securityException ("VFS.createLink" , String .format ("read-only filesystem, can't create link '%s' to '%s'" , link , existing ));
1010
1071
}
@@ -1015,7 +1076,14 @@ public Path readSymbolicLink(Path l) throws IOException {
1015
1076
Objects .requireNonNull (l );
1016
1077
Path link = toAbsolutePathInternal (l );
1017
1078
if (!pathIsInVfs (link )) {
1018
- return delegate .readSymbolicLink (link );
1079
+ try {
1080
+ Path ret = delegate .readSymbolicLink (link );
1081
+ finest ("VFS.readSymbolicLink delegated '%s' '%s'" , link , ret );
1082
+ return ret ;
1083
+ } catch (Throwable t ) {
1084
+ finest (t , "VFS.readSymbolicLink delegated '%s'" , link );
1085
+ throw t ;
1086
+ }
1019
1087
} else {
1020
1088
throw securityException ("VFS.readSymbolicLink" , String .format ("reading symbolic links in VirtualFileSystem not supported %s" , link ));
1021
1089
}
@@ -1026,7 +1094,13 @@ public void setAttribute(Path p, String attribute, Object value, LinkOption... o
1026
1094
Objects .requireNonNull (p );
1027
1095
Path path = toAbsolutePathInternal (p );
1028
1096
if (!pathIsInVfs (path )) {
1029
- delegate .setAttribute (path , attribute , value , options );
1097
+ try {
1098
+ delegate .setAttribute (path , attribute , value , options );
1099
+ finest ("VFS.setAttribute delegated '%s' '%s'" , path , attribute );
1100
+ } catch (Throwable t ) {
1101
+ finest (t , "VFS.setAttribute delegated '%s' '%s'" , path , attribute );
1102
+ throw t ;
1103
+ }
1030
1104
} else {
1031
1105
throw securityException ("VFS.setAttribute" , String .format ("read-only filesystem, can't set attribute '%s' for '%s" , attribute , p ));
1032
1106
}
@@ -1037,14 +1111,28 @@ public String getMimeType(Path p) {
1037
1111
Objects .requireNonNull (p );
1038
1112
Path path = toAbsolutePathInternal (p );
1039
1113
if (!pathIsInVfs (path )) {
1040
- return delegate .getMimeType (path );
1114
+ try {
1115
+ String ret = delegate .getMimeType (path );
1116
+ finest ("VFS.getMimeType delegated '%s' '%s" , path , ret );
1117
+ return ret ;
1118
+ } catch (Throwable t ) {
1119
+ finest (t , "VFS.getMimeType delegated '%s'" , path );
1120
+ throw t ;
1121
+ }
1041
1122
}
1042
1123
return null ;
1043
1124
}
1044
1125
1045
1126
@ Override
1046
1127
public Path getTempDirectory () {
1047
- return delegate .getTempDirectory ();
1128
+ try {
1129
+ Path ret = delegate .getTempDirectory ();
1130
+ finest ("VFS.getTempDirectory delegated '%s'" , ret );
1131
+ return ret ;
1132
+ } catch (Throwable t ) {
1133
+ finest (t , "VFS.getTempDirectory delegated" );
1134
+ throw t ;
1135
+ }
1048
1136
}
1049
1137
1050
1138
private static void warn (String msgFormat , Object ... args ) {
@@ -1071,6 +1159,12 @@ private static void finest(String msgFormat, Object... args) {
1071
1159
}
1072
1160
}
1073
1161
1162
+ private static void finest (Throwable t , String msgFormat , Object ... args ) {
1163
+ if (LOGGER .isLoggable (Level .FINEST )) {
1164
+ LOGGER .log (Level .FINEST , String .format (msgFormat , args ), t );
1165
+ }
1166
+ }
1167
+
1074
1168
private static SecurityException securityException (String from , String msg ) {
1075
1169
finer ("%s %s" , from , msg );
1076
1170
throw new SecurityException (msg );
0 commit comments