/** * Encode the metadata into a string according to the specification, so it can be * used as the value for the Upload-Metadata header. * * @return Encoded metadata */ public String getEncodedMetadata() { if(metadata == null || metadata.size() == 0) { return ""; } String encoded = ""; boolean firstElement = true; for(Map.Entry<String, String> entry : metadata.entrySet()) { if(!firstElement) { encoded += ","; } encoded += entry.getKey() + " " + base64Encode(entry.getValue().getBytes()); firstElement = false; } return encoded; }
assertEquals( upload.getEncodedMetadata(), "foo aGVsbG8=,bar d29ybGQ=,filename " + TusUpload.base64Encode(file.getName().getBytes()));