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
1
vote
1 answer

nio2: detect '..' and suchlike elements

I wish to use a string handed to me as a parameter as an element of a pathname. I do not wish to be troubled with 'Little Bobby Tables'. That is, I don't want '..' to be acceptable. I want this to work with an arbitrary NIO2 FileSystem, so just…
bmargulies
  • 97,814
  • 39
  • 186
  • 310
1
vote
2 answers

Files.walk() OS-independency issue

I have the following code which works fine under Linux/Unix: Files.walk(Paths.get(getStartingPath())) .filter(Files::isDirectory) // Skip directories which start with a dot (like, for example: .index) .filter(path ->…
carlspring
  • 31,231
  • 29
  • 115
  • 197
1
vote
2 answers

How to read text file by block with Java 8 streams

I want to read an ASCII file that is composed of "blocks" that are delimited by start and end tags. I have never used Java 8 streams and I would like to test them on this file reader, but I don't really know how to do it. For the sake of simplicity,…
Ben
  • 6,321
  • 9
  • 40
  • 76
1
vote
2 answers

Using a java.nio.file.Path instance and a string to navigate to a sub-path

How can I use a java.nio.file.Path object to navigate to a sub-path? I'd have thought that something like path = path.subFolder(string) would work where string specifies a sub-folder relative to the initial path. But there doesn't seem to be such a…
P45 Imminent
  • 8,319
  • 4
  • 35
  • 78
1
vote
0 answers

Infinite loop while using Files.newDirectoryStream

I wrote some test that zip files in some dummy directory: public void compressFileToZipTest() throws IOException{ try (DirectoryStream stream = Files.newDirectoryStream( Paths.get("src", "test", "resources", "dummy",…
Maxim Kirilov
  • 2,639
  • 24
  • 49
1
vote
0 answers

Java NIO 2 Authentication

I am working on a distributed system based on Java NIO 2, using AsynchronousSocketChannel and AsynchronousServerSocketChannel. My task is to make authentication when client attempts to connect to a server. What is the best way to do that considering…
Z1kkurat
  • 45
  • 6
1
vote
1 answer

How do I extract subpath neatly accounting for root and no root folders on java

I have a Path object and a String object, the Path object represents part of the starting path represented by the filename e.g for the filename /Music/Beatles/Help.mp3 the Path object may be / /Music /Music/Beatles this simple method returns the…
Paul Taylor
  • 13,411
  • 42
  • 184
  • 351
1
vote
1 answer

Async reading in server-client: separate client messages

I'm implementing a simple server using AsynchronousServerSocketChannel. For testing purposes, I created a tiny client prototype that sends two messages, "hi" and "stackoverflow", then disconnects. On server side, I read the arrived messages and…
hoefling
  • 59,418
  • 12
  • 147
  • 194
1
vote
1 answer

Why do I see NullPointerException when I search files by mask under the root folder ?(windows)

I investigate java nio2 possibilities. I knew that I can search files using FileVisitor interface. To achieve this functionality I use glob pattern. code of my example: visitor interface realization: class MyFileFindVisitor extends…
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
1
vote
1 answer

Nio2 WatchService

I'm learning about file watchers in nio2, and an example file had a Map variable where they mapped files to watch keys, and had the following code: for (;;) { // wait for key to be signaled WatchKey key; …
EZ PZ
  • 99
  • 9
1
vote
1 answer

DatagramChannel, blocking mode and cpu

I get the following code snippet: datagramChannel = DatagramChannel .open(StandardProtocolFamily.INET).setOption(StandardSocketOptions.SO_REUSEADDR, true) .setOption(StandardSocketOptions.IP_MULTICAST_IF,…
Doc Davluz
  • 4,154
  • 5
  • 30
  • 32
1
vote
2 answers

Get rid of a checked exception when using NIO2 API

Currently, I was loading a property file from the classpath using the following code with the help of Guava API: final URL fileURL = Resources.getResource("res.properties"); final File file = new File(fileURL.getFile()); I decided to give a try the…
jilt3d
  • 3,864
  • 8
  • 34
  • 41
1
vote
2 answers

How to set File Access attribute for a particular user in java7

i am using java7 File api. for setting owner of a file i searched and able to change owner attribute. my code is public static void main(String[] args){ Path zip=Paths.get("/home/ritesh/hello"); try{ FileOwnerAttributeView view …
mathlearner
  • 7,509
  • 31
  • 126
  • 189
1
vote
2 answers

EJB 3.1 and NIO2: Monitoring the file system

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…
Subcomandante
  • 403
  • 1
  • 6
  • 14
1
vote
1 answer

Java NIO2 AIO - TCP Chat Server

i am playing arround with Java NIO2 and i am trying to code a TCP Chat Server based on AsynchronousServerSocketChannel. To Programm a simple ECHO-Server was no problem and worked flawlessly. Now i am trying to accept many clients and to broadcast…
Filipe Santos
  • 1,629
  • 3
  • 18
  • 27