6

first, I know the difference between character and byte. character is a signature or remark of something("A", "中" or other), byte is a concrete size in computer. And the size of a character in computer depends on the encoding style. But what exactly is a character stream and a byte stream? what's the specific type they stand for? A byte stream is a stream of bytes? if so, what is a stream of character? My last question is, what type of stream does TCP transport?

1

5 Answers 5

14

Character Stream is a higher level concept than Byte Stream. A Character Stream is, effectively, a Byte Stream that has been wrapped with logic that allows it to output characters from a specific encoding; as opposed to one having to read bytes and decode the characters they represent.

0
4

An InputStream reads bytes, and a Reader reads characters.

Everything over TCP will natively be in bytes. If you know that the byte stream is representing characters, you can use an InputStreamReader to use the InputStream as a Reader.

6
  • link so how many readers are there in java? I have met two readers in my java project, BufferedReader and InputStreamReader, what do they stand for?
    – Fat Cat
    Dec 8, 2011 at 13:50
  • Click on the "Reader" link, and see the "Direct Known Subclasses" for a list of readers. There are at least this many, but anyone can extend Reader with a new implementation, so the actual number is unbounded. Clicking the link for each one from there will take you to its Javadoc, which will give you better descriptions than anyone here will be able to provide.
    – ziesemer
    Dec 8, 2011 at 13:53
  • Simply, a InputStreamReader is used as an adapter from an InputStream to a Reader, by converting bytes into characters. A BufferedReader is the character-equivalent of a BufferedInputStream, and outputs exactly what it reads - but with internal buffering to improve performance in cases where each individual read call to the underlying stream comes with a performance penalty.
    – ziesemer
    Dec 8, 2011 at 13:56
  • link I seem to understand what the reader mean, a reader just means a strcut to read or write a stream of bytes in an encoding-dependent way, java provides various extended readers to let programmers easy to transform, and any user can extend Reader class to realize their own transform, am I right?
    – Fat Cat
    Dec 8, 2011 at 14:06
  • Maybe a little vague / limited, but I wouldn't say anything you just stated is incorrect, yes. I'd highly recommend reviewing the same link that aneal answered with: docs.oracle.com/javase/tutorial/i18n/text/stream.html
    – ziesemer
    Dec 8, 2011 at 14:08
0

TCP transports bytes of course. What these bytes represent is up to the protocol.

You can read about the relation between character and byte streams here: http://docs.oracle.com/javase/tutorial/i18n/text/stream.html

Practically, a character stream is an application-side abstraction over a byte stream, allowing to read/write bytes into or from characters using various encodings.

0
0

Have a look at this :

  1. Character Streams versus Byte Streams
  2. Character and Byte Streams

and i assume TCP transport packets, stream of bytes.

0

characterstream classes in java are used to handle character'sinput and output for ex-hadles unicode whereas bytestream classes are used to handle input and output of bytes i.e ascii codes only.the former was used in java 1.0 version whereas later is used in java 1.1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.