Questions tagged [stream]

DO NOT USE FOR THE JAVA STREAM API INTRODUCED IN JAVA 8 (use [java-stream] for those questions!) A stream is a series of data elements which can be accessed in a serial fashion.

A stream is a series of data elements (characters, bytes or complex packets) which can be accessed or made accessible in a serial fashion. Random access is not possible.

The term stream is also used for streaming media, a method in which the media can be played while it is being accessed (no full download required). The ability to stream media is largely dependent on the container format used. Seeking functionality in streaming media is typically achieved through a different protocol, for example RTSP or HTTP 1.1's Range function.

14148 questions
188
votes
2 answers

Stream.Seek(0, SeekOrigin.Begin) or Position = 0

When you need to reset a stream to beginning (e.g. MemoryStream) is it best practice to use stream.Seek(0, SeekOrigin.Begin); or stream.Position = 0; I've seen both work fine, but wondered if one was more correct than the other?
ConfusedNoob
  • 8,909
  • 14
  • 55
  • 80
177
votes
8 answers

Error handling with node.js streams

What's the correct way to handle errors with streams? I already know there's an 'error' event you can listen on, but I want to know some more details about arbitrarily complicated situations. For starters, what do you do when you want to do a…
B T
  • 46,771
  • 31
  • 164
  • 191
171
votes
7 answers

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…
Nefzen
  • 7,529
  • 13
  • 33
  • 33
170
votes
6 answers

Should I call Close() or Dispose() for stream objects?

Classes such as Stream, StreamReader, StreamWriter etc implements IDisposable interface. That means, we can call Dispose() method on objects of these classes. They've also defined a public method called Close(). Now that confuses me, as to what…
Nawaz
  • 327,095
  • 105
  • 629
  • 812
155
votes
6 answers

What is a stream?

What is a stream in the programming world? Why do we need it? Kindly explain with the help of an analogy, if possible.
pokrate
  • 3,524
  • 7
  • 27
  • 36
154
votes
12 answers

Android Reading from an Input stream efficiently

I am making an HTTP get request to a website for an android application I am making. I am using a DefaultHttpClient and using HttpGet to issue the request. I get the entity response and from this obtain an InputStream object for getting the html of…
RenegadeAndy
  • 4,849
  • 14
  • 58
  • 115
148
votes
6 answers

Write string to output stream

I have several output listeners that are implementing OutputStream. It can be either a PrintStream writing to stdout or to a File, or it can be writing to memory or any other output destination; therefore, I specified OutputStream as (an) argument…
yart
  • 6,695
  • 10
  • 33
  • 36
147
votes
18 answers

How do I read the contents of a Node.js stream into a string variable?

I'm hacking on a Node program that uses smtp-protocol to capture SMTP emails and act on the mail data. The library provides the mail data as a stream, and I don't know how to get that into a string. I'm currently writing it to stdout with…
obrienmd
  • 1,775
  • 3
  • 13
  • 8
146
votes
16 answers

Java : How to determine the correct charset encoding of a stream

With reference to the following thread: Java App : Unable to read iso-8859-1 encoded file correctly What is the best way to programatically determine the correct charset encoding of an inputstream/file ? I have tried using the following: File in = …
Joel
  • 27,478
  • 33
  • 104
  • 136
145
votes
9 answers

Can I redirect the stdout 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…
Avihu Turzion
  • 2,752
  • 3
  • 22
  • 32
144
votes
7 answers

How to implement the activity stream in a social network

I'm developing my own social network, and I haven't found on the web examples of implementation the stream of users' actions... For example, how to filter actions for each users? How to store the action events? Which data model and object model can…
Nicolò Martini
  • 4,944
  • 4
  • 28
  • 38
134
votes
4 answers

How to add new line into txt file

I'd like to add new line with text to my date.txt file, but instead of adding it into existing date.txt, app is creating new date.txt file.. TextWriter tw = new StreamWriter("date.txt"); // write a line of text to the…
Elfoc
  • 3,421
  • 12
  • 43
  • 57
133
votes
7 answers

What is the purpose of flush() in Java streams?

In Java, flush() method is used in streams. But I don't understand what are all the purpose of using this method? fin.flush(); tell me some suggestions.
Venkat
  • 18,946
  • 25
  • 71
  • 83
129
votes
6 answers

How does one create an InputStream from a String?

I'm not used to working with streams in Java - how do I create an InputStream from a String?
Amir Rachum
  • 67,681
  • 68
  • 159
  • 239
124
votes
2 answers

Save byte array to file

I have a byte array (an IEnumerable actually), and I need to save it to a new file containing this data. How do I do that? I found some answers telling how to create a MemoryStream from that, but still can't save it to a brand new file.
Daniel Möller
  • 74,597
  • 15
  • 158
  • 180