io

Python3.0: tokenize & BytesIO

When attempting to tokenize a string in python3.0, why do I get a leading 'utf-8' before the tokens start? From the python3 docs, tokenize should now be used as follows: g = tokenize(BytesIO(s.encode('utf-8')).readline) However, when attempting this at the terminal, the following happens: >>> from tokenize import tokenize >>> from i...

Why can't I obtain a FileChannel from a FileWriter ?

Hi, I'm wandering why getChannel is only implemented in FileOutputStream and not in FileWriter. Is there any true reason ? Is there a way to lock a FileWriter another way ? thanks... ...

Feeding an input stream with EOF

I am building a small shell interpreter which executes various commands, and I accomplish this by forking my process. However, I want the child process to stop waiting for input in the standard input stream, and it does so by expecting an EOF. How do I push an EOF deliberately into that stream? More specifically, if I am looping on thi...

How can I covert a binary file into a set of ascii charecters

I want to convert a binary file into an array of ascii charcters . how can I do that . thank you . ...

Is there a simple method for checking whether a Ruby IO instance will block on read()?

I'm looking for a method in Ruby which is basically this: io.ready_for_read? I just want to check whether a given IO object (in my case, the result of a popen call) has output available, i.e. a follow up call io.read(1) will not block. These are the two options I see, neither of which I like: io.read_nonblock - too thin an abstract...

Java Memory model question

I know maybe the answer to the question is obvious. But if anybody can give me a definitive answer, that would be helpful. The question is : whether the java NIO package can provide some memory consistency assurance? The scenario is : Thread A Thread B [modify Object X] ...

Is there an easy way to create a Java InputStream that consists of several appended files?

I have a "processor" component that can process a single File, InputStream, Reader, or etc. For various reasons, I end up with several large files instead of one huge file. Is there a way to construct an input stream (or reader) that: transparently "appends" all these files so that: 1) The "processor" does not know where one file star...

Event Loop vs Multithread blocking IO

I was reading a comment about server architecture. http://news.ycombinator.com/item?id=520077 In this comment, the person says 3 things: The event loop, time and again, has been shown to truly shine for a high number of low activity connections. In comparison, a blocking IO model with threads or processes has been shown, time and ag...

how to get file information / search directories

Hi! I'm wondering how do you do stuff like gettling file information, searching through directories/subdirectories in c++? Is there a particular library that I should be looking at? I'm seeing stuff like this in some examples: #include <sys/types.h> #include <sys/stat.h> Not sure where they came from.. Thanks! EDIT: I'm programming...

Binary file IO in python, where to start?

As a self-taught python hobbyist, how would I go about learning to import and export binary files using standard formats? I'd like to implement a script that takes ePub ebooks (XHTML + CSS in a zip) and converts it to a mobipocket (Palmdoc) format in order to allow the Amazon Kindle to read it (as part of a larger project that I'm worki...

how to open a file (ie. .txt file) in C++ (kinda like double clicking it in windows)?

I'm wondering how I can open a file literally in C++ (like double clicking it)? ...

How to know if a BufferedReader Stream is closed

I have two threads in Java. First thread is closing a bufferedreader (br.close()) When the second thread does a read on the same reader I get an IOException (Stream Closed) I get this exception even if I use br.ready() Is there a way to know if the stream is already closed? ...

Tee-ing input (cin) out to a log file (or clog)

I am looking for a way to branch (tee) the input read from an istream (cin, in my case) out to a log file (clog/ofstream/etc), while still using the input for processing. I have read about boost::tee_device, and it is very similar to my requirements. Unfortunately, it is implemented as an ostream, and thus solves a similar problem from...

Most efficient idiom to read one integer only from a file?

In trying to resolve Facebook's Puzzle "Hoppity Hop", http://www.facebook.com/careers/puzzles.php?puzzle_id=7, I'm reading one integer only from a file. I'm wondering if this is the most efficient mechanism to do this? private static int readSoleInteger(String path) throws IOException { BufferedReader buffer = null; int integer = 0; ...

IO 101: Which are the main differences between TextWriter, FileStream and StreamWriter?

Let me first apologize if this question could sound perhaps sort of amateurish for the seasoned programmers among you, the thing is I've been having many arguments about this at work so I really want to get this straight and that's basically why I'm relying on the stackoverflow community to get this settled once and for all :) So, on th...

Stopping a thread

In a java application,when the user hits download,establishing the remote connection and downloading the content from remote is done in a separate thread and a dialog is popped up in the screen to show the download progress. Now a cancel command has been added to the dialog inorder to provide the user with an option of cancelling the dow...

System.IO.IOException: file used by another process

Dear all, I've been working in this small piece of code that seems trivial but still i cannot really see where is the problem. My functions does a pretty simple thing. Opens a file, copy its contents, replace a string inside and copy it back to the original file (a simple search and replace inside a text file then). I didn't really know ...

benchmark and the cause for difference between c# and java

I have a puzzling situation and I would need an expert opinion as to the cause of the phenomenon explained below. A couple of weeks ago, I have conducted a session titled "An overview .NET for Java developers" and as a part of it I wrote a quick class C# (3.5 framework) to read from a file and write to another file line by line (in an i...

C++ hdr image i/o library (linux and windows)

I need to find/create a library that can load hdr images in many formats for use in opengl. I have been using SDL_image, but it doesn't support hdr. I don't want to use many different image libraries, so if there is one that supports a large amount (bmp, png, jpg, tiff, tga, hdr are the most important). If there is none, I don't mind ...

Using scanf() in C++ programs is faster than using cin ?

Hello, I don't know if this is true, but when I was reading FAQ on one of the problem providing sites, I found something, that poke my attention: Check your input/output methods. In C++, using cin and cout is too slow. Use these, and you will guarantee not being able to solve any problem with a decent amount of input or output. Use...