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
4673
votes
64 answers

How do I read / convert an InputStream into a String in Java?

If you have a java.io.InputStream object, how should you process that object and produce a String? Suppose I have an InputStream that contains text data, and I want to convert it to a String, so for example I can write that to a log file. What is…
Johnny Maelstrom
  • 47,581
  • 5
  • 21
  • 18
994
votes
14 answers

How do I generate a stream from a string?

I need to write a unit test for a method that takes a stream which comes from a text file. I would like to do do something like this: Stream s = GenerateStreamFromString("a,b \n c,d");
Omu
  • 69,856
  • 92
  • 277
  • 407
944
votes
6 answers

How do I convert struct System.Byte byte[] to a System.IO.Stream object in C#?

How do I convert struct System.Byte byte[] to a System.IO.Stream object in C#?
Mehdi Hadeli
  • 9,784
  • 3
  • 20
  • 20
865
votes
10 answers

How do I save a stream to a file in C#?

I have a StreamReader object that I initialized with a stream, now I want to save this stream to disk (the stream may be a .gif or .jpg or .pdf). Existing Code: StreamReader sr = new StreamReader(myOtherObject.InputStream); I need to save this to…
Loadman
  • 8,797
  • 3
  • 17
  • 3
663
votes
6 answers

Get an OutputStream into a String

What's the best way to pipe the output from an java.io.OutputStream to a String in Java? Say I have the method: writeToStream(Object o, OutputStream out) Which writes certain data from the object to the given stream. However, I want to get this…
Adrian Mouat
  • 44,585
  • 16
  • 110
  • 102
621
votes
23 answers

Fastest way to check if a file exists using standard C++/C++11,14,17/C?

I would like to find the fastest way to check if a file exists in standard C++11, 14, 17, or C. I have thousands of files and before doing something on them I need to check if all of them exist. What can I write instead of /* SOMETHING */ in the…
Vincent
  • 57,703
  • 61
  • 205
  • 388
602
votes
9 answers

Download large file in python with requests

Requests is a really nice library. I'd like to use it for downloading big files (>1GB). The problem is it's not possible to keep whole file in memory; I need to read it in chunks. And this is a problem with the following code: import requests def…
Roman Podlinov
  • 23,806
  • 7
  • 41
  • 60
565
votes
13 answers

How do I copy the contents of one stream to another?

What is the best way to copy the contents of one stream to another? Is there a standard utility method for this?
Anton
  • 6,860
  • 12
  • 30
  • 26
502
votes
24 answers

Easy way to write contents of a Java InputStream to an OutputStream

I was surprised to find today that I couldn't track down any simple way to write the contents of an InputStream to an OutputStream in Java. Obviously, the byte buffer code isn't difficult to write, but I suspect I'm just missing something which…
Matt Sheppard
  • 116,545
  • 46
  • 111
  • 131
385
votes
12 answers

Download File to server from URL

Well, this one seems quite simple, and it is. All you have to do to download a file to your server is: file_put_contents("Tmpfile.zip", file_get_contents("http://someurl/file.zip")); Only there is one problem. What if you have a large file, like…
xaav
  • 7,876
  • 9
  • 30
  • 47
293
votes
6 answers

How do I turn a String into a InputStreamReader in java?

How can I transform a String value into an InputStreamReader?
Yossale
  • 14,165
  • 22
  • 82
  • 109
280
votes
9 answers

Difference between fprintf, printf and sprintf?

Can anyone explain in simple English about the differences between printf, fprintf, and sprintf with examples? What stream is it in? I'm really confused between the three of these while reading about "File Handling in C".
Vishwanath Dalvi
  • 35,388
  • 41
  • 123
  • 155
263
votes
12 answers

How to create streams from string in Node.Js?

I am using a library, ya-csv, that expects either a file or a stream as input, but I have a string. How do I convert that string into a stream in Node?
pathikrit
  • 32,469
  • 37
  • 142
  • 221
226
votes
21 answers

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

How do I collect all the data from a Node.js stream into a string?
obrienmd
  • 2,575
  • 3
  • 17
  • 8
220
votes
3 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
  • 9,826
  • 14
  • 64
  • 85
1
2 3
99 100