Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the write(int b) method of OutputStream exist? [duplicate]

Tags:

java

Possible Duplicate:
Why Java OutputStream.write() Takes Integer but Writes Bytes

Why does the write() method of the OutputStream class take an integer instead of a byte when it actually writes data byte by byte?

like image 863
Sheo Avatar asked Dec 10 '11 21:12

Sheo


2 Answers

it is consistent w/ IntputStream.read() and since most operations (sum, mul, div, etc) are promoted to int, it removes the need to constantly cast to byte.

I think it's ok.

like image 129
bestsss Avatar answered Sep 27 '22 23:09

bestsss


It actually writes a single byte from that int (the 8 low-order bits). See the documentation: http://docs.oracle.com/javase/1.4.2/docs/api/java/io/OutputStream.html#write%28int%29

Edit: I did some digging and found this: Why Java OutputStream.write() Takes Integer but Writes Bytes

like image 29
Tudor Avatar answered Sep 28 '22 01:09

Tudor