streams

Best way to close nested streams in Java?

What is considered the best, most comprehensive way to close nested streams in Java? For example, consider the setup: FileOutputStream fos = new FileOutputStream(...) BufferedOS bos = new BufferedOS(fos); ObjectOutputStream oos = new ObjectOutputStream(bos); I understand the close operation needs to be insured (probably by using a fin...

Writing an image to a text file as binary data C#

Hi, I need to create a file that embeds an image as text within some records. I'm having some trouble writing the images as text. What I'm doing is gathering the image as a byte array from a SQL database (image type) then I'm writing that image to a text file by going through each byte and writing that byte's ASCII equivalent to the f...

import data from web stream in c++

hi i was wondering if is possible to import data from a live stream from a web site and perform computation on the data in real time? if this is possible what is the most efficient(computationally fast) way of doing it? thank you for any help or commpents. ...

How to send interrupt key sequence to a Java Process?

I've got a handle to a Java Process instance and its associated streams. It's a console program. I'd like to simulate a break sequence. On Windows this is Ctrl-C. Is this possible without natives? The reason for doing this: the console program is a command-line console itself, controlling a virtual machine for another language. The user...

programmatically recording sound sent to Built-in Output, Mac OS X

I have a conundrum: I need to find a way to capture the raw audio data that is being piped to the Built-in Output on Mac OS X. Core Audio, HAL, etc. I can "listen" in on the Built-in Output and the mic, but neither of these appear to offer the correct data stream - the exact stream (all combined data from all input sources) that goes ...

How do I download a webpage into a stream in .NET

I know this should be a basic question but I am hitting a brick wall. I am looking to go to a URL/URI download the resulting string as if I had opened a file and then get it out into a String variable. I have been stuffing about with IO.Stream and Net.httpxxx but haven't managed to get the elements to line up in the right way. I get "t...

C# bitmap images, byte arrays and streams!

I have a function which extracts a file into a byte array (data). int contentLength = postedFile.ContentLength; byte[] data = new byte[contentLength]; postedFile.InputStream.Read(data, 0, contentLength); Later I use this byte array to construct an System.Drawing.Image object (where data is the byte array) ...

How to redefine clog to tee to original clog and a log file?

Hello, I saw a useful start here: http://www.cs.technion.ac.il/~imaman/programs/teestream.html And it works great to make a new stream which goes to both clog and a log file. However, if I try to redefine clog to be the new stream it does not work because the new stream has the same rdbuf() as clog so the following has no effect: cl...

How to redefine clog's rdbuf() to be a tee to the original rdbuf() of clog and that of a log file?

Hello, Does anyone have an example of how to redefine the C++ built in clog to instead have a new associated rdbuf() which is processed to be a tee to the original clog.rdbuf() and the rdbuf() of a ofstream object to a log file on disk. The intention is to have the code use the std::clog throughout but to have it go to the both the def...

Detecting reason for failure to open an ofstream when fail() is true

Hello, Seems like this should be simple, but I don't find it in a net search. I have an ofstream which is open() and fail() is now true, I'd like to know the reason for the failure to open, like with errno I would do sys_errlist[errno]. Thanks. -William ...

Java Large Files Disk IO Performance

I have two (2GB each) files on my harddisk and want to compare them with each other: Copying the original files with Windows explorer takes approx. 2-4 minutes (that is reading and writing - on the same physical and logical disk). Reading with java.io.FileInputStream twice and comparing the byte arrays on a byte per byte basis takes 20...

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...

How do I attach a stream filter to echo?

Is there a way to attach a stream filter to echo so that any data that is echoed goes through the stream filter? My idea is to write an output escaping filter to protect against XSS. I found this bug report http://bugs.php.net/bug.php?id=30583 but it is from 2004 and I didn't know if this is now possible or not. class strtoupper_filter...

How can I Stream bytes from a TSQL varbinary table column in .NET?

In a SQL Server 2008 database, I have a table with a column of type varbinary. Currently, I am using LINQ to SQL to access the database. I already know that I can delay the loading of the column. However, I wish to consume less memory by not loading all of the bytes from that value. Ideally, I would like to have a Stream to those bytes. ...

.NET streams, passing streams between objects, best practices (C#)

Hello, I'm currently writing a little toy assembler in c# (going through the elements of computing systems book. Really good book by the way.) The assembler takes an input file path and removes junk (comments etc) lines. The file is then passed to a parser then finally to a another module that creates the binary code. This isn't too c...

Does disposing streamreader close the stream?

I am sending a stream to methods to write on, and in those methods I am using a binary reader/wrtier. When the reader/writer gets disposed, either by using or just when it is not referenced, is the stream closed as well?? I would send a BinaryReader/Writer, but I am using a StreamReader too (maybe I should go around that. I am only usin...

.NET Stream Decoders behavior

Hello, I've got a process which attempts to decode different encodings of strings from a binary stream. I get some behavior which does not quite add up in my mind when I step through it. Specifically, what I do is: obtain the maximum number of bytes which would be used to encode a character in the given encoding grab the amount of b...

C++ Runtime string formatting

Usually I use streams for formatting stuff however in this case ?I don't know the format until runtime. I want to be able to take something like the following format string: Hello {0}! Your last login was on {1,date:dd/mm/yy}. ...and feed in the variables "Fire Lancer" and 1247859223, and end up with the following formatted string: Hell...

Please identify this algorithm: probabilistic top-k elements in a data stream

I remember hearing about the following algorithm some years back, but can't find any reference to it online. It identifies the top k elements (or heavy hitters) in a data stream of n elements using only m counters. This is particularly useful for finding top search terms, network abusers, etc. while using minimal memory. The algorithm: ...

In functional list manipulation, what do we call "inserting something between each item"?

Occasionally I find I need to process a list by inserting a new item after each item, except the last one. Similar to how you might put a comma between each item of a list of strings. I got fed up of coding the special case for the last (or first) item every time, so I captured the pattern in a Linq-style extension: public static IEnum...