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
6
votes
2 answers

Java 7's nio.file package is uber slow at creating new files

I'm trying to create 300M files from a java program, I switched from the old file API to the new java 7 nio package, but the new package is going even slower than the old one. I see less CPU utilization than I did when I was using the old file API,…
David Parks
  • 30,789
  • 47
  • 185
  • 328
5
votes
0 answers

How AsynchronousSocketChannel maintain reading?

I need to connect to 4 machines and read data from sockets. I've chosen to use an async model of nio2. Here is a pseudo-code : class Connector { private final AsynchronousChannelGroup group; private final String host; private final int…
flywell
  • 384
  • 3
  • 20
5
votes
0 answers

Support for case sensitive Windows directories in NIO.2

Recent Windows 10 builds feature an ability to mark a single NTFS directory (not the whole file system) as case sensitive, via fsutil.exe: Per-directory case sensitivity and WSL How to Enable Case Sensitive File and Folder Names on Windows 10 If I…
Bass
  • 4,977
  • 2
  • 36
  • 82
5
votes
1 answer

undertow webserver not binding to remote address

I'm testing out the undertow 2.0.0.Alpha1 webserver. When I run it locally it works and returns Hello World when I go to localhost:80. I then deploy the webserver on a remote server and go to remote_ip:80 but I get no response back. If I run curl -i…
Hooli
  • 1,135
  • 3
  • 19
  • 46
5
votes
1 answer

How to asynchronously force a file using AsynchronousFileChannel

The AsynchronousFileChannel API in Java NIO.2 contains the void force(boolean) method. Obviously this method is blocking, as it can only return once the changes have been successfully written to the device. I'm looking for a way to achieve the same,…
Chris Leishman
  • 1,777
  • 13
  • 19
5
votes
1 answer

How do I bind multiple ports using AsynchronousServerSocketChannel?

I'm trying to create a server with an asynchronous communication model and want to bind multiple ports, but it throws an error "AlreadyBoundException" when I call one more than bind method. Is there any possible way to do this? Here's my…
한재현
  • 51
  • 2
5
votes
1 answer

AccessDeniedException on Files.copy from a temporary file in Java NIO2

I am getting used to Java 7 and the new Files class. I am writing a small application which, at some point, must replace the contents of a file. I used a temporary file to avoid erasing the target file if somethign goes wrong. However, I'm always…
Silver Quettier
  • 2,045
  • 2
  • 26
  • 53
5
votes
4 answers

How can AsynchronousFileChannel read large file?

Path file = Paths.get("c:/large.log"); AsynchronousFileChannel channel = AsynchronousFileChannel.open(file); final ByteBuffer buffer = ByteBuffer.allocate(1000); channel.read(buffer, 0, buffer, new CompletionHandler
liam xu
  • 2,892
  • 10
  • 42
  • 65
5
votes
3 answers

How to convert a filepath to valid file path in Java 1.7

Using Java 1.6 Filepath can be entered by user and then I apply various regular expressions to remove characters that are invalid for the platform (such as '?' is invalid on Windows), and check path length to ensure we end up with a valid filepath…
Paul Taylor
  • 13,411
  • 42
  • 184
  • 351
5
votes
2 answers

Why is threre not a Files.readAllLines(String path) in java 7?

I'm tryting to learn the nio 2 package in Java 7 and i stumbled upon the Files.readAllLines(Path p, Charset cs) method. I find it very useful, but i'm of the opinion that there should be a version without the cs parameter, just like : public…
Chirlo
  • 5,989
  • 1
  • 29
  • 45
4
votes
2 answers

Why does Path.relativize behave differently on Java 8 and Java 11?

Why does the method relativize behave differently on java-8 and java-11? Path path1 = Paths.get("/a/./b/../image.png"); Path path2 = Paths.get("/a/file.txt"); Path path = path1.relativize(path2); System.out.println(path); java-8 (1.8.0_66 to be…
Nikolas Charalambidis
  • 40,893
  • 16
  • 117
  • 183
4
votes
1 answer

A bit strange behaviour of Files.delete and Files.deleteIfExists

I got code like this: paths.forEach(folderPath -> { Path to = folderPath.getRoot().resolve(folderPath.getParent().subpath(0, folderPath.getNameCount() - 1)); // До имени (исключительно) try { …
Aqluse
  • 307
  • 3
  • 10
4
votes
0 answers

Allocation free implementation of AsynchronousByteChannel (Java NIO.2)

All implementations of AsynchronousByteChannel in Java 8 allocate additional objects for each channel read/write operation. That looks strange for me as this API was intended (*) to be used for high performance applications and allocation of…
Alexei Osipov
  • 728
  • 10
  • 17
4
votes
4 answers

From ByteBuffer to double array

I have a ByteBuffer containing three double values, e.g. {1.0, 2.0, 3.0}. What I have now is double[] a = new double[3]; for (int i = 0; i < 3; i++) { a[i] = byteBuffer.getDouble(); } which works fine, but I would prefer a one-step solution via…
Michael Dorner
  • 17,587
  • 13
  • 87
  • 117
4
votes
1 answer

IO performance: Selector (NIO) vs AsynchronousChannel(NIO.2)

Strangely, i was unable to find in Google clear answer to NIO.2 async IO performance vs using NIO's multiplexed IO via java.nio.channels.Selector. So, my question is: Does NIO.2 AsynchronousChannel have better performance than NIO Selector? Of…
Sergey Alaev
  • 3,851
  • 2
  • 20
  • 35
1 2
3
11 12