コード例 #1
0
 public static void compress(ValueOut out, String compression, Bytes bytes) {
   switch (compression) {
     case "snappy":
       try {
         out.bytes("snappy", Snappy.compress(bytes.toByteArray()));
       } catch (IOException e) {
         throw new AssertionError(e);
       }
       break;
     case "gzip":
       try {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         GZIPOutputStream gos = new GZIPOutputStream(baos);
         bytes.copyTo(gos);
         gos.close();
         out.bytes("gzip", baos.toByteArray());
       } catch (IOException e) {
         throw new AssertionError(e);
       }
       break;
     default:
       throw new IllegalArgumentException("Unknown compression " + compression);
   }
 }