List of usage examples for java.io File toPath
public Path toPath()
From source file:ee.ria.xroad.signer.certmanager.FileBasedOcspCache.java
private static void delete(File file) { try {/* ww w . j a va2 s . c o m*/ Files.delete(file.toPath()); } catch (Exception e) { log.warn("Failed to delete {}: {}", file, e); } }
From source file:org.hawkular.alerts.actions.webhook.WebHooks.java
public static synchronized void loadFile() throws IOException { File f = new File(instance.webhooksFile); Path path = f.toPath(); StringBuilder fullFile = new StringBuilder(); Files.lines(path).forEach(s -> fullFile.append(s)); log.debug("Reading webhooks... " + fullFile.toString()); instance.webhooks = instance.mapper.readValue(fullFile.toString(), Map.class); }
From source file:com.eviware.soapui.Util.SoapUITools.java
public static Path soapuiHomeDir() { String homePath = System.getProperty("soapui.home"); if (homePath == null) { File homeFile = new File("."); log.warn("System property 'soapui.home' is not set! Using this directory instead: {}", homeFile); return homeFile.toPath(); }//w ww.j av a2s .co m return ensureExists(Paths.get(homePath)); }
From source file:com.simiacryptus.util.io.IOUtil.java
/** * Read json t./*from ww w . j a v a 2s.c o m*/ * * @param <T> the type parameter * @param file the file * @return the t */ public static <T> T readJson(File file) { try { return objectMapper.readValue(new String(Files.readAllBytes(file.toPath())), new TypeReference<T>() { }); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.simiacryptus.util.io.IOUtil.java
/** * Read kryo t.//from w w w .j av a2s .co m * * @param <T> the type parameter * @param file the file * @return the t */ public static <T> T readKryo(File file) { try { byte[] bytes = CompressionUtil.decodeBZRaw(Files.readAllBytes(file.toPath())); Input input = new Input(buffer.get(), 0, bytes.length); return (T) new KryoReflectionFactorySupport().readClassAndObject(input); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.basistech.rosette.apimodel.NonNullTest.java
@Parameterized.Parameters(name = "{0}") public static Collection<Object[]> data() throws URISyntaxException, IOException { File dir = new File("src/test/data"); Collection<Object[]> params = new ArrayList<>(); try (DirectoryStream<Path> paths = Files.newDirectoryStream(dir.toPath())) { for (Path file : paths) { if (file.toString().endsWith(".json")) { String className = file.getFileName().toString().replace(".json", ""); params.add(new Object[] { NonNullTest.class.getPackage().getName() + "." + className, file.toFile() }); }/* ww w . j a v a 2 s .c o m*/ } } return params; }
From source file:ai.susi.mind.SusiAwareness.java
/** * produce awareness by reading a memory dump up to a given attention time * @param memorydump file where the memory is stored * @param attentionTime the maximum number of cognitions within the required awareness * @return awareness for the give time/* w w w .j av a 2 s .co m*/ * @throws IOException */ public static SusiAwareness readMemory(final File memorydump, int attentionTime) throws IOException { List<String> lines = Files.readAllLines(memorydump.toPath()); SusiAwareness awareness = new SusiAwareness(); for (int i = lines.size() - 1; i >= 0; i--) { String line = lines.get(i); if (line.length() == 0) continue; SusiCognition si = new SusiCognition(new JSONObject(line)); awareness.aware.add(si); if (attentionTime != Integer.MAX_VALUE && awareness.getTime() >= attentionTime) break; } return awareness; }
From source file:com.collective.celos.ci.mode.TestTask.java
static File getTempDir() throws IOException { File celosCiDir = new File(System.getProperty("user.home"), CELOS_CI_DIR); File tempDir = new File(celosCiDir, UUID.randomUUID().toString()); return Files.createDirectories(tempDir.toPath(), getTempDirAttributes()).toFile(); }
From source file:com.arpnetworking.configuration.jackson.JsonNodeDirectorySourceTest.java
private static void deleteDirectory(final File directory) throws IOException { if (directory.exists() && directory.isDirectory()) { for (final File file : MoreObjects.firstNonNull(directory.listFiles(), new File[0])) { Files.deleteIfExists(file.toPath()); }/*from w w w .j a va2s .com*/ } Files.deleteIfExists(directory.toPath()); }
From source file:com.geewhiz.pacify.utils.FileUtils.java
private static void copyDirectoryRecursively(File source, File target) throws IOException { if (!target.exists()) { Files.copy(source.toPath(), target.toPath(), java.nio.file.StandardCopyOption.COPY_ATTRIBUTES); }/* w ww .j av a2s. c om*/ for (String child : source.list()) { copyDirectory(new File(source, child), new File(target, child)); } }