yangys
2024-04-01 86cdd920b68274185233383f69ddb974052b6b6f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.qianwen.core.tool.utils;
 
import java.io.Closeable;
import java.io.Flushable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
import org.springframework.lang.Nullable;
import org.springframework.util.StreamUtils;
 
/* loaded from: blade-core-tool-9.3.0.0-SNAPSHOT.jar:org/springblade/core/tool/utils/IoUtil.class */
public class IoUtil extends StreamUtils {
    public static void closeQuietly(@Nullable Closeable closeable) {
        if (closeable == null) {
            return;
        }
        if (closeable instanceof Flushable) {
            try {
                ((Flushable) closeable).flush();
            } catch (IOException e) {
            }
        }
        try {
            closeable.close();
        } catch (IOException e2) {
        }
    }
 
    public static String readToString(InputStream input) {
        return readToString(input, Charsets.UTF_8);
    }
 
    public static String readToString(@Nullable InputStream input, Charset charset) {
        try {
            try {
                String copyToString = copyToString(input, charset);
                closeQuietly(input);
                return copyToString;
            } catch (IOException e) {
                throw Exceptions.unchecked(e);
            }
        } catch (Throwable th) {
            closeQuietly(input);
            throw th;
        }
    }
 
    public static byte[] readToByteArray(@Nullable InputStream input) {
        try {
            try {
                byte[] copyToByteArray = copyToByteArray(input);
                closeQuietly(input);
                return copyToByteArray;
            } catch (IOException e) {
                throw Exceptions.unchecked(e);
            }
        } catch (Throwable th) {
            closeQuietly(input);
            throw th;
        }
    }
 
    public static void write(@Nullable final String data, final OutputStream output, final Charset encoding) throws IOException {
        if (data != null) {
            output.write(data.getBytes(encoding));
        }
    }
}