ByteArrayOutputStream from OutputStream
How to create OutputS开发者_Python百科tream from ByteArrayOutputStream in Java
Following runs without error:
ByteArrayOutputStream stream = new ByteArrayOutputStream();
OutputStream outStream = stream;
If you see the docs for ByteArrayOutputStream you will find that it extends OutputStream.
ByteArrayOutputStream
is a subclass of OutputStream
.
ByteArrayOutputStream bos = ...;
OutputStream os = bos;
A ByteArrayOutputStream
is an OutputStream
. I.e. you can just assign it like this:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream out = baos;
You can create a helper method like follows:
public OutputStream convert(ByteArrayOutputStream arrayOutputStreamParam){
return arrayOutputStreamParam;
}
精彩评论