frostfs-sdk-java/client/src/test/java/info/frostfs/sdk/FileUtils.java
Bruk Ori 694bb963e4 [#23] Update proto api
Add chain functionality
Add tests
Signed-off-by: Ori Bruk <o.bruk@yadro.com>
2024-11-05 11:39:57 +03:00

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);
}
}