streams

Java I/O streams; what are the differences?

java.io has many different I/O streams, (FileInputStream, FileOutputStream, FileReader, FileWriter, BufferedStreams... etc.) and I am confused in determining the differences between them. What are some examples where one stream type is preferred over another, and what are the real differences between them? ...

Using NSStream to communicate with PHP?

I'm working on an iPhone project that needs to receive data from a PHP script during execution. My first thought was to use sockets/streams on either end to connect the two, but I am having trouble finding information on how to do this from the iPhone side. Has anyone been down this path that could point me towards some useful resources...

Underlying constructs of "streams"

What are the underlying constructs of the concept known as a "stream"? How do they work internally? How does a memory stream work? How does a file stream work? Edit - From the answers I'm guessing that each type of stream is implemented differently, but the core concept is a sequence of bytes controlled and modelled by a class or a s...

Using getline(cin, ...) after using cin>>...

The code below has a method that sets the member field 'x' using the getline() function. I noticed that if I use cin before calling that method, my program would hang the next time I reach the line getline(cin, rangeInput). Since getline() is using cin, is that why it is causing the program to hang if I have previously used cin? What sh...

iTextSharp - How to convert Document to byte[]

I need to attach a pdf I created in memory to an email. Attachments can take a stream. So I believe I need to convert a iTextSharp Document object to stream. How can I do that? I tried serializing the Document object to a stream but it is not "marked as serializable". Thanks ...

C#: tail like program for text file

Hi, I have a log file that continually logs short lines. I need to develop a service that reacts (or polls, or listens to) to new lines added to that file, a sort of unix' tail program, so that my service is always up to date reguarding the file. I don't think that opening a read stream and keeping it opened is a good idea. Maybe I sho...

Check remote file existance with Flex 3

In Flex 3/AS 3, what would be a good way to check if a remote file exists? I'm thinking in PHP ways where you'd try to "fopen" a remote path (like "http://example.com/somefile.exe"), and see if it works or not. I'm not asking to just download all of the file, I just want to know if the file is there (and accessible). ...

.NET stream capabilities - is the CanXXX test safe?

There is a fairly common pattern used in .NET to test for the capabilities of a class. Here I'll use the Stream class as an example, but the issue applies to all classes that use this pattern. The pattern is to supply a boolean property called CanXXX to indicate that capability XXX is available on the class. For example, the Stream cl...

Where to learn more about streams in C++ ?

I hardly find a good resource about the subject. Almost all books and websites I know give a simple introduction about streams in C++ and that's it! Would you recommend a good book or tutorial to learn more about standard streams in C++ ? ...

Can I redirect the stdout in python into some sort of string buffer?

I'm using python's ftplib to write a small FTP client, but some of the functions in the package don't return string output, but print to stdout. I want to redirect stdout to an object which I'll be able to read the output from. I know stdout can be redirected into any regular file with: stdout = open("file", "a") But I prefer a metho...

.NET fill StreamReader from Textbox

I want to parse user input in a streamReader. My code is: string txt = txtin.text ; //<~~ txtin is something like root:x:1:1.... using (TextReader reader = new TextReader( txt)) { string line = ""; while ((line = reader.ReadLine()) != null) { string userName = line.Substring(0, line.IndexOf(':')); } } I get ...

using() and dispose with multiple wrapped streams

Am I right that you'd only need a using() for the outermost stream if you're doing e.g MemoryStream mstr = new MemoryStream(); using(StreamWriter w = new StreamWriter(mstr)) { .... } As disposing the StreamWriter should also dispose/close the underlying stream, there's no need to do this ?: using(MemoryStream mstr = new MemoryS...

Most efficient way to create InputStream from OutputStream

This page: http://ostermiller.org/convert_java_outputstream_inputstream.html describes how to create an InputStream from OutputStream: new ByteArrayInputStream(out.toByteArray()) Other alternatives are to use PipedStreams and new threads which is cumbersome. I do not like the idea of copying many megabytes to new in memory Bytes a...

Using Java's FileInputStream

In java.io.FileInputStream, there is a method int read(Byte[] buffer,int offset,int numBytes); how we can use this function - is there any difference between this method and read(byte[] buffer)? ...

Show next set of results in page with Rails, like Facebook-style "older posts" link to see next set of news items

I'm still pretty new to Rails and need your help: I have been creating a social fitness analytics site (zednine.com) that has an activity stream that lists workouts posted on the site. Several pages currently show the 10 most recently updated workouts. I'd like to add a link at the bottom to "Older workouts." On click, this should show t...

Non-destructible read from a stream.

Is is possible to try to read from a stream but do not change the stream itself (and return bool whether it was a success)? template <typename T> bool SilentRead (stringstream& s, T& value) { stringstream tmp = s; tmp >> value; return tmp; } This doesn't work because stringstream doesn't have public copy constructor. How t...

Client socket read "freezes"

I want to write a simple web proxy, for exercise. Here's the code I have so far: def g = new Proxy() g.serverPort = 9000 println "starting" g.eachClient { Socket client -> println "got a client" try { client.withStreams { input,output -> String text = input.text println "received $text from clien...

Reading from a HttpResponseStream fails

I'm running into an issue where reading from a HttpResponseStream fails because the StreamReader that I'm wrapping around in reads faster that the Response Stream gets the actual response. I'm retrieving a reasonably small sized file (around 60k) but the Parser which processes the response into an actual object fails because it hits an ...

Play Wav file backward

Hi, I'm making Braid in Java. If you rewind the time, the sound plays backward Does somebody now how to play a wav backward? Maybe with a stream with something like previous()??? On the site of braid can you see what I mean. Solved!!: See my own post!!!!!! Thanks ...

Can I do this in powershell? Read the Registry, write out binary contents to file.

This is the C# code. Can you help me translate this to powershell? private static void Main(string[] args) { byte[] buffer = (byte[]) Registry.LocalMachine.OpenSubKey(@"HARDWARE\ACPI\DSDT\HP____\8510x\00010000").GetValue("00000000"); if (File.Exists("8510x.orig")) { Console.WriteLine("File 8510x.orig already exists...