nio2

Custom NIO filesystem doesn't load through SBT's test task

前提是你 提交于 2019-12-04 14:49:27
For testing, I'm using an in-memory NIO FileSystem implementaion ( memoryfs ). I've taken advantage of it before, and it seems to run fine through e.g. Maven. However, now, in an SBT project, it's impossible to initialize a new FileSystem . Here's a minimal SBT configuration to reproduce the problem: import sbt._ import Keys._ name := "testfs" organization := "com.example version := "0.1-SNAPSHOT" scalaVersion := "2.11.6" libraryDependencies ++= { val scalaTestVersion = "2.2.5" Seq( "org.scalatest" %% "scalatest" % scalaTestVersion % "test", "org.mockito" % "mockito-core" % "1.10.19" % "test",

How to copy a directory with its attributes/permissions from one location to another?

时间秒杀一切 提交于 2019-12-03 20:22:22
I see a lot of examples that use Files.walkFileTree() to copy a directory and its contents from one location to another, but they fail to take the directory's file attributes and permissions into consideration. Meaning, they just invoke Files.createDirectories() without any attributes or permissions. How does one copy a directory (and its contents) from one location to another without losing file attributes or permissions, using the Java7 core classes? Gili Answering my own question: /** * Copies a directory. * <p> * NOTE: This method is not thread-safe. * <p> * * @param source * the directory

EJB 3.1 and NIO2: Monitoring the file system

大城市里の小女人 提交于 2019-12-02 12:00:20
问题 I guess most of us agree, that NIO2 is a fine thing to make use of. Presumed you want to monitor some part of the file system for incoming xml - files it is an easy task now. But what if I want to integrate the things into an existing Java EE application so I don't have to start another service (app-server AND the one which monitors the file system)? So I have the heavy weight app-server with all the EJB 3.1 stuff and some kind of service monitoring the file system and take appropriate action

Merge huge files without loading whole file into memory?

社会主义新天地 提交于 2019-11-30 13:36:53
问题 I want to merge huge files containing strings into one file and tried to use nio2. I do not want to load the whole file into memory, so I tried it with BufferedReader: public void mergeFiles(filesToBeMerged) throws IOException{ Path mergedFile = Paths.get("mergedFile"); Files.createFile(mergedFile); List<Path> _filesToBeMerged = filesToBeMerged; try (BufferedWriter writer = Files.newBufferedWriter(mergedFile,StandardOpenOption.APPEND)) { for (Path file : _filesToBeMerged) { // this does not

Why is Java 7 Files.walkFileTree throwing exception on encountering a tar file on remote drive

拈花ヽ惹草 提交于 2019-11-30 07:54:47
问题 Im using Files.WalkFileTree() to navigate folder and counting audio files, but there is a problem when it encounters a tar file, it seems to be treating it as an actual folder I was expecting it to just skip over it. I cannot see any options that let me control this behaviour Code: package com.jthink.songkong.fileloader; import com.jthink.songkong.cmdline.SongKong; import com.jthink.songkong.ui.MainWindow; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java

Merge huge files without loading whole file into memory?

纵饮孤独 提交于 2019-11-30 07:31:44
I want to merge huge files containing strings into one file and tried to use nio2. I do not want to load the whole file into memory, so I tried it with BufferedReader: public void mergeFiles(filesToBeMerged) throws IOException{ Path mergedFile = Paths.get("mergedFile"); Files.createFile(mergedFile); List<Path> _filesToBeMerged = filesToBeMerged; try (BufferedWriter writer = Files.newBufferedWriter(mergedFile,StandardOpenOption.APPEND)) { for (Path file : _filesToBeMerged) { // this does not work as write()-method does not accept a BufferedReader writer.append(Files.newBufferedReader(file)); }

split very large text file by max rows

点点圈 提交于 2019-11-30 04:58:00
问题 I want to split a huge file containing strings into a set of new (smaller) file and tried to use nio2. I do not want to load the whole file into memory, so I tried it with BufferedReader. The smaller text files should be limited by the number of text rows. The solution works, however I want to ask if someone knows a solution with better performance by usion java 8 (maybe lamdas with stream()-api?) and nio2: public void splitTextFiles(Path bigFile, int maxRows) throws IOException{ int i = 1;

Using Java 7 SDK features in Java 6

為{幸葍}努か 提交于 2019-11-29 09:53:15
I am interested in using some of the NIO2 features in the Java 7 SDK if available (specifically, the file system watchers ), however I do not want to compile my classes for Java 7 and exclude Java 6 runtimes. Mostly because I want retain compatibility with Mac OS X, and also because I don’t want to force my users to upgrade. Is this possible? What is the best way to do it? Any links or examples? Here are some ways I can imagine: compiling a class file with a different compiler and loading it dynamically based on the Java version? Or maybe using reflection? Or maybe there’s just a compiler

Why is Java 7 Files.walkFileTree throwing exception on encountering a tar file on remote drive

爱⌒轻易说出口 提交于 2019-11-29 05:36:05
Im using Files.WalkFileTree() to navigate folder and counting audio files, but there is a problem when it encounters a tar file, it seems to be treating it as an actual folder I was expecting it to just skip over it. I cannot see any options that let me control this behaviour Code: package com.jthink.songkong.fileloader; import com.jthink.songkong.cmdline.SongKong; import com.jthink.songkong.ui.MainWindow; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.concurrent.Callable; import java.util.logging.Level; /** * Count the number of files that can be

Find the directory for a FileStore

走远了吗. 提交于 2019-11-29 03:56:47
I'm trying to find a way to detect when a flash drive has been plugged into my computer. So far, the solution I found was to poll FileSystem#getFileStores for changes. This does indeed tell me when the flash drive has been inserted, but as far as I can tell there is no way to retrieve the location for it. FileStore#type and FileStore#name both seem highly unreliable as their return value is implementation specific, but they appear to be the only methods that might return any relevant information that might help find the directory for the FileStore . With that in mind, the following code: