Questions tagged [nio2]

NIO2 is an umbrella name for new features added to the original Java NIO package in the Java 1.7 release. Also referred to as "New I/O".

NIO.2 is an umbrella name for new features added to the original Java package in the Java 1.7 release. Also referred to as "New I/O".

  • Asynchronous Channels and Futures: A Channel that supports asynchronous I/O operations with implementations for sockets, server sockets and files.
  • Completion Handlers: The ability to register handlers that will be called on the completion of an asynchronous I/O event.
  • Asynchronous Channel Groups: A grouping of asynchronous channels for the purpose of resource sharing.
  • Asynchronous Multicast: Support for implementing asynchronous NIO I/O with callbacks for UDP multicast.
  • A New File System API for Java: Defines new interfaces and classes for the Java virtual machine to access files, file attributes, and file systems.

Articles and Tutorials

Note: This tag and wiki should be rolled into the nio tag.

173 questions
4
votes
0 answers

Implementation of java.nio.FileSystem wrapping Commons VFS?

I know there exists Apache Commons VFS which permits to connect to different FileSystem, where a FileSystem may be something like a FTP, HTTP, SFTP, Zip file or simply a local file system. I am wondering, after some search (most on Google and VFS…
NoDataFound
  • 11,381
  • 33
  • 59
4
votes
1 answer

Files.createTempDirectory("") throws NullPointerException

When I call Files.createTempDirectory("") I get the below exception: java.lang.NullPointerException at sun.nio.fs.WindowsSecurityDescriptor.fromAttribute(WindowsSecurityDescriptor.java:353) at…
balapal
  • 41
  • 1
  • 6
4
votes
2 answers

DirectoryStream.Filter example for listing files that based on certain date/time

I am trying to investigate a DirecoryStream.Filter example for newDirectoryStream where I can achieve to list all files under a directory(and all its sub directories) that are older than 60 days, as an example. DirectoryStream dirS =…
Ashley
  • 629
  • 3
  • 6
  • 16
4
votes
1 answer

Map a Java UserPrincipal to an Active Directory user

I am accessing a remote server with Java. The server runs Microsoft Windows and provides an Active Directory as well as a file system share. I read users and groups from the Active Directory via JNDI, which works great. I get all user attributes…
Sky
  • 674
  • 8
  • 22
4
votes
0 answers

How does JDK 7 implement NIO2 on Linux?

I know that the JDK 7 implements NIO2 on Windows using IOCP, but how about Linux? Although Linux has AIO since 2.6, it's only useful on files. What about the network part?
4
votes
2 answers

NIO2: how to generically map a URI to a Path?

I'm trying to find an easy way to map a URI to a Path without writing code specific to any particular file system. The following seems to work but requires a questionable technique: public void process(URI uri) throws IOException { try { …
cambecc
  • 4,083
  • 1
  • 23
  • 24
4
votes
1 answer

Connection refusal on Java7 async NIO2 server

I have written a async socketserver using java 7 nio2. Here is a snipper of the Server. public class AsyncJava7Server implements Runnable, CounterProtocol, CounterServer{ private int port = 0; private AsynchronousChannelGroup group; …
dublintech
  • 16,815
  • 29
  • 84
  • 115
4
votes
1 answer

Using a Java WatchService to monitor folders within folders

I'm trying out WatchService with Java 7, to monitor a folder. I want it to monitor any files or folders being added to the path registered with the WatchService. If I add a folder to the registered path it detects it correctly as ENTRY_CREATE and…
Paul Taylor
  • 13,411
  • 42
  • 184
  • 351
3
votes
1 answer

Is there an equivalent to transferTo for AsynchronousFileChannel?

I've been playing around with NIO2 in Java 7 and I kind of assumed that the AsynchronousFileChannel would have a transferTo method like its synchronous FileChannel sibling. I'm looking to perform a zero-copy transfer between a local file and an open…
Chris Mowforth
  • 6,689
  • 2
  • 26
  • 36
3
votes
1 answer

How do I prevent java FileTreeWalker failing prematurely

I am trying to walk file tree to count files. But even though I handle exceptions within my CountFiles class the call to walkFileTree() has failed prematurely i the FileTreeWalker class preventing it counting the remaining files. How can I avoid…
Paul Taylor
  • 13,411
  • 42
  • 184
  • 351
3
votes
1 answer

How to connect with external file system via FileSystem class in Java 8?

I found the following example of establishing connection with external file system using http protocol in OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide book: FileSystem fileSystem = FileSystems.getFileSystem(new…
Michał Szewczyk
  • 7,540
  • 8
  • 35
  • 47
3
votes
1 answer

How to check if java.nio.file.Path is from the default file system?

What's the easiest way to check if a java.nio.file.Path is a path from the default file system? I'm working with an older API that still uses java.io.File but also allows to pass an java.net.URL. I've come up with two possible solutions but they…
Jimmy T.
  • 4,033
  • 2
  • 22
  • 38
3
votes
2 answers

Java: ZipFile using Path

I have a Path to zip file on virtual filesystem (jimfs) and I need to open this zip file using ZipFile. But there is no constructor in ZipFile to get Path as argument, only File. However, I can't create from my Path a File (path.toFile()) because I…
Pavel_K
  • 10,748
  • 13
  • 73
  • 186
3
votes
1 answer

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

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…
mikołak
  • 9,605
  • 1
  • 48
  • 70
3
votes
0 answers

Set up permissions on file in mounted CIFS share - NIO.2

I am trying to add a set of attributes at creation time as in the following example. This code creates a new file on a POSIX file system with specific permissions ("rw-rw-r--") in mounted CIFS share. public static void main(String[] args) { …
mariusz117
  • 151
  • 1
  • 4