Can you explain the concept of streams?

前端 未结 15 1915
无人共我
无人共我 2020-11-30 15:54

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

相关标签:
15条回答
  • 2020-11-30 16:56

    Think of streams as of an abstract source of data (bytes, characters, etc.). They abstract actual mechanics of reading from and writing to the concrete datasource, be it a network socket, file on a disk or a response from the web server.

    0 讨论(0)
  • 2020-11-30 17:00

    A stream is an abstraction that provides a standard set of methods and properties for interacting with data. By abstracting away from the actual storage medium, your code can be written without total reliance on what that medium is or even the implementation of that medium.

    An good analogy might be to consider a bag. You don't care what a bag is made of or what it does when you put your stuff in it, as long as the bag performs the job of being a bag and you can get your stuff back out. A stream defines for storage media what the concept of bag defines for different instances of a bag (such as trash bag, handbag, rucksack, etc.) - the rules of interaction.

    0 讨论(0)
  • 2020-11-30 17:01

    It's not about streams - it's about swimming. If you can swim one Stream, than you can swim any Stream you encounter.

    0 讨论(0)
提交回复
热议问题