List of usage examples for java.io File toPath
public Path toPath()
From source file:es.upv.grycap.coreutils.fiber.test.mockserver.ObjectResponseValidator.java
public static void validateJson(final File file, final String expectedId) throws IOException, JSONException { final String objectId = readObjectIdFromJson(new String(readAllBytes(file.toPath()))); assertThat("Object Id coincides with expected", objectId, allOf(notNullValue(), not(equalTo("")), equalTo(expectedId))); }
From source file:com.diffplug.gradle.pde.PdeProductBuildConfig.java
static void transformProductFile(File input, File output, PluginCatalog catalog, String version) throws IOException { String inputStr = new String(Files.readAllBytes(input.toPath()), StandardCharsets.UTF_8); String result = StringPrinter.buildString(printer -> { String[] lines = FileMisc.toUnixNewline(inputStr).split("\n"); for (String line : lines) { ProductFileUtil.transformProductFile(printer, line, catalog, version); }/* w w w .j a v a 2s. c o m*/ }); Files.write(output.toPath(), result.getBytes(StandardCharsets.UTF_8)); }
From source file:de.alpharogroup.crypto.key.reader.PublicKeyReader.java
/** * Read the public key from a pem file as base64 encoded {@link String} value. * * @param file// w ww . j a v a 2 s .c om * the file in pem format that contains the public key. * @return the base64 encoded {@link String} value. * @throws IOException * Signals that an I/O exception has occurred. */ public static String readPemFileAsBase64(final File file) throws IOException { final byte[] keyBytes = Files.readAllBytes(file.toPath()); final String publicKeyAsBase64String = new String(keyBytes).replace(BEGIN_PUBLIC_KEY_PREFIX, "") .replace(END_PUBLIC_KEY_SUFFIX, ""); return publicKeyAsBase64String; }
From source file:Main.StaticTools.java
/** * Opens up a <code> DirectoryChooser </code> * @param dir set the home directory if it's not valid "C:\" will be used * @return a <code> File </code> object of the chosen path *//*from w w w. j a v a2s . c om*/ public static File getDir(File dir) { DirectoryChooser chooser = new DirectoryChooser(); if (Files.exists(dir.toPath())) chooser.setInitialDirectory(dir); else chooser.setInitialDirectory(new File("C:\\")); return chooser.showDialog(null); }
From source file:com.android.tradefed.util.ZipUtil2.java
/** * A util method to apply unix mode from {@link ZipArchiveEntry} to the created local file * system entry if necessary// w w w. j a v a 2 s .c om * @param entry the entry inside zipfile (potentially contains mode info) * @param localFile the extracted local file entry * @throws IOException */ private static void applyUnixModeIfNecessary(ZipArchiveEntry entry, File localFile) throws IOException { if (entry.getPlatform() == ZipArchiveEntry.PLATFORM_UNIX) { Files.setPosixFilePermissions(localFile.toPath(), FileUtil.unixModeToPosix(entry.getUnixMode())); } else { CLog.i("Entry does not contain Unix mode info: %s", entry.getName()); } }
From source file:dk.dma.dmiweather.service.FTPLoader.java
private static void deleteRecursively(File lastTempDir) throws IOException { Path rootPath = lastTempDir.toPath(); //noinspection ResultOfMethodCallIgnored Files.walk(rootPath, FileVisitOption.FOLLOW_LINKS).sorted(Comparator.reverseOrder()) // flips the tree so leefs are deleted first .map(Path::toFile).peek(f -> log.debug("deleting file " + f.getAbsolutePath())) .forEach(File::delete); }
From source file:com.simiacryptus.util.io.IOUtil.java
/** * Write json.//from w w w .jav a 2 s. com * * @param <T> the type parameter * @param obj the obj * @param file the file */ public static <T> void writeJson(T obj, File file) { StringWriter writer = new StringWriter(); try { objectMapper.writeValue(writer, obj); Files.write(file.toPath(), writer.toString().getBytes()); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.thesmartguild.firmloader.lib.tftp.TFTPServerFactory.java
public static TFTPServer instantiate(File file) { try {/* w w w .j a v a 2s . co m*/ TFTPServer TFTPServer_; Path tmpFilePath = TFTPServerFactory.createTempDirectory(); Path filePath = Files.copy(file.toPath(), Paths.get(tmpFilePath.toString(), file.getName()), StandardCopyOption.REPLACE_EXISTING); filePath.toFile().deleteOnExit(); TFTPServer_ = new TFTPServer(tmpFilePath.toFile(), tmpFilePath.toFile(), ServerMode.GET_ONLY); TFTPServer_.setLog(System.out); TFTPServer_.setLogError(System.out); return TFTPServer_; } catch (IOException e) { e.printStackTrace(); return null; } }
From source file:com.schnobosoft.semeval.cortical.SemEvalTextSimilarity.java
/** * Read an input file of tab-separated texts. Ignoring empty lines. * * @param inputFile the input {@link File} * @return an array {@link CompareModels}, each holding two {@link Text}s which have been read from the file. * @throws IOException//from ww w.j a va2s.c om */ private static CompareModels[] readInput(File inputFile) throws IOException { LOG.info("Reading input file " + inputFile); assert inputFile.getName().startsWith(INPUT_FILE_PREFIX); List<CompareModels> lines = Files.lines(inputFile.toPath()).filter((s) -> !s.isEmpty()) .map(line -> line.split("\t")).map(line -> new CompareModels(new Text(line[0]), new Text(line[1]))) .collect(Collectors.toList()); return lines.toArray(new CompareModels[lines.size()]); }
From source file:gob.dp.simco.comun.FunctionUtil.java
public static String uploadArchive(Part fil) { String nameArchive = getFilename(fil); String extencion = getFileExtension(getFilename(fil)); if (StringUtils.isNoneBlank(nameArchive)) { String formato = RandomStringUtils.random(32, 0, 20, true, true, "qw32rfHIJk9iQ8Ud7h0X".toCharArray()); String ruta = formato + extencion; File file = new File(ConstantesUtil.FILE_SYSTEM + ruta); try (InputStream input = fil.getInputStream()) { Files.copy(input, file.toPath()); } catch (IOException ex) { log.error(ex);// ww w . j a v a 2s . c om } return ruta; } return null; }