io

Disk Activity in Applescript

How can I poll disk activity in Applescript? Check to see if disk X is being read, written, or idle every N seconds and do something. ...

What is the best epoll/kqueue/select equvalient on Windows?

What is Windows' best I/O event notification facility? By best I mean something that ... doesn't have a limit on number of input file descriptors works on all file descriptors (disk files, sockets, ...) provides various notification modes (edge triggered, limit triggered) ...

Java: Reading an ASCII file with FileChannel and ByteArrays.

I have the following code: String inputFile = "somefile.txt"; FileInputStream in = new FileInputStream(inputFile); FileChannel ch = in.getChannel(); ByteBuffer buf = ByteBuffer.allocateDirect(BUFSIZE); // BUFSIZE = 256 /* read the file into a buffer, 256 bytes at a time */ int rd; while ( (rd = ch...

How do you rate-limit an IO operation?

Suppose you have a program which reads from a socket. How do you keep the download rate below a certain given threshold? ...

XSLT multiple file inputs?

Within an XSLT document, is it possible to loop over a set of files in the current directory? I have a situation where I have a directory full of xml files that need some analysis done to generate a report. I have my stylesheet operating on a single document fine, but I'd like to extend that without going to another tool to merge the x...

How do I read a file over a network that is in use/locked by another process in c#?

Is there a way to read a locked file across a network given that you are the machine admin on the remote machine? I haven't been able to read the locked file locally, and attempting it over the network adds another layer of difficulty. ...

Closing/cleaning up "mixed" file descriptors / sockets.

When I create a socket using accept() and make a FILE out of it using fdopen(), what do I have to do to clean everything up? Do I need to do fclose() on the FILE, shutdown() and close() on the socket, or only the shutdown() and or close() or fclose()? If I don't do fclose(), do I have to free() the FILE pointer manually? ...

How to prevent SIGPIPEs (or handle them properly).

I have a small server program that accepts connections on a TCP or local UNIX socket, reads a simple command and, depending on the command, sends a reply. The problem is that the client may have no interest in the answer sometimes and exits early, so writing to that socket will cause a SIGPIPE and make my server crash. What's the best pr...

How do I handle multiple streams in Java?

I'm trying to run a process and do stuff with its input, output and error streams. The obvious way to do this is to use something like select(), but the only thing I can find in Java that does that is Selector.select(), which takes Channels. It doesn't appear to be possible to get a Channel from an InputStream or OutputStream (FileStream...

Why does "piping" a CharBuffer hang?

Why does the following method hang? public void pipe(Reader in, Writer out) { CharBuffer buf = CharBuffer.allocate(DEFAULT_BUFFER_SIZE); while( in.read(buf) >= 0 ) { out.append(buf.flip()); } } ...

Java idiom for "piping"

Is there a more concise/standard idiom (e.g., a JDK method) for "piping" an input to an output in Java than the following? public void pipe(Reader in, Writer out) { CharBuffer buf = CharBuffer.allocate(DEFAULT_BUFFER_SIZE); while( in.read(buf) >= 0 ) { out.append(buf.flip()); buf.clear(); } } [EDIT] Please not...

Sending the same but modifed object over ObjectOutputStream

I have the following code that shows either a bug or a misunderstanding on my part. I sent the same list, but modified over an ObjectOutputStream. Once as [0] and other as [1]. But when I read it, I get [0] twice. I think this is caused by the fact that I am sending over the same object and ObjectOutputStream must be caching them som...

C# how can you get output of an other batch file?

I have to use an other application (console) to pass some parameter to this program and inside my C# program get the output of that program. I would like not to see the console (all invisible to the user). How can I do that? ...

synchronizing io operation in java on a string method argument?

Basically, I have a class with 2 methods: one to serialize an object into an XML file and another to read an object from XML. Here is an example of synchronized part from the method that restores an object: public T restore(String from) throws Exception { // variables declaration synchronized (from) { try { de...

How to read from a memory mapped I/O port in .Net?

Can standard pointers in .Net do this? Or does one need to resort to P/invoke? Note that I'm not talking about object references; I'm talking about actual C# pointers in unsafe code. ...

Reading from file not fast enough, how would I speed it up?

This is the way I read file: public static string readFile(string path) { StringBuilder stringFromFile = new StringBuilder(); StreamReader SR; string S; SR = File.OpenText(path); S = SR.ReadLine(); while (S != null) { stringFromFile.Append(SR.ReadLine()); ...

C# : Characters do not display well when in Console, why?

The picture below explains all: The variable textInput comes from File.ReadAllText(path); and characters like : ' é è ... do not display. When I run my UnitTest, all is fine! I see them... Why? ...

Haskell: Inserting every line from a file into a list

I'm currently working on project with Haskell, and have found myself some trouble. I'm supposed to read and insert into a list each line in a "dictionary.txt" file, but I can't seem to do so. I've got this code: main = do let list = [] loadNums "dictionary.txt" list loadNums location list = do inh <- openFile location ReadM...

Get an OutputStream into a String

What's the best way to pipe the output from an java.io.OutputStream to a String in Java? Say I have the method: writeToStream(Object o, OutputStream out) Which writes certain data from the object to the given stream. However, I want to get this output into a String as easily as possible. I'm considering writing a class like this (...

How to access a file with the least amount of locking

in my application (c# 3.5) there are various processes accessing a single xml file (read and write) very frequently. the code accessing the file is placed in an assembly referenced by quite a couple of other applications. for example a windows service might instanciate the MyFileReaderWriter class (locatied in the previously mentioned as...