aboutsummaryrefslogtreecommitdiff
path: root/spark-common/src/main/java/me/lucko/spark/common/util
diff options
context:
space:
mode:
Diffstat (limited to 'spark-common/src/main/java/me/lucko/spark/common/util')
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/util/BytebinClient.java15
1 files changed, 15 insertions, 0 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/util/BytebinClient.java b/spark-common/src/main/java/me/lucko/spark/common/util/BytebinClient.java
index 9202303..29ee5bb 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/util/BytebinClient.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/util/BytebinClient.java
@@ -25,13 +25,18 @@
package me.lucko.spark.common.util;
+import com.google.protobuf.AbstractMessageLite;
+
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
+import java.util.zip.GZIPOutputStream;
/**
* Utility for posting content to bytebin.
@@ -81,6 +86,16 @@ public class BytebinClient extends AbstractHttpClient {
}
}
+ public Content postContent(AbstractMessageLite<?, ?> proto, MediaType contentType) throws IOException {
+ ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
+ try (OutputStream out = new GZIPOutputStream(byteOut)) {
+ proto.writeTo(out);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return postContent(byteOut.toByteArray(), contentType);
+ }
+
public static final class Content {
private final String key;