@Test public void canWriteDir() { File file = dirForStaticTests.toFile(); assertThat(file.exists()); assertThat(DiskCache2.canWrite(file)); }
public static boolean canWrite(File f) { Path path = f.toPath().toAbsolutePath(); try { if (Files.isDirectory(path)) { Files.delete(Files.createTempFile(path, "check", null)); } else if (Files.isRegularFile(path)) { Files.newOutputStream(path, StandardOpenOption.APPEND).close(); } else { Files.delete(Files.createTempFile(path.getParent(), "check", null)); } } catch (IOException | SecurityException e) { return false; } return true; }
DiskCache2 { public static boolean canWrite(File f) { Path path = f.toPath().toAbsolutePath(); try { if (Files.isDirectory(path)) { Files.delete(Files.createTempFile(path, "check", null)); } else if (Files.isRegularFile(path)) { Files.newOutputStream(path, StandardOpenOption.APPEND).close(); } else { Files.delete(Files.createTempFile(path.getParent(), "check", null)); } } catch (IOException | SecurityException e) { return false; } return true; } }
DiskCache2 { public static boolean canWrite(File f) { Path path = f.toPath().toAbsolutePath(); try { if (Files.isDirectory(path)) { Files.delete(Files.createTempFile(path, "check", null)); } else if (Files.isRegularFile(path)) { Files.newOutputStream(path, StandardOpenOption.APPEND).close(); } else { Files.delete(Files.createTempFile(path.getParent(), "check", null)); } } catch (IOException | SecurityException e) { return false; } return true; } private  DiskCache2();  DiskCache2(String root, boolean reletiveToHome, int persistMinutes, int scourEveryMinutes); }
DiskCache2 { public static boolean canWrite(File f) { Path path = f.toPath().toAbsolutePath(); try { if (Files.isDirectory(path)) { Files.delete(Files.createTempFile(path, "check", null)); } else if (Files.isRegularFile(path)) { Files.newOutputStream(path, StandardOpenOption.APPEND).close(); } else { Files.delete(Files.createTempFile(path.getParent(), "check", null)); } } catch (IOException | SecurityException e) { return false; } return true; } private  DiskCache2();  DiskCache2(String root, boolean reletiveToHome, int persistMinutes, int scourEveryMinutes); static void exit(); static DiskCache2 getDefault(); static DiskCache2 getNoop(); void setRootDirectory(String cacheDir); String getRootDirectory(); File getCacheFile(String fileLocation); File getFile(String fileLocation); static boolean canWrite(File f); File getExistingFileOrCache(String fileLocation); synchronized File createUniqueFile(String prefix, String suffix); void setPolicy(CachePathPolicy cachePathPolicy); void setCachePathPolicy(CachePathPolicy cachePathPolicy, String cachePathPolicyParam); void setPolicy(String policy); void setAlwaysUseCache(boolean alwaysUseCache); void setNeverUseCache(boolean neverUseCache); void showCache(Formatter f); void cleanCache(File dir, Formatter sbuff, boolean isRoot); @Override String toString(); }
DiskCache2 { public static boolean canWrite(File f) { Path path = f.toPath().toAbsolutePath(); try { if (Files.isDirectory(path)) { Files.delete(Files.createTempFile(path, "check", null)); } else if (Files.isRegularFile(path)) { Files.newOutputStream(path, StandardOpenOption.APPEND).close(); } else { Files.delete(Files.createTempFile(path.getParent(), "check", null)); } } catch (IOException | SecurityException e) { return false; } return true; } private  DiskCache2();  DiskCache2(String root, boolean reletiveToHome, int persistMinutes, int scourEveryMinutes); static void exit(); static DiskCache2 getDefault(); static DiskCache2 getNoop(); void setRootDirectory(String cacheDir); String getRootDirectory(); File getCacheFile(String fileLocation); File getFile(String fileLocation); static boolean canWrite(File f); File getExistingFileOrCache(String fileLocation); synchronized File createUniqueFile(String prefix, String suffix); void setPolicy(CachePathPolicy cachePathPolicy); void setCachePathPolicy(CachePathPolicy cachePathPolicy, String cachePathPolicyParam); void setPolicy(String policy); void setAlwaysUseCache(boolean alwaysUseCache); void setNeverUseCache(boolean neverUseCache); void showCache(Formatter f); void cleanCache(File dir, Formatter sbuff, boolean isRoot); @Override String toString();  }