package io.snowcamp.papaya.api;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalDouble;
import java.util.OptionalInt;
import java.util.OptionalLong;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public interface Document extends Map<String, Object> {
  // a map of key/value pairs, keys are String, values are any JSON values
  
  default <T> Optional<T> get(String key, Class<T> type) {
    return Optional.ofNullable(get(key)).filter(type::isInstance).map(type::cast);
  }
  
  default OptionalInt getInt(String key) {
    return get(key, Integer.class).map(OptionalInt::of).orElseGet(OptionalInt::empty);
  }
  default OptionalLong getLong(String key) {
    return get(key, Long.class).map(OptionalLong::of).orElseGet(OptionalLong::empty);
  }
  default OptionalDouble getDouble(String key) {
    return get(key, Double.class).map(OptionalDouble::of).orElseGet(OptionalDouble::empty);
  }
  
  default void putBlob(String key, byte[] blob) {
    put(key, new BASE64Encoder().encode(blob));
  }
  default Optional<byte[]> getBlob(String key) {
    return get(key, String.class).map(base64 -> {
      try {
        return new BASE64Decoder().decodeBuffer(base64);
      } catch (IOException e) {
        throw new UncheckedIOException(e);
      }
    });
  }
}

@@ -42,59 +42,61 @@
 ava.
+n
 io.
-IOException;%0Aimport java.io.UncheckedIOException
+charset.StandardCharsets;%0Aimport java.util.Base64
 ;%0Aim
@@ -241,71 +241,8 @@
 g;%0A%0A
-import sun.misc.BASE64Decoder;%0Aimport sun.misc.BASE64Encoder;%0A%0A
 publ
@@ -1004,22 +1004,33 @@
 ey, new 
-BASE64
+String(Base64.get
 Encoder(
@@ -1043,16 +1043,46 @@
 de(blob)
+, StandardCharsets.ISO_8859_1)
 );%0A  %7D%0A 
@@ -1181,47 +1181,18 @@
  -%3E 
-%7B%0A      try %7B%0A        return new BASE64
+Base64.get
 Deco
@@ -1207,22 +1207,16 @@
 code
-Buffer
 (base64)
 ;%0A  
@@ -1215,98 +1215,8 @@
 e64)
-;%0A      %7D catch (IOException e) %7B%0A        throw new UncheckedIOException(e);%0A      %7D%0A    %7D
 );%0A 

use java.util.Base64 instead of sun.misc.Base64Encoder/Decoder