private static byte[] toByteArray(InputStream in) throws IOException {
    ArrayDeque<byte[]> deque = new ArrayDeque<>();
    byte[] buf = new byte[100];
    int read = in.read(buf);
    while (read != -1) {
      deque.add(Arrays.copyOf(buf, read));
      read = in.read(buf);
    }
    return combine(deque);
  }
Writes the keyset managed by {@code handle} to {@code outputStream} with format {@code
outFormat}. Maybe encrypt it with {@code masterKeyUri} and {@code credentialPath}.
tools/tinkey/src/main/java/com/google/crypto/tink/tinkey/TinkeyUtil.java