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

io.github.taills.common.util.ResourceUtils Maven / Gradle / Ivy

There is a newer version: 1.3.0
Show newest version
package io.github.taills.common.util;


import org.springframework.core.io.Resource;
import org.springframework.util.FileCopyUtils;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UncheckedIOException;

import static java.nio.charset.StandardCharsets.UTF_8;

/**
 * @ClassName ResourceUtils
 * @Description
 * @Author nil
 * @Date 2022/1/10 5:24 PM
 **/
public class ResourceUtils {
    public static String asString(Resource resource) {
        try (Reader reader = new InputStreamReader(resource.getInputStream(), UTF_8)) {
            return FileCopyUtils.copyToString(reader);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy