ensign/src/main/java/com/yem/wm/utils/StreamUtils.java
2024-08-26 09:19:12 +08:00

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;
}
}