public class ByteArrayOutputStream extends OutputStream
ByteArrayOutputStream替换方案, 执行toByteArray()
方法时返回的是只读的内部字节数组, 避免了没有必要的字节复制. 本代码移植自IBM developer works文章:
| Constructor and Description |
|---|
ByteArrayOutputStream() |
ByteArrayOutputStream(int initialBufferSize) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
reset() |
ByteArray |
toByteArray() |
InputStream |
toInputStream() |
void |
write(byte[] data,
int offset,
int length) |
void |
write(int datum) |
void |
writeTo(OutputStream out) |
flush, writepublic ByteArrayOutputStream()
public ByteArrayOutputStream(int initialBufferSize)
public void write(int datum)
throws IOException
write in class OutputStreamIOExceptionpublic void write(byte[] data,
int offset,
int length)
throws IOException
write in class OutputStreamIOExceptionpublic void close()
close in interface Closeableclose in interface AutoCloseableclose in class OutputStreampublic void writeTo(OutputStream out) throws IOException
IOExceptionpublic ByteArray toByteArray()
public InputStream toInputStream()
public void reset()
throws IOException
IOExceptionCopyright © 2006–2018 TinyGroup. All rights reserved.