Source:
public static byte[] buildUserMetadata(Map<String, Object> args) throws RestServiceException { ByteBuffer userMetadata; if (args.containsKey(MultipartPost.USER_METADATA_PART)) { userMetadata = (ByteBuffer) args.get(MultipartPost.USER_METADATA_PART); } else { Map<String, String> userMetadataMap = new HashMap<String, String>(); int sizeToAllocate = 0; for (Map.Entry<String, Object> entry : args.entrySet()) { String key = entry.getKey(); if (key.toLowerCase().startsWith(Headers.USER_META_DATA_HEADER_PREFIX)) { sizeToAllocate += 4; String keyToStore = key.substring(Headers.USER_META_DATA_HEADER_PREFIX.length()); sizeToAllocate += keyToStore.getBytes(StandardCharsets.UTF_8).length; String value = getHeader(args, key, true); userMetadataMap.put(keyToStore, value); sizeToAllocate += 4; sizeToAllocate += value.getBytes(StandardCharsets.UTF_8).length; } } if (sizeToAllocate == 0) { userMetadata = ByteBuffer.allocate(0); } else { sizeToAllocate += 2; sizeToAllocate += 4; sizeToAllocate += 4; sizeToAllocate += CRC_SIZE; userMetadata = ByteBuffer.allocate(sizeToAllocate); userMetadata.putShort(USER_METADATA_VERSION_V1); userMetadata.putInt(sizeToAllocate - 6 - CRC_SIZE); userMetadata.putInt(userMetadataMap.size()); for (Map.Entry<String, String> entry : userMetadataMap.entrySet()) { String key = entry.getKey(); Utils.serializeString(userMetadata, key, StandardCharsets.UTF_8); Utils.serializeString(userMetadata, entry.getValue(), StandardCharsets.UTF_8); } Crc32 crc = new Crc32(); crc.update(userMetadata.array(), 0, sizeToAllocate - CRC_SIZE); userMetadata.putLong(crc.getValue()); } } return userMetadata.array(); }

Target:
public static byte[] buildUserMetadata(Map<String, Object> args) throws RestServiceException { ByteBuffer userMetadata; if (args.containsKey(MultipartPost.USER_METADATA_PART)) { userMetadata = (ByteBuffer) args.get(MultipartPost.USER_METADATA_PART); } else { Map<String, String> userMetadataMap = new HashMap<String, String>(); int sizeToAllocate = 0; for (Map.Entry<String, Object> entry : args.entrySet()) { String key = entry.getKey(); if (key.toLowerCase().startsWith(Headers.USER_META_DATA_HEADER_PREFIX)) { sizeToAllocate += 4; String keyToStore = key.substring(Headers.USER_META_DATA_HEADER_PREFIX.length()); sizeToAllocate += keyToStore.getBytes(CHARSET).length; String value = getHeader(args, key, true); userMetadataMap.put(keyToStore, value); sizeToAllocate += 4; sizeToAllocate += value.getBytes(CHARSET).length; } } if (sizeToAllocate == 0) { userMetadata = ByteBuffer.allocate(0); } else { sizeToAllocate += 2; sizeToAllocate += 4; sizeToAllocate += 4; sizeToAllocate += CRC_SIZE; userMetadata = ByteBuffer.allocate(sizeToAllocate); userMetadata.putShort(USER_METADATA_VERSION_V1); userMetadata.putInt(sizeToAllocate - 6 - CRC_SIZE); userMetadata.putInt(userMetadataMap.size()); for (Map.Entry<String, String> entry : userMetadataMap.entrySet()) { String key = entry.getKey(); Utils.serializeString(userMetadata, key, CHARSET); Utils.serializeString(userMetadata, entry.getValue(), CHARSET); } Crc32 crc = new Crc32(); crc.update(userMetadata.array(), 0, sizeToAllocate - CRC_SIZE); userMetadata.putLong(crc.getValue()); } } return userMetadata.array(); }