streams

Python: C++-like stream input

Hi! Is there a pythonic way of reading - say - mixed integer and char input without reading the whole input at once and without worrying about linebreaks? For example I have a file with whitespace-separated data of which I only know that there are x integers, then y chars and then z more integers. I don't want to assume anything about l...

Testing if NetworkStream is closed

Hi there! I have a class, that wrapps a Stream instance, so I can use it for wrapping FileStreams and NetworkStreams. Now, I want to test if the stream is still delivering any data, in other words, I want to test the NetworkStream if it is still connected or the FileStream if it reached its end. Is there any function whose return value...

Can you use Boost.Regex to parse a stream?

I was playing around with Boost.Regex to parse strings for words and numbers. This is what I have so far: #include <iostream> #include <string> #include <boost/foreach.hpp> #include <boost/regex.hpp> #include <boost/range.hpp> using namespace std; using namespace boost; int main() { regex re ( "(" "([a-z]+)...

Streaming files over the network with random access - java

Hey all, So ive got a need to play music files from a server on the network, in a java client app. I was thinking Sockets - have the server open a music file as a stream, and have the client connect to that and read & play it as an InputStream. Which would work - except AFAICS users wont be able to seek into the file(which they can curr...

Where is the content of a java piped stream 'stored' ?

I am running my application under a profiler. The 'class' that has the most memory consumption is the 'char[]' which is about 10kB in my application. I then created an InputStream (PipedInputStream to be exact) which holds a byte array data of 300MB. Then I took a look at my profiler, and I don't see any significant change ( don't see...

Why isn't the StringBuilder class inherited from Stream?

I'm just curious about this. It strikes me that the behavior of a StringBuilder is functionally (if not technically) the same as a Stream -- it's a bin of data to which other data can be added. Again, just curious. ...

Persisting Blob Streams with NHibernate

If I have a class declared as: public class MyPersistentClass { public int ID { get; set; } public Stream MyData {get;set; } } How can I use NHibernate's mappings to persist the MyData property to and from the database? ...

Optimal way to get a string or char* into an istream?

What is the most optimal way to get a string or char* pointer into an istream. I want to do the following std::string a = "abc.."; //I know this can be done, not sure if this is most efficient // and not sure about char* pointers std::istringstream istr (a); ... foo (istr); void foo(std::istream& is) { } ...

F# how to abstract Console.ReadLine() as string seq

Hi, I want to write a function to abstract Console.ReadLine() into a string seq the seq should break when line = null ConsoleLines(): unit -> string seq To be used like this: for line in ConsoleLines() do DoSomething line How do you write this function? Thanks ...

Java - Capturing System.err.println or Capturing a PrintStream

Hi Java Newbie question : I need to capture the text being written to a printStream by a 3rd party component. The PrintStream is defaulted to System.err, but can be changed to another PrintStream. Looking through the docs, I couldn't find an easy way to direct the contents of a PrintStream to a string writer / buffer. Can someone pl...

Can you explain the concept of streams?

I understand that a stream is a representation of a sequence of bytes. Each stream provides means for reading and writing bytes to its given backing store. But what is the point of the stream? Why isn't the backing store itself what we interact with? For whatever reason this concept just isn't clicking for me. I've read a bunch of...

How to use my logging class like a std C++ stream?

I've a working logger class, which outputs some text into a richtextbox (Win32, C++). Problem is, i always end up using it like this: stringstream ss; ss << someInt << someString; debugLogger.log(ss.str()); instead, it would be much more convenient to use it like a stream as in: debugLogger << someInt << someString; Is there a ...

Unbuffered StreamReader

Is there a way to keep StreamReader from doing any buffering? I'm trying to handle output from a Process that may be either binary or text. The output will look like an HTTP Response, e.g. Content-type: application/whatever Another-header: value text or binary data here What I want to do is to parse the headers using a StreamReader,...

Performance of creating a C++ std::string from an input iterator.

I'm doing something really simple: slurping an entire text file from disk into a std::string. My current code basically does this: std::ifstream f(filename); return std::string(std::istreambuf_iterator<char>(f), std::istreambuf_iterator<char>()); It's very unlikely that this will ever have any kind of performance impact on the program...

Help with streams (.net)

I have a stream object, and I want to create and output xml using some kind of xml stream, based on data in my input stream. I haven't done much work with streams, so I am trying to learn how to do this as efficiently as possible. The idea is that I do not want to load the entire input stream in memory, then create the entire output st...

redirect std::cout to a custom writer

I want to use this snippet from Mr-Edd's iostreams article to print std::clog somewhere. #include <iostream> #include <iomanip> #include <string> #include <sstream> int main() { std::ostringstream oss; // Make clog use the buffer from oss std::streambuf *former_buff = std::clog.rdbuf(oss.rdbuf()); std::clog <<...

Why is the end of the input stream never reached using Java Sockets?

I am writing a simple proxy in Java. I am having trouble reading the entirety of a given request into a byte array. Specifically, in the following loop, the call to 'read' blocks even though the client has sent all the data that it will (that is, the end of stream is never reached). As I can't be sure that it is time to start writing ...

How to make a better mapper in Scheme using Streams

The Scheme implementation of map takes N+1 arguments: a procedure of N arguments, and N lists. Further, it terminates mapping when the end of the shortest list is reached. An alternative is to provide a default value for each list, which will be treated as the next element(s) of each list if it turns out to be shorter than the others. ...

Convert a StreamWriter to an OutputStream in java ?

I am trying to redirect System.out into a String using System.setOut, which takes a PrintStream. Is there any way to convert a StringWriter into a Stream so that I can pass it to setOut? ...

Java - Reading Strings and Binary from the same stream

I have a file that contains some amount of plain text at the start followed by binary content at the end. The size of the binary content is determined by some one of the plain text lines I read. I was using a BufferedReader to read the individual lines, however it exposes no methods to refer to read a byte array. The readUTF for a DataI...