nio

Efficient file transfer from Java server to multiple C++ clients?

I need to transfer files fast over the Internet from a Java server to C++ clients, where often many clients would need the same files. I was looking at say transferTo() in Java which sounds like it would be a decently optimized function to send files. However, I'm not sure when I use transferTo() how to best receive that in C++ (i.e. i...

java nio Selector wakeup

Please point/provide me an working example of selector.wakeup(); method between two threads. I tried to create a simple program where a thread is waiting on selector.select() method. Second thread creates some sockets and tries to register with the selector; on which the first thread is blocked. Hence I need to use selector's wakeup m...

NIO file channel transfer problem on iSeries

Hi all, I'm having a problem with some Java NIO code running on an iSeries box (JDK 1.5). Basically the code is splitting a file up into chunks part of a file to another smaller files. The same code has been operating on other iSeries boxes for some time with no problems. Here's the code snippet: //copy original data file content to te...

reusing socket channels

im trying to implement a client app with an asynchronous connection. i want to know if i can reuse a SocketChannel object after it has failed to connect to a server. SocketChannel channel = SocketChannel.open(); channel.configureBlocking(false); InetSocketAddress addr = new InetSocketAddress(host, port); SelectionKey key = channel....

Should I use (non-blocking) NIO for UDP?

According to this post, UDP just doesn't block. Are there any advantage using the (non-blocking) NIO API for UDP? Or should I just use the easier "traditional" io API? ...

SSL and NIO Non-blocking Sockets

How do you recommend making a highly scalable SSL client? Currently, I'm using plain Sockets to connect to the Apple APNS server which requires a non-HTTP SSL sockets. I considered using the NIO library, but it is lacking a SSLSocketChannel, and I couldn't find a good library or a smooth tutorial on how to roll out your own. ...

Java SocketChannel Eating my bytes

Hi, I created a SocketChannel to a remote server to send and receive messages on Tomcat. To receive messages from a remote computer, I used a thread dedicated to task (only this thread will read from the socket, nothing else). When some bytes are received at the SocketChannel (I keep polling the SocketChannel on non-blocking mode for n...

Java's ReadableByteChannelImpl inconsistent behaviour

When I create a channel out of the InputStream with Channels.newChannel(is) java standard library returns a ReadableByteChannelImpl, which is: private static class ReadableByteChannelImpl extends AbstractInterruptibleChannel // Not really interruptible implements ReadableByteChannel { InputStream in; ...

How do I rename (not move) a file in JDK7?

Hello! I'm a bit confused with all these new File I/O classes in JDK7. Let's say, I have a Path and want to rename the file, it represents. How do I specify the new name, when again a Path is expected? Path p = /* path to /home/me/file123 */; Path name = p.getName(); /* gives me file123 */ name.moveTo(/* what now? */); /* how to renam...

In-memory version of Java's FileChannel

I'm in the process of making some changes to a library that I'm using. In order to reduce memory usage the library is writing its temporary data to disk instead of keeping it in memory. However, for my usage scenario it is more efficient to keep it in memory. It also has some concurrency issues, because it has constant names for its temp...

Java: use NIO with System.in

Is it possible to use NIO with System.in? I would like to somehow treat 'stdin' as a selectable channel. Has anyone found a way to do this? ...

How should I deal with a very large array in Java?

I have an algorithm which currently allocates a very large array of doubles, which it updates and searches frequently. The size of the array is N^2/2, where N is the number of rows on which the algorithm is operating. I also have to keep a copy of the entire thing for purposes associated with the application surrounding the algorithm. ...

How to properly send data via MINA?

I'm attempting to get started with MINA, and all of the examples seem to have data written to the session, rather than making use of a method that can write the same type of data over and over. I'm trying to make use of org.apache.mina.filter.codec.demux.MessageEncoder / MessageDecoder to encode / decode messages, which will allow me to...

Java.NIO InvalidIndexException - how to read and write with random access to large files.

I've created a java.nio.MappedByteBuffer around a java.io.RandomAccessFile (a file which is only 54 KB in size). The resulting MappedByteBuffer has a "capacity" and "limit" of around 12 KB, so when I try to invoke mybytebuffer.get(i > 13044) or mybytebuffer.put(i > 13044, value) it throws an InvalidIndexException. All of this behavior i...

Where is java.nio.file

I'm new to java so I am not familiar with the framework yet. I am reading java documentation that tells me there should be a java.nio.file namespace. But when I attempt to import it the precompiler is complaining that it doesn't exist. What's up? ...

Java, C++, NIO, mmaped buffer, synchronization

Exposition: I am on Linux / Mac. Part of my code is in Java, part of my code is in C++. They both have the same file mmapped for fast communication. I want to synchronize the Java & C++ code. I know the following: 1) given two threads in Java, I can use Locks / monitors. 2) given one piece of code in Java, one in C++, I can have t...

get FileChannel without using java.io.* (use pure NIO)

Recently I got a comment to this answer that I should stay away from java.io if I want to use "pure NIO". This is the simplified code (copy a file): private static void copy(File source, File destination) throws IOException { long length = source.length(); FileChannel input = new FileInputStream(source).getChannel(); FileCha...

MINA: Is finishDecode where I send a response message?

In using Apache MINA, I'm sending a login request from the client, which is interpreted on the server via LoginRequestDecoder (implements org.apache.mina.filter.codec.demux.MessageDecoder). I now want to send a response (LoginResponse) that includes a success/failure code. Should I be sending the response from the LoginRequestDecoder's...

Is there a want for a Java 7 Cloud Server Framework that is not Spring/Tomcat based?

I have a question. Is there a demand out there for a small, lightweight, Java 7 based open source project that is geared toward making Cloud services more elegant? I have written several servers in my lifetime, and was curious if there was a need for this. My thoughts were to keep it simple, lightweight, and use the Java 7 NIO 2 funct...

Recursively list files in Java

How do I recursively list all files under a directory in Java? Does the framework provide any utility? I saw a lot of hacky implementations. But none from the framework or nio ...