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.

15725 questions
212
votes
20 answers

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…
Rob Sobers
  • 20,737
  • 24
  • 82
  • 111
197
votes
9 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
  • 57,525
  • 34
  • 189
  • 207
196
votes
7 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
  • 353,942
  • 115
  • 666
  • 851
186
votes
0 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,954
  • 7
  • 30
  • 36
182
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
  • 3,284
  • 4
  • 25
  • 34
182
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,819
  • 14
  • 36
  • 34
161
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
  • 5,440
  • 18
  • 70
  • 130
160
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
  • 7,515
  • 12
  • 37
  • 37
159
votes
9 answers

Converting a Buffer into a ReadableStream in Node.js

I have a library that takes as input a ReadableStream, but my input is just a base64 format image. I could convert the data I have in a Buffer like so: var img = new Buffer(img_string, 'base64'); But I have no idea how to convert it to a…
Masiar
  • 20,450
  • 31
  • 97
  • 140
158
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
  • 29,538
  • 35
  • 110
  • 138
154
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
  • 20,802
  • 26
  • 75
  • 84
152
votes
6 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
  • 5,182
  • 4
  • 32
  • 38
143
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
  • 84,878
  • 18
  • 192
  • 214
142
votes
5 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,649
  • 15
  • 46
  • 57
139
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
  • 76,817
  • 74
  • 166
  • 248