ModelUtils { @Nullable public static File makeFileForPath(@Nullable final String path) { if (path == null || path.isEmpty()) { return null; } if (path.startsWith("file:")) { try { return new File(new URI(normalizeFileURI(path))); } catch (URISyntaxException ex) { LOGGER.error("URISyntaxException for " + path, ex); return null; } } else { return new File(path); } } private  ModelUtils(); static int calcCharsOnStart(final char chr, @Nonnull final String text); static boolean onlyFromChar(@Nonnull final String line, final char chr); @Nonnull @MustNotContainNull static Object[] joinArrays(@Nonnull @MustNotContainNull final Object[]... arrs); @Nonnull static String makePreBlock(@Nonnull final String text); @Nonnull static String escapeTextForPreBlock(@Nonnull final String text); @Nonnull static String makeMDCodeBlock(@Nonnull final String text); @Nonnull static String escapeMarkdownStr(@Nonnull final String text); static int calcMaxLengthOfBacktickQuotesSubstr(@Nullable final String text); static void writeChar(@Nonnull final Appendable out, final char chr, final int times); @Nonnull static String unescapeMarkdownStr(@Nonnull final String text); @Nonnull static String makeShortTextVersion(@Nonnull String text, final int maxLength); static int countLines(@Nonnull final String text); @Nonnull @MustNotContainNull static String[] breakToLines(@Nonnull final String text); @Nonnull static String makeQueryStringForURI(@Nullable final Properties properties); @Nonnull static Properties extractQueryPropertiesFromURI(@Nonnull final URI uri); @Nonnull static String encodeForURI(@Nonnull final String s); @Nullable static File makeFileForPath(@Nullable final String path); @Nonnull static String escapeURIPath(@Nonnull final String text); @Nonnull static String removeISOControls(@Nonnull final String text); @Nullable static URI toURI(@Nullable final Path path); @Nonnull static File toFile(@Nonnull final URI uri); static final Comparator<String> STRING_COMPARATOR; }
@Test public void testMakeFileForPath() throws Exception { assertNull(ModelUtils.makeFileForPath(null)); assertNull(ModelUtils.makeFileForPath("")); assertEquals(new File((File) null, "/some/who/files/2012-11-02 13.47.10.jpg").getCanonicalPath(), ModelUtils.makeFileForPath("file: assertEquals(new File((File) null, "/some/who/files/2012-11-02 13.47.10.jpg").getCanonicalPath(), ModelUtils.makeFileForPath("file: assertEquals(new File((File) null, "/some/who/files/main.c++").getCanonicalPath(), ModelUtils.makeFileForPath("file: assertEquals(new File((File) null, "/some/folder/temp/").getCanonicalPath(), ModelUtils.makeFileForPath("file: if (SystemUtils.IS_OS_LINUX) { assertEquals(new File((File) null, "/some/folder/temp/ :<>?").getCanonicalPath(), ModelUtils.makeFileForPath("file: assertEquals(new File((File) null, "/some/folder&ssd/temp/ :<>?test=jks&lls=1").getCanonicalPath(), ModelUtils.makeFileForPath("file: } assertEquals("src/main/java/com/igormaznitsa/nbmindmap/nb/QuickSearchProvider.java".replace('/', File.separatorChar), ModelUtils.makeFileForPath("src/main/java/com/igormaznitsa/nbmindmap/nb/QuickSearchProvider.java").getPath()); }