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.
2,987
questions
0
votes
0
answers
34
views
Problem with java.nio.ByteBuffer and java.nio.SocketChannel: java.lang.OutOfMemoryError: Direct buffer memory
I'm facing with a problem with the java.nio.ByteBuffer while I'm reading data from SocketChannel.
Let's begin this with my code:
Here my readFromSocket method which is invoked when i have some ...
2
votes
0
answers
86
views
Java Object.notifyAll() blocks for long time while consuming high CPU
We have a large enterprise telecom application running over OpenJDK8 (25.171-b10) on RHEL6.10.
We observe a very strange issue that occurs randomly in production servers.
The process starts consuming ...
1
vote
1
answer
44
views
How do i catch an HTTP request header parse error thrown by Http11Processor?
I am running a spring boot application with an embedded Tomcat server on an AWS EC2 instance. I use Log4J2 to log both the spring boot logs as well as the tomcat server logs.
Tomcat will usually ...
-1
votes
0
answers
38
views
Unexpected error [32] writing data to the APR/native socket
Just upgraded project to: springboot 2.6.6, tomcat 9, jdk11
started getting this exception:
java.io.IOException: Unexpected error [32] writing data to the APR/native socket [140,717,649,426,640] with ...
0
votes
0
answers
64
views
AsyncHttpClient with Netty: High response time as compared to curl. High TCP connection time and SSL handshake
I am using AsyncHttpClient to make an http request. I am using Netty and seeing very high response time (total time to execute HTTP request).
For an endpoint (Only running 1) which has an actual ...
0
votes
1
answer
37
views
Why doesn't nio filesystem move work outside try block?
I am trying to use nio's filesystem to rename files in a zip file.
The example below from the documentation works for me.
import java.util.*;
import java.net.URI;
import java.nio.file.Path;
import ...
1
vote
1
answer
39
views
How to use Java nio's Files.move in Matlab
I want to use the java.nio.file.Files.move() method in Matlab.
Although I only need the default behavior, Matlab requires all 3 inputs or would throw the No method ... with matching signature found. ...
0
votes
0
answers
31
views
Difference between CharBuffer/ByteBuffer and other arrays
I'm unable to understand what is the difference between CharBuffer/ByteBuffer and other Arrays(say a character array).
I know CharBuffer(or Buffers in general) was added as part of java NIO update, ...
0
votes
0
answers
16
views
java nio end a read from a tcp socket
I'm using java NIO to read/write messages into a socket
Both client and server have a Bytebuffer of a fixed dimension but both want to send and receive messages of a nuknown length
The send function ...
1
vote
0
answers
35
views
java.nio: Constructing BigInteger from ByteBuffer
I need to deserialize BigInteger instances from byte buffers and do it fast. The combination of new BigInteger(byte[], int, int) and ByteBuffer#array() seems to be the best option, but it only works ...
0
votes
0
answers
29
views
Correct way to send a string through tcp using java nio
I'm trying to send/recv a String using a Bytebuffer of fixed dimension, no matter what dimension is the string
Both client and server are composed by 2 classes, the main and the Client/Server, witch ...
2
votes
1
answer
88
views
Why Java Files.walkFileTree throw a NoSuchFileException?
I'm using Files.walkFileTree to delete a directory. When running this code in CentOS, I got an error in my server log.
if (Files.exists(p)) {
if (Files.isDirectory(p)) {
Files.walkFileTree(...
0
votes
0
answers
19
views
MarkerFileExclusiveReadLockStrategy .camelLock file stuck on process termination. How to remove .camelLock file?
We are using MarkerFileExclusiveReadLockStrategy to poll file from input location and avoid reading same file in multiple service instances. Comments on MarkerFileExclusiveReadLockStrategy class,
/**
...
0
votes
0
answers
34
views
How do I download a file in chunks using NIO channels?
The server which serves the file I am downloading limits users to a 10-megabyte per second download speed. If there is any speed greater, the user will be throttled. In order to achieve this, I ...
0
votes
0
answers
37
views
Why does niO's selector selectedKeys removal seem not to work?
After the server receives data for the first time, there will be data in each loop of selectedKeys. I would like to ask if the remove operation is not effective or there is some other reason
server ...
1
vote
1
answer
61
views
java nio FileLock.release() throws ClosedChannelException and truncates my file
I've got e:\myfile.txt with some random contents:
abcabcxyz...abc
Then I try to use nio FileLock like below:
import java.io.*;
import java.nio.channels.*;
public class FileLockTest{
public static ...
0
votes
0
answers
29
views
NIO endless loop of OP_READ [duplicate]
I have a NIO problem in Java.I am trying writing a read TCP data stream program.TCPDemoNIO is the code.The problem is:
when data coming, it can read first,but then OP_READ is always triggered.So the ...
1
vote
1
answer
35
views
Only download a certain amount of files per second - "decrease" the download speed
It appears to me that my server only allows 60 files to be downloaded per second, but I have 63 of them - all tiny, YAML files. As a result, the last 3 files don't get downloaded and throw error 503. ...
-4
votes
1
answer
108
views
How to programatically modify Libre Office odt document in java? [closed]
package army;
import org.apache.commons.io.FileUtils;
import org.odftoolkit.odfdom.doc.OdfTextDocument;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.stream.Collectors;...
0
votes
0
answers
35
views
Copying large file taking more time
I have used code mentioned in below website but for it is always taking More than 2 mnts to upload 570MB file.
https://thomaswabner.wordpress.com/2007/10/09/fast-stream-copy-using-javanio-channels/
0
votes
0
answers
107
views
Getting exception org.apache.commons.io.FileExistsException while renaming file using Apache Commons
I need to upload a file to different folders using sftp . The data in file is same but name of the file in each folder is different . So I decided to rename the same file before sending it to ...
0
votes
0
answers
52
views
FileChannel not writing special characters properly
I'm trying to write some text into a file using a FileChannel. So far everything works fine except for the fact that umlauts are not written correctly.
Path fileChannel = Paths.get("c:/channel....
0
votes
0
answers
109
views
How to download file from a URL and save/replace it in a folder using Java 8?
So, I need to download 2 csv files which include pricing details for some AWS services.
https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AWSStorageGateway/current/index.csv
https://pricing.us-...
4
votes
0
answers
235
views
Does java nio read/write file actually non-blocking io?
I'm learning about non-blocking i/o terms. Mainly, I'm learning java Nio. I'm trying to understand non-blocking i/o better and observe how it works in the implementation with Java Nio.
I read a dozen ...
1
vote
1
answer
120
views
Selecting a particular Column in a CSV-file Dynamically
I have this CSV file:
id,name,mark
20203923380,Lisa Hatfield,62
20200705173,Jessica Johnson,59
20205415333,Adam Harper,41
20203326467,Logan Nolan,77
And I'm trying to process it with this code:
try (...
0
votes
0
answers
59
views
Why does client not receive final server answer in non-blocking client-server app?
I am trying to figure out NIO in Java doing some simple client-server project.
The case is I have to concurrent clients in cached thread pool executor, who are communicating with single-threaded ...
1
vote
0
answers
42
views
Redis server system call context switch statistics
The official article introducing Redis pipelining emphasis that the read() and write() system call has a huge negative impact on request processing because of context switch:
Pipelining is not just a ...
0
votes
1
answer
33
views
AsynchronousFileChannel not creating subdirectories
Below program throws "java.nio.file.NoSuchFileException" when subdirecties doesnot exist in path. Could some one please help how can I acheive this ? I want to insert records in asyncronous ...
0
votes
2
answers
109
views
How to get the inmediate child directory of a file path in Java?
I want to navigate the file system and get the path to the child of a directory (if exists) without the root.
For example:
Input: Users/Documents/SVG
Output: Documents/SVG
My solution so far is to ...
0
votes
1
answer
44
views
selecting one file/folder from the directory
I am building a program that manages the quantity and distribution of files and folders from folder "a" to "b" in java (io , nio, apache commons-io) libs.
I got stuck at a point ...
0
votes
1
answer
170
views
when using a zip file as a FileSystem the zip file is not being update
I want to manipulate a jar using the standard nio Files and Paths methods. So, Java has a way to do this by creating a zip FileSystem:
try {
zipFS = FileSystems.newFileSystem(zipDisk, ...
0
votes
1
answer
53
views
Loading all classes in an external JAR using NIO
I have a plugin folder that contains some JARs, and I want to load all of their *.class. I see a lot of answers with JarFile or ZipEntry stuff. However, I would like to do this using java.nio package ...
1
vote
1
answer
114
views
Java Selector for socket client not waked up after changing of interested ops from different thread
I use Java Selector for both server and client. For Server side it works perfect. It stops the thread when i call select() and wakes up when i change interest ops and it is ready for this operation..
...
0
votes
0
answers
40
views
Why my DatagramChannel socket can't read my custom object?
I'm developing a real time application in Java with communication between one server and one client with UDP socket.
It worked fine when i send and receive string but when i tried to receive a custom ...
0
votes
0
answers
55
views
Why my `Selector` always return same `SelectionKey` in java NIO?
My NetSelector class:
class NetSelector(
private var selector: Selector,
private val emptySelectThreshold: Int
) : NetSelector {
private var keyIterator: ...
0
votes
0
answers
89
views
How to append batches of stream data to one CSV file using Java NIO Package
I am reading data from API response in batches of bytes which is of Content-Type = text/CSV and using Java's NIO package to transfer bytes between two Channels. I want to write API responses in ...
0
votes
1
answer
139
views
Character encoding issue while reading api response using NIO
I am reading data from API response which is of Content-Type = text/CSV and using Java's NIO package to transfer bytes between two Channels.
While the code execution is in progress, I get the below ...
0
votes
0
answers
79
views
Apache sshd-sftp server over vfs2
I’m looking to build an Afro server with pluggable file systems.
The apache mina ash’s-sftp server provides for file system implementations using nio.
I would like to use a number of providers though ...
0
votes
1
answer
48
views
How to listen `disconnect` event in Java NIO?
In java NIO server, we can register SelectionKey.OP_ACCEPT, listen and read channel from selector.select() and selector.selectedKeys().
But how to listen to the 'disconnected' event?
Trying channel....
0
votes
0
answers
18
views
Should I cancel the key when SocketChannel#connect returns true?
When SocketChannel#connect returns a true for a selector-registered SocketChannel, should I cancel the SelectionKey?
final var client = SocketChannel.open();
client....
0
votes
1
answer
212
views
Reliable alternative to Java Watch Service
I am using Java nio's WatchService but I find it quite unreliable for the following use cases:
When a very big file (>500 megs) is written to the directory being watched, if I rely on ENTRY_CREATE ...
0
votes
1
answer
139
views
Netty ChannelInboundHandlerAdapter async/multithreading
I'm having trouble grasping the concepts behind multithreading in netty, EventLoopGroup (MultithreadEventLoopGroup), MultithreadEventExecutorGroup, DefaultEventExecutorGroup
I am trying to understand ...
0
votes
0
answers
248
views
How to Resolve Security Issue in this sample code - Checkmarx - Incorrect Permission Assignment for Critical Resources
This is my sample code to read a file and display its contents.
public class TestClass3 {
public static void main(String[] args) {
try {
String pathString = "...
0
votes
0
answers
26
views
Why is the status of the server channel still connected after my client is forcibly closed?
server code:
public static void main(String[] args) throws IOException {
Selector selector = Selector.open();
ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
...
1
vote
1
answer
355
views
Non-blocking reading from the file using Reactor
Do you know if it's possible to create Flux of file lines really non-blocking way?
The best solution I've found is next:
Flux.using(
() -> Files.lines(PATH),
Flux::fromStream,
...
0
votes
1
answer
425
views
FileSystems.getDefault().getPath() vs Paths.get() and resource leakage
If I use FileSystems.getDefault().getPath() it holds resource at FileSystems.getDefault(). Few tools like sonar, coverity give high impact issues of resource leak for using this.
If I replace it with ...
1
vote
2
answers
86
views
Can I get sameFile is true after copy in Java nio?
I thought the result is true when Files.isSameFile invoke after fileB is copied from fileA, because fileA is same with fileB. However, the result is false.
Path pathA = Path.of("A.txt");
...
5
votes
1
answer
316
views
What's the space-efficient way to read multiple ByteBuffers into a single String?
I'm writing a decoder that will receive a sequence of byte buffers and decode the contents into a single String. There can be any number of byte buffers, each containing any number of bytes. The ...
0
votes
0
answers
31
views
NotDirectoryException when using Files.copy() to copy from visible storage into getExternalFilesDir(null)
I've been trying to copy files from the visible storage into the app-specific storage and decided on getExternalFilesDir(null) because of the rather large files I'm trying to copy. When testing, both ...
0
votes
0
answers
76
views
How to fix "An error occurred while installing nio4r (2.5.8), and Bundler cannot continue."
enter image description here
i got such error and i have no idea how to solve it, how can i solve it? I am using ubuntu 20.04.