This is classic - how can you .read() if there is nothing to read? NIO is clearly performance intensive, dedicated to achieving non-blocking io. Try doing nio on Socket.read() - you still will get either a blocking operation or fall through on timeout ... no amount of fancy will cause data to appear on the 'port' unless you generate some data ...
final SecureRandom dataGenerator = SecureRandom.getInstance("SHA1PRNG");
final Integer range = new Integer( 'z' - 'a' );
for ( big loop )
{
buffer.append( dataGenerator.nextInt ( range.intValue() + (int) 'a' ) );
// ............
do.something( buffer.toString() );
Now your development skills move, even if at a Glacial Pace but they move.
try {
// Create a read/writeable file channel
File file = new File("filename");
FileChannel channel = new RandomAccessFile(file, "rw").getChannel();
// Create an output stream on the channel
OutputStream os = Channels.newOutputStream(channel);
// Create an inputstream on the channel
InputStream is = Channels.newInputStream(channel);
// Close the channel
is.close();
} catch (IOException e) {
}
Message edit: I grasp your critical response, wait till your twelve thousand lines into CORBA trying to implement readObjectNoData() ( useful for initializing deserialized objects properly despite a "hostile" or incomplete source stream )
My one-off psuedo-code was expected to provide some sort of data stream to decode, reload or whatever - I re-read your post; I think it says how to read() non-blocking io on an object that may not be there ... which drills deeply into known issues of Exception and scheduling, gets dicey trying to work this with someone who asks the question in the manner you worded it, try re-wording and having others explain to me what it is you are asking.
I'm gonna go to the taco stand right at the moment.