FileUtils { public static String shortenPath(String path) { File f = new File(path); String name = f.getName(); return Splitter.on(File.separator) .splitToStream(path) .map( s -> { if (s.isEmpty() || s.equals(name)) { return s; } return s.substring(0, 1); }) .collect(Collectors.joining(File.separator)); }  static boolean isJavaFile(final File file); @SuppressWarnings("try") static String getChecksum(final File file); static List<File> listJavaFiles(File parent); @SuppressWarnings("try") static List<File> collectFiles(final File root, final String ext); @SuppressWarnings("try") static Optional<File> collectFile(final File root, final String ext); static boolean filterFile(final File file); @SuppressWarnings("try") static Optional<String> findProjectID(final File root, final String target); static String getVersionInfo(); @SuppressWarnings("try") static Optional<File> getSourceFile(final String importClass, final Set<File> sourceRoots); @SuppressWarnings("try") static Optional<File> getClassFile(
      String path, final Set<File> sourceRoots, final File out); @SuppressWarnings("try") static Collection<File> getPackagePrivateSource(final List<File> compileFiles); @SuppressWarnings("try") static List<File> getModifiedSources(
      final File projectRoot,
      final List<File> sourceFiles,
      final Set<File> sourceRoots,
      final File output); @SuppressWarnings("try") static List<String> readLines(File file); @SuppressWarnings("try") static void readRangeLines(File file, long start, long end, Consumer<String> fn); @SuppressWarnings("try") static void formatJavaFile(final Properties properties, final String path); @SuppressWarnings("try") static void formatJavaFile(final String path); static Properties loadPropertiesFile(final File file); @SuppressWarnings("try") static Optional<File> existsFQCN(final Set<File> roots, final String fqcn); @SuppressWarnings("try") static Optional<Source> getSource(final File file); @SuppressWarnings("try") static Optional<String> convertPathToClass(final Set<File> roots, final File file); static String shortenPath(String path); static final String JAVA_EXT; static final String JAR_EXT; static final String CLASS_EXT; }
@Test public void testShortenPath() throws Exception { String s = FileUtils.shortenPath("/foo/bar/Test.java"); assertEquals("/f/b/Test.java", s); }