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

com.lastb7.swagger.util.IOUtils Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package com.lastb7.swagger.util;

import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * copy from commons-io.IOUtils
 *
 * @author: lbq
 * 联系方式: [email protected]
 * 创建日期: 2020/6/15
 */
public class IOUtils {

    public static int copy(InputStream input, OutputStream output) throws IOException {
        long count = copyLarge(input, output);
        return count > 2147483647L ? -1 : (int) count;
    }

    public static long copyLarge(InputStream input, OutputStream output) throws IOException {
        return copy(input, output, 4096);
    }

    public static long copy(InputStream input, OutputStream output, int bufferSize) throws IOException {
        return copyLarge(input, output, new byte[bufferSize]);
    }

    public static long copyLarge(InputStream input, OutputStream output, byte[] buffer) throws IOException {
        long count;
        int n;
        for (count = 0L; -1 != (n = input.read(buffer)); count += (long) n) {
            output.write(buffer, 0, n);
        }

        return count;
    }

    public static void closeQuietly(InputStream input) {
        closeQuietly((Closeable) input);
    }

    public static void closeQuietly(Closeable closeable) {
        try {
            if (closeable != null) {
                closeable.close();
            }
        } catch (IOException var2) {
            ;
        }

    }

    public static void closeQuietly(OutputStream output) {
        closeQuietly((Closeable) output);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy