Add a bytes() method for MoreHttpResponses

This commit is contained in:
Sollace 2018-09-07 19:50:44 +02:00
parent 0f454b753c
commit e296d87376

View file

@ -1,5 +1,6 @@
package com.voxelmodpack.hdskins.util; package com.voxelmodpack.hdskins.util;
import com.google.common.io.ByteStreams;
import com.google.common.io.CharStreams; import com.google.common.io.CharStreams;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.voxelmodpack.hdskins.server.SkinServer; import com.voxelmodpack.hdskins.server.SkinServer;
@ -48,6 +49,12 @@ public interface MoreHttpResponses extends AutoCloseable {
return new BufferedReader(new InputStreamReader(getInputStream(), StandardCharsets.UTF_8)); return new BufferedReader(new InputStreamReader(getInputStream(), StandardCharsets.UTF_8));
} }
default byte[] bytes() throws IOException {
try (InputStream input = getInputStream()) {
return ByteStreams.toByteArray(input);
}
}
default String text() throws IOException { default String text() throws IOException {
try (BufferedReader reader = getReader()) { try (BufferedReader reader = getReader()) {
return CharStreams.toString(reader); return CharStreams.toString(reader);