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

The following examples show how to use org.apache.commons.compress.utils.Charsets. 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
Source File: ResponseObjectBuilderImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
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 File: S3ObjectVersion.java    From ecs-sync with 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
 */
@Override
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);
        canonicalString.append("{")
                .append("\"deleteMarker\":").append(version.isDeleteMarker())
                .append("\"md5\":\"").append(md5).append("\"")
                .append("}");
    }
    canonicalString.append("]");

    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 File: InfluxDBPublisher.java    From beam with 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 File: SyncProcessTest.java    From ecs-sync with Apache License 2.0 4 votes vote down vote up
@Test
public void testDuplicatesInSourceList() throws Exception {
    SyncOptions options = new SyncOptions();

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

    // ingest one object
    String identifier = source.getIdentifier("foo", false);
    source.updateObject(identifier,
            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++) {
        list.append(identifier).append("\n");
    }
    Path sourceListPath = Files.createTempFile("dup-source-list", null);
    Files.write(sourceListPath, list.toString().getBytes(Charsets.UTF_8));

    options.setSourceListFile(sourceListPath.toString());

    // 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();
    sync.setSyncConfig(syncConfig);
    sync.setSource(source);
    sync.setDbService(dbService);
    sync.run();

    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()) {
        count++;
    }
    Assert.assertEquals(1, count);
}