List of usage examples for java.io File toPath
public Path toPath()
From source file:edu.umd.umiacs.clip.tools.io.AllFiles.java
public static List<String> readAllLines(File file) { return readAllLines(file.toPath()); }
From source file:edu.umd.umiacs.clip.tools.io.AllFiles.java
public static Stream<CSVRecord> records(CSVFormat format, File file) { return records(format, file.toPath()); }
From source file:es.uvigo.ei.sing.adops.operations.running.tcoffee.TCoffeeDefaultProcessManager.java
private static String shortenPath(String pathString, File basedir) { final Path path = Paths.get(pathString); final Path pathBasedir = basedir.toPath(); final Path relativePath = pathBasedir.relativize(path); final String relativePathString = relativePath.toString(); return relativePathString.length() < pathString.length() ? relativePathString : pathString; }
From source file:codes.writeonce.maven.plugins.soy.CompileMojo.java
private static byte[] getFilesDigest(File directory) throws IOException, NoSuchAlgorithmException { final Path path = directory.toPath(); return getFilesDigest(path, Utils.getFilesFromSubtree(path)); }
From source file:halive.shootinoutside.common.core.game.map.GameMap.java
private static byte[] loadDefaultTextureSheet() { File f = new File("map/DefaultTileMap.png"); try {//from w w w . ja v a 2 s. co m return Files.readAllBytes(f.toPath()); } catch (IOException e) { e.printStackTrace(); return null; } }
From source file:com.excelsiorjet.api.util.Utils.java
public static void cleanDirectory(File f) throws IOException { Files.walkFileTree(f.toPath(), new FileVisitor<Path>() { @Override/* w w w . ja v a 2s . co m*/ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { return FileVisitResult.CONTINUE; } private void deleteFile(File f) throws IOException { if (!f.delete()) { if (f.exists()) { throw new IOException(Txt.s("JetApi.UnableToDelete.Error", f.getAbsolutePath())); } } } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { deleteFile(file.toFile()); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { if (file.toFile().exists()) { throw new IOException(Txt.s("JetApi.UnableToDelete.Error", f.getAbsolutePath())); } return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { deleteFile(dir.toFile()); return FileVisitResult.CONTINUE; } }); }
From source file:divconq.util.IOUtil.java
public static Memory readEntireFileToMemory(File file) { return IOUtil.readEntireFileToMemory(file.toPath()); }
From source file:io.druid.segment.loading.HdfsDataSegmentPullerTest.java
@BeforeClass public static void setupStatic() throws IOException, ClassNotFoundException { hdfsTmpDir = File.createTempFile("hdfsHandlerTest", "dir"); if (!hdfsTmpDir.delete()) { throw new IOE("Unable to delete hdfsTmpDir [%s]", hdfsTmpDir.getAbsolutePath()); }/* w w w .ja va2 s . c om*/ conf = new Configuration(true); conf.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, hdfsTmpDir.getAbsolutePath()); miniCluster = new MiniDFSCluster.Builder(conf).build(); uriBase = miniCluster.getURI(0); final File tmpFile = File.createTempFile("hdfsHandlerTest", ".data"); tmpFile.delete(); try { Files.copy(new ByteArrayInputStream(pathByteContents), tmpFile.toPath()); try (OutputStream stream = miniCluster.getFileSystem().create(filePath)) { Files.copy(tmpFile.toPath(), stream); } } finally { tmpFile.delete(); } }
From source file:io.druid.storage.hdfs.HdfsDataSegmentPullerTest.java
@BeforeClass public static void setupStatic() throws IOException { hdfsTmpDir = File.createTempFile("hdfsHandlerTest", "dir"); if (!hdfsTmpDir.delete()) { throw new IOE("Unable to delete hdfsTmpDir [%s]", hdfsTmpDir.getAbsolutePath()); }// ww w . j av a2s .com conf = new Configuration(true); conf.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, hdfsTmpDir.getAbsolutePath()); miniCluster = new MiniDFSCluster.Builder(conf).build(); uriBase = miniCluster.getURI(0); final File tmpFile = File.createTempFile("hdfsHandlerTest", ".data"); tmpFile.delete(); try { Files.copy(new ByteArrayInputStream(pathByteContents), tmpFile.toPath()); try (OutputStream stream = miniCluster.getFileSystem().create(filePath)) { Files.copy(tmpFile.toPath(), stream); } } finally { tmpFile.delete(); } }
From source file:Main.java
/** * <p>Decompresses a the content of a file from {@code startPosition} of {@code compressedSize} * and return the bytes of it. If a {@code compressedSize} can be provided if it is known * how large the decompressed content will be.</p> * * @param file the file//ww w . j a v a 2s. c om * @param startPosition the start position * @param compressedSize the compresse * @param decompressedSize the decompressed size * @return the decompressed bytes * @throws IOException if there was any io issues * @throws DataFormatException if there was an issue decompressing content */ public static byte[] decompress(File file, int startPosition, int compressedSize, int decompressedSize) throws IOException, DataFormatException { if (decompressedSize == 0) { return decompress(file, startPosition, compressedSize); } try (FileChannel fileChannel = FileChannel.open(file.toPath())) { ByteBuffer buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, startPosition, compressedSize); Inflater inflater = new Inflater(); byte[] compressedBytes = new byte[compressedSize]; byte[] bytes = new byte[decompressedSize]; buffer.get(compressedBytes); inflater.setInput(compressedBytes, 0, compressedSize); inflater.inflate(bytes); inflater.end(); return bytes; } }