/** * Convert the given string to be safe for use in signed URLs for a private distribution. * * @param str * @return a URL-safe Base64 encoded version of the data. * @throws UnsupportedEncodingException */ protected static String makeStringUrlSafe(String str) throws UnsupportedEncodingException { return ServiceUtils.toBase64(str.getBytes("UTF-8")) .replace('+', '-') .replace('=', '_') .replace('/', '~'); }
/** * Convert the given data to be safe for use in signed URLs for a private distribution by * using specialized Base64 encoding. * * @param bytes * @return a URL-safe Base64 encoded version of the data. * @throws UnsupportedEncodingException */ protected static String makeBytesUrlSafe(byte[] bytes) throws UnsupportedEncodingException { return ServiceUtils.toBase64(bytes) .replace('+', '-') .replace('=', '_') .replace('/', '~'); }
/** * Convert the given string to be safe for use in signed URLs for a private distribution. * * @param str * @return a URL-safe Base64 encoded version of the data. * @throws UnsupportedEncodingException */ protected static String makeStringUrlSafe(String str) throws UnsupportedEncodingException { return ServiceUtils.toBase64(str.getBytes("UTF-8")) .replace('+', '-') .replace('=', '_') .replace('/', '~'); }
/** * Convert the given data to be safe for use in signed URLs for a private distribution by * using specialized Base64 encoding. * * @param bytes * @return a URL-safe Base64 encoded version of the data. * @throws UnsupportedEncodingException */ protected static String makeBytesUrlSafe(byte[] bytes) throws UnsupportedEncodingException { return ServiceUtils.toBase64(bytes) .replace('+', '-') .replace('=', '_') .replace('/', '~'); }
/** * Calculates the MD5 hash value of the given data object, and compares it * against this object's hash (as stored in the Content-MD5 header for * uploads, or the ETag header for downloads). * * @param downloadedDataStream * the input stream of a downloaded object. * * @return * true if the calculated MD5 hash value of the input stream matches this * object's hash value, false otherwise. * * @throws NoSuchAlgorithmException * @throws FileNotFoundException * @throws IOException */ public boolean verifyData(InputStream downloadedDataStream) throws NoSuchAlgorithmException, FileNotFoundException, IOException { return getMd5HashAsBase64().equals( ServiceUtils.toBase64( ServiceUtils.computeMD5Hash(downloadedDataStream))); }
/** * Calculates the MD5 hash value of the given data object, and compares it * against this object's hash (as stored in the Content-MD5 header for * uploads, or the ETag header for downloads). * * @param downloadedData * @return * true if the calculated MD5 hash value of the bytes matches this object's * hash value, false otherwise. * * @throws NoSuchAlgorithmException * @throws FileNotFoundException * @throws IOException */ public boolean verifyData(byte[] downloadedData) throws NoSuchAlgorithmException, FileNotFoundException, IOException { return getMd5HashAsBase64().equals( ServiceUtils.toBase64( ServiceUtils.computeMD5Hash(downloadedData))); }
ServiceUtils.toBase64( ServiceUtils.computeMD5Hash( new FileInputStream(downloadedFile))));
/** * Calculates the MD5 hash value of the given data object, and compares it * against this object's hash (as stored in the Content-MD5 header for * uploads, or the ETag header for downloads). * * @param downloadedData * @return * true if the calculated MD5 hash value of the bytes matches this object's * hash value, false otherwise. * * @throws NoSuchAlgorithmException * @throws FileNotFoundException * @throws IOException */ public boolean verifyData(byte[] downloadedData) throws NoSuchAlgorithmException, FileNotFoundException, IOException { return getMd5HashAsBase64().equals( ServiceUtils.toBase64( ServiceUtils.computeMD5Hash(downloadedData))); }
ServiceUtils.toBase64( ServiceUtils.computeMD5Hash( new FileInputStream(downloadedFile))));
/** * Calculates the MD5 hash value of the given data object, and compares it * against this object's hash (as stored in the Content-MD5 header for * uploads, or the ETag header for downloads). * * @param downloadedDataStream * the input stream of a downloaded object. * * @return * true if the calculated MD5 hash value of the input stream matches this * object's hash value, false otherwise. * * @throws NoSuchAlgorithmException * @throws FileNotFoundException * @throws IOException */ public boolean verifyData(InputStream downloadedDataStream) throws NoSuchAlgorithmException, FileNotFoundException, IOException { return getMd5HashAsBase64().equals( ServiceUtils.toBase64( ServiceUtils.computeMD5Hash(downloadedDataStream))); }
if (log.isDebugEnabled()) { log.debug("MD5 digest of data sent for '" + name + "' - B64:" + ServiceUtils.toBase64(dataMD5Hash) + " Hex:" + ServiceUtils.toHex(dataMD5Hash));
/** * Set the MD5 hash value of this object's data. * The hash value is stored as metadata under <code>Content-MD5</code> (Base64-encoded) * and the JetS3t-specific <code>md5-hash</code> (Hex-encoded). * * @param md5Hash * the MD5 hash value of the object's data. */ public void setMd5Hash(byte[] md5Hash) { addMetadata(METADATA_HEADER_HASH_MD5, ServiceUtils.toHex(md5Hash)); addMetadata(METADATA_HEADER_CONTENT_MD5, ServiceUtils.toBase64(md5Hash)); }
/** * Set the MD5 hash value of this object's data. * The hash value is stored as metadata under <code>Content-MD5</code> (Base64-encoded) * and the JetS3t-specific <code>md5-hash</code> (Hex-encoded). * * @param md5Hash * the MD5 hash value of the object's data. */ public void setMd5Hash(byte[] md5Hash) { addMetadata(METADATA_HEADER_HASH_MD5, ServiceUtils.toHex(md5Hash)); addMetadata(METADATA_HEADER_CONTENT_MD5, ServiceUtils.toBase64(md5Hash)); }
@Override public void setLifecycleConfigImpl(String bucketName, LifecycleConfig config) throws S3ServiceException { Map<String, String> requestParameters = new HashMap<String, String>(); requestParameters.put("lifecycle", ""); String xml; String xmlMd5Hash; try { xml = config.toXml(); xmlMd5Hash = ServiceUtils.toBase64( ServiceUtils.computeMD5Hash(xml.getBytes(Constants.DEFAULT_ENCODING))); } catch (Exception e) { throw new S3ServiceException("Unable to build LifecycleConfig XML document", e); } Map<String, Object> metadata = new HashMap<String, Object>(); metadata.put("Content-MD5", xmlMd5Hash); try { performRestPut(bucketName, null, metadata, requestParameters, new StringEntity(xml, "text/plain", Constants.DEFAULT_ENCODING), true); } catch (ServiceException se) { throw new S3ServiceException(se); } catch (UnsupportedEncodingException e) { throw new S3ServiceException("Unable to encode XML document", e); } }
@Override public void setLifecycleConfigImpl(String bucketName, LifecycleConfig config) throws S3ServiceException { Map<String, String> requestParameters = new HashMap<String, String>(); requestParameters.put("lifecycle", ""); String xml; String xmlMd5Hash; try { xml = config.toXml(); xmlMd5Hash = ServiceUtils.toBase64( ServiceUtils.computeMD5Hash(xml.getBytes(Constants.DEFAULT_ENCODING))); } catch (Exception e) { throw new S3ServiceException("Unable to build LifecycleConfig XML document", e); } Map<String, Object> metadata = new HashMap<String, Object>(); metadata.put("Content-MD5", xmlMd5Hash); try { performRestPut(bucketName, null, metadata, requestParameters, new StringEntity(xml, "text/plain", Constants.DEFAULT_ENCODING), true); } catch (ServiceException se) { throw new S3ServiceException(se); } catch (UnsupportedEncodingException e) { throw new S3ServiceException("Unable to encode XML document", e); } }
/** * @return * the Base64-encoded MD5 hash of an object's data contents as stored in the metadata * item <code>Content-MD5</code>, or as derived from an <code>ETag</code> or * <code>md5-hash</code> hex-encoded version of the hash. Returns null if the hash value is not * available. */ public String getMd5HashAsBase64() { String md5HashBase64 = (String) getMetadata(METADATA_HEADER_CONTENT_MD5); if (md5HashBase64 == null) { // Try converting the object's ETag (a hex-encoded md5 hash). final String eTag = getETag(); if (eTag != null && ServiceUtils.isEtagAlsoAnMD5Hash(eTag)) { return ServiceUtils.toBase64(ServiceUtils.fromHex(eTag)); } // Try converting the object's md5-hash (another hex-encoded md5 hash). if (getMd5HashAsHex() != null) { return ServiceUtils.toBase64(ServiceUtils.fromHex(getMd5HashAsHex())); } } return md5HashBase64; }
/** * @return * the Base64-encoded MD5 hash of an object's data contents as stored in the metadata * item <code>Content-MD5</code>, or as derived from an <code>ETag</code> or * <code>md5-hash</code> hex-encoded version of the hash. Returns null if the hash value is not * available. */ public String getMd5HashAsBase64() { String md5HashBase64 = (String) getMetadata(METADATA_HEADER_CONTENT_MD5); if (md5HashBase64 == null) { // Try converting the object's ETag (a hex-encoded md5 hash). final String eTag = getETag(); if (eTag != null && ServiceUtils.isEtagAlsoAnMD5Hash(eTag)) { return ServiceUtils.toBase64(ServiceUtils.fromHex(eTag)); } // Try converting the object's md5-hash (another hex-encoded md5 hash). if (getMd5HashAsHex() != null) { return ServiceUtils.toBase64(ServiceUtils.fromHex(getMd5HashAsHex())); } } return md5HashBase64; }
/** * Add default metadata. Do not add checksum as object metadata must remain constant for all chunks. */ protected S3Object getDetails(final Path file, final TransferStatus status) { final S3Object object = new S3Object(containerService.getKey(file)); final String mime = status.getMime(); if(StringUtils.isNotBlank(mime)) { object.setContentType(mime); } final Checksum checksum = status.getChecksum(); if(Checksum.NONE != checksum) { switch(checksum.algorithm) { case md5: // Set checksum on our own to avoid jets3t setting AWS metadata for MD5 as metadata must remain // constant for all chunks object.addMetadata("Content-MD5", ServiceUtils.toBase64(ServiceUtils.fromHex(checksum.hash))); break; } } return object; }
xmlMd5Hash = ServiceUtils.toBase64( ServiceUtils.computeMD5Hash(xml.getBytes(Constants.DEFAULT_ENCODING))); } catch (Exception e) {
xmlMd5Hash = ServiceUtils.toBase64( ServiceUtils.computeMD5Hash(xml.getBytes(Constants.DEFAULT_ENCODING))); } catch (Exception e) {