Questions tagged [nio]
NIO is Java 'New I/O' introduced in 1.4, providing non-blocking and multiplexed network I/O; 'direct' (native) buffers; file locks and mapped files; and character set codecs.
3,013
questions
2
votes
1
answer
40
views
+50
Test performance between Tomcat BIO and NIO connectors
I would like to observe the performance improvement of using NIO connector vs BIO connector on Apache Tomcat. The differences between BIO and NIO is, (quoting from DZONE),
The BIO connector (blocking ...
0
votes
0
answers
19
views
serverSocketChannel.accept() returns null
I am trying to write a simple client server program in Java NIO.
Here is the code:
package org.lb;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.SelectionKey;...
0
votes
0
answers
29
views
Java NIO: Problem creating files in a renamed folder when observing a file tree
I am currently working on a project with Java NIO which should simply observe all subdirectories and files located in a specific directory. When a Delete or Create event happens it should be printed ...
0
votes
0
answers
46
views
TinyRadius Netty RadiusClient test program does not shutdown & return despite closing the NioDatagramChannel & shutting down NioEventLoopGroup
This is regarding the use of tinyradius-netty & the mechanism to properly close the channel & shutdown (as part of app shutdown).
Here is the sample code on the tinyradius-netty public git ...
1
vote
1
answer
75
views
Replace a file, if existing, or else create a new file, using NIO.2 in Java 7+
The Files.write & Files.writeString methods in Java 7+ are a concise handy way to write text to a file.
try
{
Files.write (
Paths.get ( "/Users/My_UserName/Example.txt" ) ...
0
votes
1
answer
40
views
Read from File, then write to File under same FileLock?
I want to perform a read and a write under the same lock. Once the lock is acquired, I want to read the file, do some data manipulation, then write that data to the same file.
I have tried the ...
0
votes
0
answers
74
views
Why doesn't server read again from client?
This works for one iteration in while loop. Selector recognizes readable key, then recognizes writable key and client got answer from server. However, in second iteration is the problem. Selector ...
0
votes
0
answers
28
views
Limiting the maximum number of client connections in an NIO Selector
I have an asynchronous NIO Server using a regular java.nio.channels.Selector that accepts clients (in non-blocking mode, i.e. I do socketChannel.configureBlocking(false) for each accepted client).
...
1
vote
1
answer
74
views
Apache Ignite: Closing NIO session because of unhandled exception
I recently get this error every time when I try to load around 100G data into ignite. (Actually is around 50G, with one backup for this cache). Typically this error happens after it successfully ...
0
votes
0
answers
25
views
Java NIO server never finds any SelectionKey
Using this example of a non-blocking NIO server, the non-blocking client is able to connect to the non-blocking NIO server. Even when the server stops running, the client repeats "broken pipe&...
0
votes
0
answers
15
views
In Java, is the AsynchronousFileChannel open() method a "blocking" operation?
I need to open an async file channel in a Netty handler. Do I need to do that on a background thread?
It seems logical that AsynchronousFileChannel's open() method would be a blocking operation but I ...
0
votes
0
answers
36
views
Using Java deleting files with walkFileTree and SimpleFileVisitor - FileSystemException
When I'm trying to delete files very few files in the same directory get access issues as below in error logs. There are 8 files in that directory but only 2 files are not able to delete and throwing ...
0
votes
0
answers
55
views
java nio create directory cyrillic name
I want create directory with cyrillic name. But when I did it, I get normal folder and folder with not correct name.
How I can fix it? I need only 1 folder with correct name.
public void addEntry(...
0
votes
0
answers
22
views
How to know whether or not a RST sent by peer , while read/write on a SocketChannel. (JAVA)
Is there a graceful way to solve this problem, given a SocketChannel and a readable event ,to determine whether or not the RST has been sent by the peer.
I use kill -9 to eixt the client process, and ...
0
votes
2
answers
78
views
How to check content-length match after download image in java Nio?
static void downloadWebp(String url) {
URL url1;
try {
url1 = new URL(url);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
...
-2
votes
1
answer
96
views
Create new file in resource directory
The task is to create a new file in the existing resource folder (named "local", for example)
File file1 = new File("src/main/resources/" + "local" + "/" + &...
2
votes
0
answers
59
views
NIO SelectionKey processing should it be single or multi threaded?
I m reading how Selector can multiplex multiple channels and do I/O operations whenever the channels are ready to be processed. Many online tutorials/resources uses something similar where they ...
0
votes
0
answers
41
views
Can Java copy files with the lpProgressRoutine callback?
I read here that Java NIO's Files.copy(Path, Path, CopyOption...) method uses the Windows function CopyFileEx on Windows machines. The documentation for this function describes a lpProgressRoutine ...
0
votes
2
answers
131
views
How to check if a file is owned by the current user in Java?
I want to show a warning if a file is read that is not owned by the user that started the JVM.
In my application, this file can make the program write arbitrary files. So I want to reduce the risk of ...
0
votes
0
answers
88
views
NFS volume read-write concurrency control between multiple containers using Java NIO FileChannel Lock
I have a NFS based volume mounted into multiple containers. The containers need to read & write(append) to the same files resided into the volume.
I am thinking to use Java NIO FileChannel Locks ...
0
votes
1
answer
136
views
How effectively download file by url and convert to org.springframework.core.io.Resource?
I have a link that opens a file. The file can be a pdf or an image. I need to load this file and then use it in a service like org.springframework.core.io.Resource.
My code downloads a file and saves ...
1
vote
1
answer
94
views
Why does this Netty basic example not work?
I am trying to learn netty to implement a multicast udp server that is able to listen to multiple multicast groups (and potentially in the future multiplex channels that are listening to separate ...
1
vote
0
answers
48
views
Java desktop application with continuous communication between many clients and one server. How to properly set communication between devices?
I am creating a javafx application that can communicate with a server over the internet and I need some clarification on how things should work.
I am using an SSLSocket between the client and server (...
0
votes
1
answer
154
views
Files.exists() returning false when a regular file is tested and true when a directory is tested
I created a directory called "examples" inside my current working directory (C) and inside it I created a .txt file called "test.txt", but when I test the file using Files.exists(),...
0
votes
0
answers
58
views
java socketChannel::finishConnect throws NoConnectionPendingException even though connect has been successful
I have the following Java code:
class TestClient {
...
SocketChannel channel = SocketChannel.open()
channel.configureBlocking(false)
SelectionKey key = channel.register(...
0
votes
1
answer
38
views
Read from non blocking socketChannel to Protobuf
I'm trying to create simple server-client app using Java NIO.
Here are my Protobuf classes:
message ArrRequest {
int32 n = 1;
repeated int32 array = 2;
}
message ArrResponse {
int32 n = 1;
...
-1
votes
2
answers
44
views
Sending message between ServerSocket and client
I need to send a message from the ServerSocket to the client when the key is writable, I think that the message is being sent in the right way but when I try to read it on the client I get this error:
...
0
votes
0
answers
100
views
I have a question on Nio's selector and threads part
Please help .
When you first start the server, create a thread pool in advance (5 threads) and create 5 selectors to read, pass one selector to each Runnable, and immediately send the submit function ...
0
votes
2
answers
91
views
Detect if 2 paths are hard-linked together
If I have 2 Paths for files, both share the same FileStore, how can I verify with Java 17 whether they are pointing to the same file on disk (are hard-linked)? For Unix-like systems there seems at ...
0
votes
1
answer
154
views
Java NIO non-blocking read and write operations
I'm developing for a project a NIO server that takes as input a message from the client containing the times of running for the read and write operations.
I have a problem because at the first ...
2
votes
1
answer
386
views
How is Apache NIO HttpAsyncClient performing non-blocking HTTP Client
How is Apache NIO HttpAsyncClient able to wait for a remote response without blocking any thread? Does it have a way to setup a callback with the OS (I doubt so?). Otherwise does it perform some sort ...
0
votes
1
answer
153
views
What does it mean when Java could not read the lastModifiedTime attribute on Windows?
A customer has lots of following stacktraces appearing in the logs of my application.
It runs on WildFly 18 and JDK 11 on Windows Server.
2022-10-14 14:36:19,382 ERROR [io.undertow.request] (default I/...
-2
votes
2
answers
296
views
Skip directory creation if directory already exists
I want to create a Quartz job that reads .csv files and moves them when the file is processed. I tried this:
@Override
public void execute(JobExecutionContext context) {
File directoryPath = new ...
0
votes
0
answers
34
views
Maintaining a list of SocketChannels that are unique
I am using Java NIO and selectors to get instances of SocketChannels. I need to attach each instance of a SocketChannel that I get from the selector to an encryption key that is unique to each ...
0
votes
0
answers
289
views
Why does Files.copy cause out of memory error when creating large file
I have a simple method that creates a tar file with a collection of compressed files inside:
private byte[] gzipCompress() throws IOException {
File source = super.getPath();
...
1
vote
5
answers
1k
views
The process cannot access the file because it is being used by another process when file is moved
I want to create a Quartz job which reads .csv files and moves them when file is processed. I tried this:
@Override
public void execute(JobExecutionContext context) {
File directoryPath = new ...
0
votes
2
answers
401
views
How to release Pooled direct ByteBuf in netty when written after by ChannelHandlerContext?
In my c/s project, c/s need to exchange fixed-size message with netty.
I use pooled direct buffer to buffer message.
Code just like below:
public void channelRead(ChannelHandlerContext ctx, Object msg)...
-1
votes
1
answer
57
views
how to move different sub directories and files in to one directory in java
i have a requirement like to move all directories that have in multiple directories need to move into one directory
eg:
enter image description here
i wanted to move all sub folders in to one folder ...
0
votes
0
answers
76
views
It's possible with a non-blocking SocketChannel to read all present buffered data while preventing further receiving from clients?
The use case is, in an only reading server, when a shutdown request is received to prevent clients to send more data but do the best effort to process possible data in buffers.
I've tried with ...
0
votes
2
answers
70
views
How to get the jar files in the specified directory and why is PathMatcher not working?
I'm trying to get *.jar files in a specified directory (no recursing subdirectories), I think my code is no problem, but the results are incomprehensible, am I doing something wrong?
import java.io.*;
...
0
votes
0
answers
129
views
File deleted before being read, InputStream from file, DELETE_ON_CLOSE
Why is my file being deleted before I read it? How is that even possible?
I am using the api java.nio.file.Files.newInputStream(<path>, StandardOpenOption.DELETE_ON_CLOSE) to create an input ...
1
vote
0
answers
282
views
how netty server detects the close of netty client
When a connected netty client is forced closed, the netty server will detect the close action and throw IOException:
java.io.IOException: 远程主机强迫关闭了一个现有的连接(In English: the remote host forcely closed an ...
-1
votes
3
answers
174
views
how to write very long string to a gzip file in java
i have a very long string, and want to wirt to a gzip file
i try use GZIPOutputStream to write a gzip file
but where has exception when i use string.getBytes()
java.lang.OutOfMemoryError: Requested ...
2
votes
1
answer
259
views
JavaFX - ProviderNotFoundException: Provider not found
I am building my JavaFX application together with the required JVM (openjdk-18.0.2.1) components using in jlink.
The build script is almost no different from being created using IDEA by default.
...
-2
votes
1
answer
35
views
when should I remove/register the 'read operation' in java nio selector? [closed]
in my understanding,'read operation' is always being registered.At some places, i find the fact that 'read operation' could be removed
0
votes
0
answers
193
views
How to set read attribute false on a file?
I've tried this:
File file = new File(path);
file.setReadable(false);
System.out.println(file.canRead()); // returns true
How can I make a file unreadable with Java code ?
0
votes
1
answer
155
views
SwiftNIO: How "expensive" is transformation in each ChannelHandler?
Checking this tutorial: https://rderik.com/blog/understanding-swiftnio-by-building-a-text-modifying-server/
One thing I do not understand that the main point using NIO directly is to increase speed of ...
-2
votes
1
answer
110
views
How to verify fields inside a .txt file in Java? [closed]
I have a .txt file which i want to read using Java and then verify if some particular fields is equal to a given string.
Now, i want to validate that if line/record starts with 03, then see of 7th ...
0
votes
0
answers
958
views
Unexpected error [32] writing data to the APR/native socket
Just upgraded java springboot project to:
springboot 2.6.6
tomcat 9
jdk11
war
some pointers:
I dont use websockets in my project
I dont write any files to my server
started getting this exception:
...
2
votes
2
answers
406
views
How do I integrate Tomcat APR protocol connector with embedded Tomcat 9 in Springboot 2.3.12?
I need to use APR protocol connector to replace the default NIO protocol connector in embedded Tomcat 9 of Springboot 2.3.12, may I ask how to implement it?