aspose file tools*
The moose likes Linux / UNIX and the fly likes Reading a file descriptor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Reading a file descriptor" Watch "Reading a file descriptor" New topic
Author

Reading a file descriptor

vin Hari
Ranch Hand

Joined: Nov 16, 2006
Posts: 161
Hello all,
Please tell me is there way to read the <b>file descriptors</b> and give the contents to the <b>streambuf</b>,
using streams,
iam trying from all the way to achieve this but not able to succeed please tell me answer to this problem basically
iam trying in this way,


in this way but this is not giving me answer because of

this casting,
please help me how to read this file descriptor and give the result to streambuf ,
which other part of my project is using ,please help.
iam using c++ for this if this is not a right forum please transfer this to the corresponding forum, because almost c++ is also a object oriented as java thats why i posted this here because reamins the same.
[ November 26, 2007: Message edited by: vin Hari ]
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8997
    
    9

This forum is for Java-specific IO questions. I'll move this question to the Unix forum. It looks like your previous question got good traffic there.


[How To Ask Questions On JavaRanch]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

The ifstream constructor is expecting the name of a file to open; casting an int file descriptor to a char* isn't going to magically give you the name of the file (of course). There's actually no way to do what you want built into the standard C++ libraries. You can either "roll your own" by subclassing streambuf (not recommended) or use a third-party library. You can't go wrong with the Boost libraries, many of which are being rolled into future C++ standards. Boost.iostreams has a file_descriptor_source class that lets you do what you want:

http://www.boost.org/libs/iostreams/doc/classes/file_descriptor.html


[Jess in Action][AskingGoodQuestions]
vin Hari
Ranch Hand

Joined: Nov 16, 2006
Posts: 161
thank you for reply ,
so according to this discussion is there no way to open that file descriptor
and redirect the output to the streambuf, is it the conclusion,
if not in c++,also in c,\
even i tried directly
ifstream f(fd);
which result in error. i included <fstream.h>.

please clear me.
[ November 26, 2007: Message edited by: vin Hari ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Actually I said yes, there is a way. I think what you would do would be to implement a custom subclass of streambuf, which would use low-level C calls to work with the file descriptor. I imagine you could copy some code from the ifstream class to do this.

Or...

You could simply use the Boost library, which already provides a class (file_descriptor_source) which does exactly what you need. See the link I provided above.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading a file descriptor