nio

Asynchronous channel close in Java NIO

Suppose I have simple nio based java server. For example (simplified code): while (!self.isInterrupted()) { if (selector.select() <= 0) { continue; } Iterator<SelectionKey> iterator = selector.selectedKeys().iterator(); while (iterator.hasNext()) { SelectionKey key = iterator.next(); iterator.remove(); Selectabl...

SSL and SocketChannel

Ideally, I only need a simple SSLSocketChannel: I already have a component that reads and writes message over ordinary SocketChannel, but for some of those connection, I have to use SSL over the wire; the operations over that connections, however, are the same. Does anyone knows a free SSLSocketChannel implementation (with the appropria...

how to send data to client using nio

Is there any simple example for reading data from server and sending the response to client using java NIO socket channel Thanks, Deepak ...

How does SocketChannel know when reading a file is completed?

I am using socket channel and NIO concept to read data from client. How does Socket Channel knows when reading a file is completed? ByteBuffer byteBuffer = ByteBuffer.allocate(BUFSIZE); int nbytes = socketChannel.getChannel().read(byteBuffer); I am reading the data all at once if the data is small, but if the data is large, I read the...

how to write data to socket channel

is there any small working program for recieving from and sending data to client using java nio. Actually i am unable to write to socket channel but i am able to read the incoming data how to write data to socket channel Thanks Deepak ...

how to send and then read \n using SocketChannel in Java

I am using the SocketChannel Java class for a client/server application. I can send and retrieve data. But if my data contains '\n' then I do not read the correct data. For example sending data = "Hi dear" receiving data = "Hi dear" sending data = "Hi dear\n\n i am fine" receiving data = "Hi dear" sending data = "Hi dear\\n\\n i am f...

problem with writing large data using java nio socket channel

I can sent small data using java nio. But If I want to send a very large data then my socket channel did not work fine. message = "very large data"+"\n"; ByteBuffer buf = ByteBuffer.wrap(message.getBytes()); int nbytes = channel.write(buf); all the data is sent. I want to read data from server so i am using BufferedInputStreaReader....

How to read huge data in socket and also write into socketchannel

How to read a very big data using DataInputStream of socket If the data is in String format and having a length of more than 1,00,000 characters. Also How to write that big data using SocketChannel in java Thanks Deepak ...

help needed in threading implementation in NIO

I want to have create NIOServer which reads data from client using 1 thread and writes data to the client using another thread. also accepting client connection will be in some other thread. Is there any online help Thanks Deepak ...

How Can I create different selectors for accepting new connection in java NIO

I want to write java tcp socket programming using java NIO. Its working fine. But I am using the same selector for accepting reading from and writing to the clients. How Can I create different selectors for accepting new connection in java NIO, reading and writing. Is there any online help. Actually when I am busy in reading or writing...

how to read and write data and accepting connection using socket channel

I have created a simple server client application using java NIO. I used a single selector there for accepting connection, reading data and writing. But I want an application where 1 selector will be busy in accepting the connection while the 2nd selector will read the data and the 3rd selector will write the data. Means I donot want to...

NIO Server not able to listen to client

Hi I am trying to implements a simple Java NIO server; which registers the socketChannel with the selector. Hence I wish to listen to client and send some response back. After the socketChannel is registered with the selector, even if client(non NIO) sends some data, Server is not able to read; howerver the key generated is still being i...

How can I find the byte encoding of a TIBCO Rendezvous message?

In my Java application, I am archiving TIBCO RV messages to a file as bytes. I am writing a small utility app that will play the messages back. This way I can just create a TibrvMsg object from the bytes without having to parse the file and construct the object manually. The problem I am having is that I am reading a file that was cre...

How do I define my own SelectableChannel?

How would I define a new type of java.nio.channels.SelectableChannel (say for serial ports)? ...

SSLEngine and close

Hi, I've implemented an helper module that lets me obtain clean data from a channel used with SSL and write encrypted data into it: this is the relevant interface (I've also some non-abstract methods in that class, so doesn't say to me that "DataProvider should be an interface" ;)): public abstract class DataProvider { // Notify th...

Java Large Files Disk IO Performance

I have two (2GB each) files on my harddisk and want to compare them with each other: Copying the original files with Windows explorer takes approx. 2-4 minutes (that is reading and writing - on the same physical and logical disk). Reading with java.io.FileInputStream twice and comparing the byte arrays on a byte per byte basis takes 20...

How to change image permission mode to 777 using java code?

Hi All : I want to give permissions mode value "777" to image file using java code. How can i give that using java?. Because i cant delete the image with default permission mode "664". Please help me ...

Selector doesn't block after a wakeup() on windows

I'm referring to that: on Windows my selector, after a wakeup(), doesn't block anymore and then hogs my cpu time. This is for an end-course project, where it is only required to work in our linux network, so in theory I can just ignore the problem and live an happy life, but I want to fix it anyway. Anyone could suggest me a workaround...

Is it possible to read the Process stdout InputStream into an NIO ByteBuffer?

Is it possible to use NIO to process the stdout from a Process? I have it working with java.io, but this is something of an exercise to learn a bit more about NIO and to explore the possibility of performance improvements. Basically I want to stream a large volume of text from stdout into a buffer as fast as possible without blocking, ...

java.nio channels buffers streams terminology

Does anybody have a good analogy (or, failing that, a good resource) for describing the relationships between buffers, streams, readers, channels, selectors etc. in java.io and java.nio? Thanks ...