35 lines
890 B
Java
35 lines
890 B
Java
package com.yem.wm.utils;
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
|
|
/**
|
|
* @Description: TODO
|
|
* @Date: 2024/8/19 11:52
|
|
* @Created: by ZZSLL
|
|
*/
|
|
|
|
public class StreamUtils {
|
|
public static InputStream cloneInputStream(InputStream in) {
|
|
try {
|
|
return new ByteArrayInputStream(transformStream(in).toByteArray());
|
|
} catch (IOException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
|
|
}
|
|
|
|
private static ByteArrayOutputStream transformStream(InputStream input) throws IOException {
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
byte[] buffer = new byte[1024];
|
|
int len;
|
|
while ((len = input.read(buffer)) > -1) {
|
|
baos.write(buffer, 0, len);
|
|
}
|
|
baos.flush();
|
|
return baos;
|
|
}
|
|
}
|