static String shortenPathName ( Path path , int bytes ) { String pathString = path . toUri ( ) . getPath ( ) ; String replaced = pathString . replace ( "/" , "_" ) ; if ( replaced . length ( ) <= bytes ) { return replaced ; } int bytesPerHalf = ( bytes - 3 ) / 2 ; return replaced . substring ( 0 , bytesPerHalf ) + "..." + replaced . substring ( replaced . length ( ) - bytesPerHalf ) ; }
Shorten an absolute path into a sanitized String of length at most bytes . This is useful for including a summary of an absolute path in a file name .