@Test public void testGetId() { GlobalMetadata m1 = buildMetadata(); GlobalMetadata m2 = buildMetadata(); Assert.assertEquals(m1.getId(), m2.getId()); m1.addTransferEncoding("baz"); Assert.assertNotEquals(m1.getId(), m2.getId()); }
public String getId() { if (cachedId != null) { return cachedId; } if (datasetLevel.size() == 0 && fileLevel.size() == 0) { cachedId = EMPTY_ID; return cachedId; } try { ByteArrayOutputStream bOs = new ByteArrayOutputStream(512); MessageDigest md5Digest = MessageDigest.getInstance("MD5"); try (JsonGenerator generator = jsonFactory.createJsonGenerator(bOs, JsonEncoding.UTF8).setCodec(objectMapper)) { generator.writeStartObject(); bodyToJsonUtf8(generator); generator.writeEndObject(); } byte[] digestBytes = md5Digest.digest(bOs.toByteArray()); cachedId = DatatypeConverter.printHexBinary(digestBytes); return cachedId; } catch (IOException|NoSuchAlgorithmException e) { throw new RuntimeException("Unexpected exception generating id", e); } }
GlobalMetadata { public String getId() { if (cachedId != null) { return cachedId; } if (datasetLevel.size() == 0 && fileLevel.size() == 0) { cachedId = EMPTY_ID; return cachedId; } try { ByteArrayOutputStream bOs = new ByteArrayOutputStream(512); MessageDigest md5Digest = MessageDigest.getInstance("MD5"); try (JsonGenerator generator = jsonFactory.createJsonGenerator(bOs, JsonEncoding.UTF8).setCodec(objectMapper)) { generator.writeStartObject(); bodyToJsonUtf8(generator); generator.writeEndObject(); } byte[] digestBytes = md5Digest.digest(bOs.toByteArray()); cachedId = DatatypeConverter.printHexBinary(digestBytes); return cachedId; } catch (IOException|NoSuchAlgorithmException e) { throw new RuntimeException("Unexpected exception generating id", e); } } }
GlobalMetadata { public String getId() { if (cachedId != null) { return cachedId; } if (datasetLevel.size() == 0 && fileLevel.size() == 0) { cachedId = EMPTY_ID; return cachedId; } try { ByteArrayOutputStream bOs = new ByteArrayOutputStream(512); MessageDigest md5Digest = MessageDigest.getInstance("MD5"); try (JsonGenerator generator = jsonFactory.createJsonGenerator(bOs, JsonEncoding.UTF8).setCodec(objectMapper)) { generator.writeStartObject(); bodyToJsonUtf8(generator); generator.writeEndObject(); } byte[] digestBytes = md5Digest.digest(bOs.toByteArray()); cachedId = DatatypeConverter.printHexBinary(digestBytes); return cachedId; } catch (IOException|NoSuchAlgorithmException e) { throw new RuntimeException("Unexpected exception generating id", e); } } GlobalMetadata(); }
GlobalMetadata { public String getId() { if (cachedId != null) { return cachedId; } if (datasetLevel.size() == 0 && fileLevel.size() == 0) { cachedId = EMPTY_ID; return cachedId; } try { ByteArrayOutputStream bOs = new ByteArrayOutputStream(512); MessageDigest md5Digest = MessageDigest.getInstance("MD5"); try (JsonGenerator generator = jsonFactory.createJsonGenerator(bOs, JsonEncoding.UTF8).setCodec(objectMapper)) { generator.writeStartObject(); bodyToJsonUtf8(generator); generator.writeEndObject(); } byte[] digestBytes = md5Digest.digest(bOs.toByteArray()); cachedId = DatatypeConverter.printHexBinary(digestBytes); return cachedId; } catch (IOException|NoSuchAlgorithmException e) { throw new RuntimeException("Unexpected exception generating id", e); } } GlobalMetadata(); void markImmutable(); boolean isImmutable(); static GlobalMetadata fromJson(String json); void addAll(GlobalMetadata other); void mergeWithDefaults(GlobalMetadata defaults); byte[] toJsonUtf8(); String toJson(); String getDatasetUrn(); void setDatasetUrn(String urn); void setContentType(String contentType); String getContentType(); void setInnerContentType(String innerContentType); String getInnerContentType(); void setNumOutputFiles(int numFiles); void setNumRecords(long numRecords); Object getDatasetMetadata(String key); void setDatasetMetadata(String key, Object val); @SuppressWarnings("unchecked") List<String> getTransferEncoding(); synchronized void addTransferEncoding(String encoding); long getNumRecords(); int getNumFiles(); Object getFileMetadata(String file, String key); void setFileMetadata(String file, String key, Object val); @Override boolean equals(Object o); @Override int hashCode(); String getId(); boolean isEmpty(); }
GlobalMetadata { public String getId() { if (cachedId != null) { return cachedId; } if (datasetLevel.size() == 0 && fileLevel.size() == 0) { cachedId = EMPTY_ID; return cachedId; } try { ByteArrayOutputStream bOs = new ByteArrayOutputStream(512); MessageDigest md5Digest = MessageDigest.getInstance("MD5"); try (JsonGenerator generator = jsonFactory.createJsonGenerator(bOs, JsonEncoding.UTF8).setCodec(objectMapper)) { generator.writeStartObject(); bodyToJsonUtf8(generator); generator.writeEndObject(); } byte[] digestBytes = md5Digest.digest(bOs.toByteArray()); cachedId = DatatypeConverter.printHexBinary(digestBytes); return cachedId; } catch (IOException|NoSuchAlgorithmException e) { throw new RuntimeException("Unexpected exception generating id", e); } } GlobalMetadata(); void markImmutable(); boolean isImmutable(); static GlobalMetadata fromJson(String json); void addAll(GlobalMetadata other); void mergeWithDefaults(GlobalMetadata defaults); byte[] toJsonUtf8(); String toJson(); String getDatasetUrn(); void setDatasetUrn(String urn); void setContentType(String contentType); String getContentType(); void setInnerContentType(String innerContentType); String getInnerContentType(); void setNumOutputFiles(int numFiles); void setNumRecords(long numRecords); Object getDatasetMetadata(String key); void setDatasetMetadata(String key, Object val); @SuppressWarnings("unchecked") List<String> getTransferEncoding(); synchronized void addTransferEncoding(String encoding); long getNumRecords(); int getNumFiles(); Object getFileMetadata(String file, String key); void setFileMetadata(String file, String key, Object val); @Override boolean equals(Object o); @Override int hashCode(); String getId(); boolean isEmpty(); final static String DATASET_URN_KEY; final static String TRANSFER_ENCODING_KEY; final static String CONTENT_TYPE_KEY; final static String INNER_CONTENT_TYPE_KEY; final static String NUM_RECORDS_KEY; final static String NUM_FILES_KEY; }