forked from TrueCloudLab/frostfs-sdk-java
31 lines
868 B
Java
31 lines
868 B
Java
package info.frostfs.sdk;
|
|
|
|
import com.google.common.io.ByteStreams;
|
|
import lombok.SneakyThrows;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import static java.util.Objects.isNull;
|
|
|
|
public class FileUtils {
|
|
|
|
@SneakyThrows
|
|
public static byte[] resourceToBytes(String resourcePath) {
|
|
if (StringUtils.isBlank(resourcePath)) {
|
|
throw new IllegalArgumentException("Blank filename!");
|
|
}
|
|
|
|
ClassLoader loader = FileUtils.class.getClassLoader();
|
|
if (isNull(loader)) {
|
|
throw new RuntimeException("Class loader is null!");
|
|
}
|
|
|
|
InputStream certStream = loader.getResourceAsStream(resourcePath);
|
|
if (isNull(certStream)) {
|
|
throw new RuntimeException("Resource could not be found!");
|
|
}
|
|
|
|
return ByteStreams.toByteArray(certStream);
|
|
}
|
|
}
|