Esempio n. 1
0
 private <T> void encodeOptional(DataOutputStream os, Optional<T> ot, Codec<T> codec)
     throws IOException {
   if (ot.isPresent()) {
     os.writeBoolean(true);
     codec.encode(os, ot.get());
   } else {
     os.writeBoolean(false);
   }
 }
Esempio n. 2
0
 private <T> Optional<T> decodeOptional(DataInputStream is, Codec<T> codec)
     throws IOException {
   return is.readBoolean() ? Optional.of(codec.decode(is)) : Optional.empty();
 }