22
33import lombok .NonNull ;
44import nbbrd .io .FileFormatter ;
5+ import nbbrd .io .WrappedIOException ;
56import nbbrd .io .function .IOSupplier ;
67
78import java .io .File ;
1112import java .nio .channels .Channels ;
1213import java .nio .channels .FileChannel ;
1314import java .nio .channels .FileLock ;
15+ import java .nio .channels .OverlappingFileLockException ;
1416import java .nio .file .Path ;
1517import java .nio .file .StandardOpenOption ;
1618
@@ -26,6 +28,8 @@ public void formatFile(@NonNull T value, @NonNull File target) throws IOExceptio
2628 try (FileOutputStream stream = new FileOutputStream (checkTarget (target ))) {
2729 try (FileLock ignore = stream .getChannel ().lock ()) {
2830 delegate .formatStream (value , stream );
31+ } catch (OverlappingFileLockException ex ) {
32+ throw WrappedIOException .wrap (ex );
2933 }
3034 }
3135 }
@@ -35,6 +39,8 @@ public void formatPath(@NonNull T value, @NonNull Path target) throws IOExceptio
3539 try (FileChannel channel = FileChannel .open (checkTarget (target ), StandardOpenOption .WRITE , StandardOpenOption .CREATE )) {
3640 try (FileLock ignore = channel .lock ()) {
3741 delegate .formatStream (value , Channels .newOutputStream (channel ));
42+ } catch (OverlappingFileLockException ex ) {
43+ throw WrappedIOException .wrap (ex );
3844 }
3945 }
4046 }
0 commit comments