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
9
votes
4 answers

Using Java 7 SDK features in Java 6

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…
Laurens Holst
  • 20,156
  • 2
  • 29
  • 33
9
votes
2 answers

WatchService fires ENTRY_MODIFY sometimes twice and sometimes once

I am using this WatchService example from Oracle: import java.nio.file.*; import static java.nio.file.StandardWatchEventKinds.*; import static java.nio.file.LinkOption.*; import java.nio.file.attribute.*; import java.io.*; import…
halil
  • 800
  • 16
  • 33
9
votes
2 answers

split very large text file by max rows

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…
nimo23
  • 5,170
  • 10
  • 46
  • 75
9
votes
4 answers

Any available in-memory FileSystem implementations for Java7 nio2?

I was looking for in-memory nio2 FileSystem implementations, that would allow me to more easily test my IO-dependent code. It seems natively, Java only provides (in my JDK) a Win32FileSystem and a ZipFileSystem. It seems ShrinkWrap has something of…
devoured elysium
  • 101,373
  • 131
  • 340
  • 557
8
votes
2 answers

What is the difference between Files.walk.filter and Files.find?

This code searches for a specific file: Stream findMyFile = Files.find(Paths.get("c:\\temp\\pathtest"), Integer.MAX_VALUE,(p, a) -> p.endsWith("test.txt") && a.isRegularFile()); Stream findMyFileSecond =…
Adrian Krebs
  • 4,179
  • 5
  • 29
  • 44
8
votes
3 answers

Java 7 NIO watchservice vs jpathwatch

The project I'm working has been using Java 6 and jpathwatch (.95) and is now upgrading to Java 7. Currently on Windows 7 and 2008 Server. I'm refactoring areas of code to use the new Java 7 NIO and is relatively straight forward - even using the…
mjash
  • 245
  • 1
  • 7
8
votes
2 answers

Java 7 NIO.2 Files.getLastModifiedTime time zone

I'm writing a program which needs to determine files/directories last modified time. I want to handle this time using Joda Time, and I'm using Java 7 NIO.2 class Files to get file last modified time. Its getLastModifiedTime() method returns an…
Vladimir Matveev
  • 120,085
  • 34
  • 287
  • 296
7
votes
3 answers

Thread-safety of NIO2 CompletionHandler

Is the following code thread-safe? If so, what guarantees the safe publication of the ByteBuffer instance to the thread executing the CompletionHandler? AsynchronousSocketChannel channel = ... ByteBuffer buf =…
Malt
  • 28,965
  • 9
  • 65
  • 105
7
votes
1 answer

Java AsyncHttpClient: broken file while writing from LazyResponseBodyPart to AsynchronousFileChannel

I use AsyncHttpClient library for async non blocking requests. My case: write data to a file as it is received over the network. For download file from remote host and save to file I used default ResponseBodyPartFactory.EAGER and…
Peter Kozlovsky
  • 633
  • 2
  • 10
  • 28
7
votes
0 answers

Print Decoded Data after SSLEngine Handshake is FINISHED

How do I get the decoded data after the SSL Handshake is complete? At the moment it seems to decrypt just some of the data. Steps to reproduce Save and Run this code Go to https://localhost:1500 - You should notice the beginning and end of the…
user1191027
7
votes
1 answer

Do valid java.net.URIs for nested archives exist?

It's possible, although perhaps ill-advised, to read archive formats that are basically renamed .zip files (.ear, .war, .jar, etc.), by using the jar: URI scheme. For example, the following code works well when the uri variable evaluates to a…
Justin Garrick
  • 14,767
  • 7
  • 41
  • 66
7
votes
4 answers

In jdk7 watch service API, when will the OVERFLOW event be thrown?

The documentation for the overflow states: OVERFLOW – Indicates that events might have been lost or discarded. It does not say under what circumstance should I expect event to be lost or discarded? At first I thought it would be a result of…
Vitaliy
  • 8,044
  • 7
  • 38
  • 66
6
votes
3 answers

How to check that file exists inside a zip archive?

How to check that file exists inside a zip archive? For example, check whether app.apk contains classes.dex. I want to find a solution that uses Java NIO.2 Path and without extracting the whole archive if possible. I've tried and it didn't…
naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
6
votes
2 answers

Should I close Streams created with java.nio.file.Files.newInputStream?

In the stream tutorial, nothing is said about closing streams gained from Files.newInputStream( path ). Only some obscure: Whether the returned stream is asynchronously closeable and/or interruptible is highly file system provider specific and…
math
  • 8,514
  • 10
  • 53
  • 61
6
votes
3 answers

Merge huge files without loading whole file into memory?

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 =…
nimo23
  • 5,170
  • 10
  • 46
  • 75
1
2
3
11 12