This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Program for file descriptors

 
pavang kumar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I want to do is produce a Java program which does the equivalent of UNIX select() or poll() on a set of file descriptors.Can some help me .or provide any links
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the java.nio.channels package, especially class java.nio.channels.Selector. Note that FileChannel cannot be used with this class since it does not extend SelectableChannel. That's because data from files is regarded as always being available when you ask for it.
 
pavang kumar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes FileChannel cannot be used with this class since it does not extend Selectable Channel,so how to over come it any suggestions.

 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15214
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch. Please UseCodeTags when you post source code.
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's the thing - with FileChannel you don't need to use polling. The data is simply always considered as being available until everything is read.

If you want to read a file that is continually written to, there is currently no support for that in Java.
 
pavang kumar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So any good alternative that you can suggest how it can be done in java.

Well can I write a normal method where it can check all the files in a particular location whether they are redable/writable and then get the list of files that are redable.

Would that be equivalent to same of the unix select () .Please correct me if i am wrong .

@ Rob Prime

Can you explain in detail why with FileChannel you don't need to use polling . and any suggestions.

Thanks
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pavang kumar wrote:Would that be equivalent to same of the unix select () .Please correct me if i am wrong .

You are wrong. select() has nothing to do with selecting a readable files from a folder, it checks how many of a given set of already open file descriptors (which can also point to sockets or pipes, not just files) have data available.

Can you explain in detail why with FileChannel you don't need to use polling . and any suggestions.

Because FileChannel read operations simply should not block. The contents on the disk are considered to be always available. select() and poll() are to be used with blocking I/O only.
 
pavang kumar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So how should I approach ,well could solve this for me .where i need a select() command similar to unix and can you provide code or any sample program that can make me understand.I will greatly thankful to you.

Please reveiew and help me ...

Thanks
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to I/O
 
pavang kumar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well i did not get you exactly. How can that be done uisng I/O .Can you elobrate it so that it can help me as I am novice this .

Can you please provide me an algorithm like thing so that i can move forward.
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was moving your thread to the I/O and Streams forum, where it is better suited since file descriptors are all about I/O (input/output).
 
pavang kumar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Any one there .. Please provide a solution..

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic