All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dxy.library.network.http.util.StreamUtils Maven / Gradle / Ivy

The newest version!
package com.dxy.library.network.http.util;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

/**
 * @author duanxinyuan
 * 2019/1/14 18:45
 */
public class StreamUtils {

    public static InputStream cloneInputStream(final InputStream inputStream) {
        try {
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            int readLength;
            while ((readLength = inputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, readLength);
            }
            outputStream.flush();
            return new ByteArrayInputStream(outputStream.toByteArray());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy