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
0
votes
0 answers

Java NIO2 Files.copy() vs. Bash cp - Performance comparison

I have a Java program which is launched through command-line by a Bash script, which is in turn called at various intervals by cron. There are several operations performed by this program, the first being the copy of a possibly large number of more…
Silver Quettier
  • 2,045
  • 2
  • 26
  • 53
0
votes
1 answer

Java NIO 2 DirectoryStream list changes when file is changed

I have noticed a weird behavior when listing files in a directory. My situation is i have a list of txt files which i save in database and corresponding to those data files there are xml file that contains some tags for each txt which are associated…
Adyz
  • 302
  • 4
  • 18
0
votes
2 answers

NIO.2 asynchronous channels coding guidelines

For example, i want to read 100500 bytes to an array: byte[] array = new byte[100500]; int offset = 0; ByteBuffer buf = ByteBuffer.directBuffer(4096); channel.read(buffer, null, new LambdaAdapter((count, exception, attachment) -> { …
Sergey Alaev
  • 3,851
  • 2
  • 20
  • 35
0
votes
2 answers

Too many levels of symbolic links using Java NIO 2 - Paths.get(workFolder, timestamp);

I am getting "Too many levels of symbolic links" I am using Java NIO2 :- This is run on Unix. Any thoughts would be of great help. Thanks. Deep inside the code I am calling Path currentFolder = Paths.get(currentFolder, date); and at some point in…
Shiv Gopal
  • 539
  • 2
  • 10
  • 21
0
votes
1 answer

Is it possible for any reason to register two WatchKeys per Path?

I can't reproduce the issue in a minor example, but is it possible to register two different WatchKeys for one Path if the WatchService and the Kinds are the same? For instance if the parent-directory content changes?
Franz Ebner
  • 4,951
  • 3
  • 39
  • 57
0
votes
1 answer

Java NIO2: Need clarification on FileChannel

I'm trying to build a custom FileChannel, and I'm experiencing a lack of clarity due to inconsistency in the documentation. The documentation for the FileChannel.transferFrom(ReadableByteChannel src, long position, long count) method says, If the…
Harry
  • 3,684
  • 6
  • 39
  • 48
0
votes
1 answer

Why do asynchronous channels in Java's NIO.2 require these pauses?

I've written minimal example, but it's still too long, so let me know I should post the link to Pastebin instead. Server: import java.io.IOException; import java.net.InetSocketAddress; import java.net.StandardSocketOptions; import…
tkroman
  • 4,811
  • 1
  • 26
  • 46
0
votes
1 answer

How do I instantiate a Java 7 completion handler in Scala

I was playing with scala (newbie) and I was trying to use Java 7 NIO (because I like to start easy). But I can't work out how to instantiate the CompletionHandler for the accept. The following code is wrong and I can't fix it: package async import…
gotch4
  • 13,093
  • 29
  • 107
  • 170
0
votes
3 answers

How to delete a file after uploading using Struts 2?

I am able to upload a file using Struts2, but I want to drop the specified directory but I don't know how to delete a file. Here is my code: public String execute(){ destPath = "/tmp/listfile"; try{ System.out.println("Src File name: " +…
user
  • 101
  • 1
  • 1
  • 4
0
votes
1 answer

java.nio DatagramChannel non-blocking mode.. you still have to block?

I've been looking into java.nio's asynchronous capabilities, and so far I am a fan of the AsynchronousByteChannel class, as it lets me provide completion callbacks for each read or write operation. This adapts well with scala's Future class. Now I'm…
Dylan
  • 13,645
  • 3
  • 40
  • 67
0
votes
2 answers

How to read a large file using Nio2

I am trying to read a text file which has around 3 lakh lines as of now. How am I reading? I am reading using the java.io.BufferedReader Here is a small code snippet which represents my approach. int lineNumber = 1; BufferedReader br =…
srk
  • 4,857
  • 12
  • 65
  • 109
0
votes
1 answer

Java Async I/O with NIO2: Does AsynchronousServerSocketChannel.accept give you an active AsynchronousSocketChannel

For server.accept I wrote a completion handler that has the parameters. When the handler is invoked via the accept method, does that mean the AsynchronousSocketChannel is now conneted? Or do I have to invoke the AsynchronousSocketChannel.connect…
0
votes
2 answers

Query on FileSystems.getPath(URI)

In the Java 7 source code the class, Paths has a method - get(URI). Within get(URI) exists: return FileSystems.getDefault().provider().getPath(uri); FileSystems.getDefault() returns a reference to the default filesystem. But then, according to the…
user465001
  • 806
  • 13
  • 29
0
votes
2 answers

Correct behavior from nio.2 AsynchronousServerSocketChannel.accept() on windows?

The following test program does a simple bind/accept and then shuts down the channel group. I would expect the program to print out the resulting ShutdownChannelGroupException, but instead it never calls the completion handler and throws the…
jadamcrain
  • 125
  • 7
0
votes
1 answer

Unexpeced output of java 7 nio 2 program

I am trying a small program from Pro Java 7 NIO.2 Page No 118 Code is : class WatchRafaelNadal { public void watchRNDir(Path path) throws IOException, InterruptedException { try (WatchService watchService =…
Vikram
  • 1,999
  • 3
  • 23
  • 35
1 2 3
11
12