streams

StreamReader.ReadToEnd() returning an empty string

I have a method private static String DecompressAndDecode(byte[] data) { GZipStream decompressor = new GZipStream(new MemoryStream(data), CompressionMode.Decompress); StreamReader decompressed = new StreamReader(decompressor, Encoding.UTF8); String result = decompressed.ReadToEnd(); return result; } I have some GZipped tex...

What is the best practice about rewinding streams?

I've made the same mistake many times: I've tried to use a Stream that is positioned in the end, consequently returning nothing. What is the best way of designing the code involved in the stream loading and passing to avoid forgetting to rewind it? It's is always better to have the stream just initializated but always load the data wh...

Writing String to Stream and reading it back does not work

I want to write a String to a Stream (a MemoryStream in this case) and read the bytes one by one. stringAsStream = new MemoryStream(); UnicodeEncoding uniEncoding = new UnicodeEncoding(); String message = "Message"; stringAsStream.Write(uniEncoding.GetBytes(message), 0, message.Length); Console.WriteLine("This:\t\t" + (char)uniEncodi...

Capturing stdout within the same process in Python

I've got a python script that calls a bunch of functions, each of which writes output to stdout. Sometimes when I run it, I'd like to send the output in an e-mail (along with a generated file). I'd like to know how I can capture the output in memory so I can use the email module to build the e-mail. My ideas so far were: use a memor...

Method may fail to close stream on exception

I get the critical error with finbugs The method creates an IO stream object, does not assign it to any fields, pass it to other methods, or return it, and does not appear to close it on all possible exception paths out of the method. This may result in a file descriptor leak. It is generally a good idea to use a finally block to ensu...

Common lisp gray streams

Is there a tutorial on how to use gray streams? I want to create a class that reads from a file while looking for a specific set of bytes. My initial thought was to use gray streams, but could not find any starting information. ...

can't read from stream until child exits?

OK I have a program that creates two pipes -> forks -> the child's stdin and stdout are redirected to one end of each pipe -> the parent is connected to the other ends of the pipes and tries to read the stream associated with the child's output and print it to the screen (and I will also make it write to the input of the child eventually...

Play audio url on windows mobile

I'm going to write a function to play a mp3 file from an URL on Windows Mobile 6.0 without downloading all the stream to mobile. I read some documentation and faced some problem that. Using NAudio.dll : The dll is not compatible for Windows Mobile Using DirectShowLib.dll : have not found way to get from audio stream. Is i...

C++ UTF-8 output with ICU

I'm struggling to get started with the C++ ICU library. I have tried to get the simplest example to work, but even that has failed. I would just like to output a UTF-8 string and then go from there. Here is what I have: #include <unicode/unistr.h> #include <unicode/ustream.h> #include <iostream> int main() { UnicodeString s = UNI...

Downloading a webpage in C# example

I am trying to understand some example code on this web page: (http://www.csharp-station.com/HowTo/HttpWebFetch.aspx) that downloads a file from the internet. The piece of code quoted below goes through a loop getting chunks of data and saving them to a string until all the data has been downloaded. As I understand it, "count" contains...

fgets() and fread() - What is the difference?

I understand the differences between fgets() and fgetss() but I don't get the difference between fgets() and fread(), can someone please clarify this subject? Which one is faster? Thanks! ...

after dup2, stream still contains old contents?

so if I do: dup2(0, backup); // backup stdin dup2(somefile, 0); // somefile has four lines of content fgets(...stdin); // consume one line fgets(....stdin); // consume two lines dup2(backup, 0); // switch stdin back to keyboard I am finding at this point.. stdin still contains the two lines I haven't consumed. Why is that? Because the...

filebuf in ifstream and ofstream

How can i set a new char array to be the buffer of a fstream's filebuf, there is a function (setbuf) in the filebuf but it is protected. while searching on the web, some sites mention fstream::setbuf but it doesn't seem to exist anymore. Thanks ...

Client Server communication in Java - which approach to use?

I have a typical client server communication - Client sends data to the server, server processes that, and returns data to the client. The problem is that the process operation can take quite some time - order of magnitude - minutes. There are a few approaches that could be used to solve this. Establish a connection, and keep it alive,...

How can I tell whether a process hanging is due to filled buffers (TCP, stdin, stdout)?

I've got a C# application which launches a console application in a separate process. The two applications communicate via a TCP connection, as well as some (limited) standard input/output. The problem I'm experiencing is that whenever I "break" within the debugger, it seems to cause the console application to hang. If I leave the app...

Java deadlock problem....

I am using java sockets for communication. On the client side I have some processing and at this point I send an object to the cient. The code is as follows: while (true) { try { Socket server = new Socket("localhost", 3000); OutputStream os = server.getOutputStream(); InputStream is = server.getInputStream(); CommMes...

Is it possible to view multiple video files with android simultaneously ?

Hello, I would like to play three or more video streams on my Nexus One with the VideoView class (or other). Unfortunately the other streams always stop after I start the next video. Always one at the same time is playing, but not more - even if I use threads. Does anybody have an idea how to solve this? Thanks for help. ...

Async stream writing in a thread

I have a thread in which I write to 2 streams. The problem is that the thread is blocked until the first one finishes writing (until all data is transferred on the other side of the pipe), and I don't want that. Is there a way to make it asynchronous? chunkOutput is a Dictionary filled with data from multiple threads, so the faster check...

Concepts: Channel vs. Stream

Hello, is there a conceptual difference between the terms "Channel" and "Stream"? Do the terms require/determine, for example, the allowed number of concurrent Consumers or Producers? I'm currently developing a Channel/Stream of DataFlowVariables, which may be written by one producer and read by one consumer as the implementation is de...

Why use buffers to read/write Streams

Following reading various questions on reading and writing Streams, all the various answers define something like this as the correct way to do it: private void CopyStream(Stream input, Stream output) { byte[] buffer = new byte[16 * 1024]; int read; while ((read = input.Read(buffer, 0, buffer.Length)) > 0) { output.Wri...