Deserialize a Base64-encoded histogram, used when deserializing from JSON (such as when transferring query results)
or when ingesting a pre-computed histogram.

@param encodedHistogram Base64-encoded histogram
@return Deserialized object
495084
public static FixedBucketsHistogram fromBase64(String encodedHistogram)
  {
    byte[] asBytes = StringUtils.decodeBase64(encodedHistogram.getBytes(StandardCharsets.UTF_8));
    return fromBytes(asBytes);
  }
406122
@SneakyThrows
    public static <T extends Serializable> T decodeAndDeserializeObject(final byte[] object,
                                                                        final CipherExecutor cipher,
                                                                        final Class<T> type) {
        return decodeAndDeserializeObject(object, cipher, type, ArrayUtils.EMPTY_OBJECT_ARRAY);
    }
386014
private Histogram getHistogram(String entity, String watermarkColumn, SourceState state,
      Partition partition) {
    SalesforceConnector connector = getConnector(state);

    try {
      if (!connector.connect()) {
        throw new RuntimeException("Failed to connect.");
      }
    } catch (RestApiConnectionException e) {
      throw new RuntimeException("Failed to connect.", e);
    }

    Histogram histogram = getHistogramByDayBucketing(connector, entity, watermarkColumn, partition);

    // exchange the first histogram group key with the global low watermark to ensure that the low watermark is captured
    // in the range of generated partitions
    HistogramGroup firstGroup = histogram.get(0);
    Date lwmDate = Utils.toDate(partition.getLowWatermark(), Partitioner.WATERMARKTIMEFORMAT);
    histogram.getGroups().set(0, new HistogramGroup(Utils.epochToDate(lwmDate.getTime(), SECONDS_FORMAT),
        firstGroup.getCount()));

    // refine the histogram
    if (state.getPropAsBoolean(ENABLE_DYNAMIC_PROBING)) {
      histogram = getRefinedHistogram(connector, entity, watermarkColumn, state, partition, histogram);
    }

    return histogram;
  }
644344
public Object deserialize(JsonObject message) {
    String type = message.getString("type");
    if (type == null) {
      return message.getValue("value");
    } else {
      switch (type) {
        case "buffer":
          return new Buffer(message.getBinary("value"));
        case "bytes":
          return message.getBinary("value");
        case "serialized":
          byte[] bytes = message.getBinary("value");
          ObjectInputStream stream = null;
          try {
            stream = new ThreadObjectInputStream(new ByteArrayInputStream(bytes));
            return stream.readObject();
          } catch (ClassNotFoundException | IOException e) {
            throw new SerializationException(e.getMessage());
          } finally {
            if (stream != null) {
              try {
                stream.close();
              } catch (IOException e) {
              }
            }
          }
        default:
          return message.getValue("value");
      }
    }
  }
1013003
public static String decryptData(String base64EncryptedInfo, String encoding) {
		return SecureUtil.decryptData(base64EncryptedInfo, encoding, CertUtil
				.getSignCertPrivateKey());
	}
1346238
@Deprecated
    public static byte[] encodeToBytes(byte[] bytes)
    {
        try {
            char[] chars = Base64.encode(bytes);
            String string = new String(chars);
            return string.getBytes(DEFAULT_ENCODING);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }
413173
public static byte[] decodeToBytes(String encoded) {
    try {
      byte[] bytes = encoded.getBytes("UTF-8");
      Base64Decoder in = new Base64Decoder(new ByteArrayInputStream(bytes));

      ByteArrayOutputStream out = new ByteArrayOutputStream((int) (bytes.length * 0.67));

      try {
        byte[] buf = new byte[4 * 1024]; // 4K buffer
        int bytesRead;
        while ((bytesRead = in.read(buf)) != -1) {
          out.write(buf, 0, bytesRead);
        }
        out.close();

        return out.toByteArray();
      } catch (IOException ignored) {
        return null;
      }
    } catch (UnsupportedEncodingException ignored) {
      return null;
    }
  }
119047
public static Binary fromBase64(String base64) {
        byte[] arr = Base64.decode(base64);
        return Binary.wrap(arr);
    }
955223
public static String base64Decode(String base64Str,String encoding) throws IOException{
		byte [] rawByte = base64Str.getBytes(encoding);
		return new String(SecureUtil.base64Decode(rawByte),encoding);	
	}
892871
@Deprecated
    public static String decode(String string)
    {
        try {
            byte[] bytes = Base64.decode(string.toCharArray());
            return new String(bytes, DEFAULT_ENCODING);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }
1124371
public static byte[] decode(byte[] in) {
        return org.apache.commons.codec.binary.Base64.decodeBase64(in);
    }
969323
public Histogram_F64 copy() {
		Histogram_F64 out = newInstance();

		System.arraycopy(value,0,out.value,0,length.length);

		return out;
	}
965341
public final byte[] decodeString(String base64String) {
        logger.entry();
        byte[] decodedBytes = Base64Utils.decode(base64String);
        logger.exit();
        return decodedBytes;
    }
1244177
public static final Object deserialize(byte[] bytes) throws Exception {
        final boolean trace = TraceComponent.isAnyTracingEnabled();
        if (trace && tc.isEntryEnabled())
            Tr.entry(tc, "deserialize");

        Object o;
        try {
            ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
            ObjectInputStream oin = new ObjectInputStream(bis);
            o = oin.readObject();
            oin.close();
        } catch (IOException e) {
            FFDCFilter.processException(e, ConnectorService.class.getName(), "151");
            if (trace && tc.isEntryEnabled())
                Tr.exit(tc, "deserialize", new Object[] { toString(bytes), e });
            throw e;
        }

        if (trace && tc.isEntryEnabled())
            Tr.exit(tc, "deserialize", o == null ? null : o.getClass());
        return o;
    }
683799
public static JWSHeader fromBase64String(String base64) throws IOException {
        String json = MessageSecurityHelper.base64UrltoString(base64);
        ObjectMapper mapper = new ObjectMapper();
        return mapper.readValue(json, JWSHeader.class);
    }
425532
public static String base64Encode(String rawStr,String encoding) throws IOException{
		byte [] rawByte = rawStr.getBytes(encoding);
		return new String(SecureUtil.base64Encode(rawByte),encoding);
	}
29331
public static Header decode(String header) {
    // verify to json with JAX-RS standard
    JsonObject json;
    try {
      json = Json.createReader(new ByteArrayInputStream(Base64.getUrlDecoder().decode(header))).readObject();
    } catch (JsonException e) {
      throw new DecodeException("Failed convert to JsonObject", e);
    } catch (IllegalArgumentException e) {
      throw new DecodeException("The header is not in valid Base64 scheme", e);
    }

    // validate the typ parameter
    String type = json.containsKey("typ") ? json.getString("typ") : null;
    if (type != null && !DEFAULT_TYPE.equals(type))
      throw new DecodeException("The header type '" + type + "' is not support.");

    // validate the alg parameter
    String algorithm = json.containsKey("alg") ? json.getString("alg") : null;
    if (algorithm != null && !Algorithm.HS256.name().equals(algorithm))
      throw new DecodeException("The header algorithm '" + algorithm + "' is not support.");

    // construct a header instance
    if (DEFAULT_TYPE.equals(type) && Algorithm.HS256.name().equals(algorithm)) {
      // optimise the default standard header to always the same instance
      return Header.DEFAULT;
    } else {
      // create a whole new instance
      Header h = new Header();
      h.type = type;
      h.algorithm = (algorithm != null ? Algorithm.valueOf(algorithm) : null);
      return h;
    }
  }