Java Code Examples for org.apache.commons.compress.utils.Charsets

The following examples show how to use org.apache.commons.compress.utils.Charsets. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private Map<String, SignatureVerificationResult> checkAssertions(List<String> result) throws Exception {
   SignatureBuilder builder = SignatureBuilderFactory.getSignatureBuilder(AdvancedElectronicSignatureEnumeration.XAdES);
   Map<String, Object> options = Collections.emptyMap();
   Map<String, SignatureVerificationResult> signatureVerificationResults = new HashMap();
   Iterator i$ = result.iterator();

   while(i$.hasNext()) {
      String assertionXml = (String)i$.next();
      if (assertionXml != null) {
         Assertion assertion = (Assertion)ConnectorXmlUtils.toObject(assertionXml, Assertion.class);
         if (assertion != null && assertion.getSignature() != null) {
            SignatureVerificationResult signatureVerificationResult = builder.verify(assertionXml.getBytes(Charsets.UTF_8), options);
            signatureVerificationResults.put(assertion.getID(), signatureVerificationResult);

   return signatureVerificationResults;
Example 2
Source Project: ecs-sync   Source File:    License: Apache License 2.0 6 votes vote down vote up
 * Generates a standard MD5 (from the object data) for individual versions, but for an instance that holds the entire
 * version list, generates an aggregate MD5 (of the individual MD5s) of all versions
public String getMd5Hex(boolean forceRead) {
    // only the latest version (the one that is referenced by the ObjectContext) will have this property
    List versions = (List) getProperty(AbstractS3Storage.PROP_OBJECT_VERSIONS);
    if (versions == null) return super.getMd5Hex(forceRead);

    // build canonical string of all versions (deleteMarker, eTag) and hash it
    StringBuilder canonicalString = new StringBuilder("[");
    for (Object versionO : versions) {
        S3ObjectVersion version = (S3ObjectVersion) versionO;
        String md5 = (version == this) ? super.getMd5Hex(forceRead) : version.getMd5Hex(forceRead);

    try {
        MessageDigest digest = MessageDigest.getInstance("md5");
        return DatatypeConverter.printHexBinary(digest.digest(canonicalString.toString().getBytes(Charsets.UTF_8)));
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException("Could not initialize MD5", e);
Example 3
Source Project: beam   Source File:    License: Apache License 2.0 5 votes vote down vote up
private static String getErrorMessage(final HttpEntity entity) throws IOException {
  final Header encodingHeader = entity.getContentEncoding();
  final Charset encoding =
      encodingHeader == null
          ? StandardCharsets.UTF_8
          : Charsets.toCharset(encodingHeader.getValue());
  final JsonElement errorElement =
      new Gson().fromJson(EntityUtils.toString(entity, encoding), JsonObject.class).get("error");
  return isNull(errorElement) ? "[Unable to get error message]" : errorElement.toString();
Example 4
Source Project: ecs-sync   Source File:    License: Apache License 2.0 4 votes vote down vote up
public void testDuplicatesInSourceList() throws Exception {
    SyncOptions options = new SyncOptions();

    // construct source storage
    TestConfig testConfig = new TestConfig().withDiscardData(false);
    TestStorage source = new TestStorage();

    // ingest one object
    String identifier = source.getIdentifier("foo", false);
            new SyncObject(source, "foo", new ObjectMetadata(), new ByteArrayInputStream(new byte[0]), new ObjectAcl()));

    // create source list file with x duplicates
    int x = 12;
    StringBuilder list = new StringBuilder();
    for (int i = 0; i < x; i++) {
    Path sourceListPath = Files.createTempFile("dup-source-list", null);
    Files.write(sourceListPath, list.toString().getBytes(Charsets.UTF_8));


    // create a DB table (this is the root of the issue)
    DbService dbService = new SqliteDbService(":memory:");

    SyncConfig syncConfig = new SyncConfig().withOptions(options).withTarget(new TestConfig());

    // run sync
    EcsSync sync = new EcsSync();

    Assert.assertEquals(0, sync.getStats().getObjectsFailed());
    Assert.assertEquals(1, sync.getStats().getObjectsComplete());
    Assert.assertEquals(x - 1, sync.getStats().getObjectsSkipped());

    // count DB records
    int count = 0;
    for (SyncRecord record : dbService.getAllRecords()) {
    Assert.assertEquals(1, count);