How to quickly convert OutputStream to InputStream?
Today, I helped my colleagues solve a pit problem of converting OutputStream to InputStream in Java. Let me record it:
don’t talk nonsense, just upload the code directly. The principle is what I think:
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] bytes = outputStream.toByteArray();
ByteBuffer buffer = ByteBuffer.wrap(bytes);
InputStream inputStream = new ByteArrayInputStream(buffer.array());