com.ionoscloud.s3.messages.Metadata Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ionos-cloud-sdk-s3 Show documentation
Show all versions of ionos-cloud-sdk-s3 Show documentation
IONOS Java SDK for Amazon S3 Compatible Cloud Storage
The newest version!
package com.ionoscloud.s3.messages;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.simpleframework.xml.Root;
import org.simpleframework.xml.convert.Convert;
import org.simpleframework.xml.convert.Converter;
import org.simpleframework.xml.stream.InputNode;
import org.simpleframework.xml.stream.OutputNode;
/** XML friendly map denotes metadata. */
@Root(name = "Metadata")
@Convert(Metadata.MetadataConverter.class)
public class Metadata {
Map map;
public Metadata() {}
public Metadata(Map map) {
this.map = Collections.unmodifiableMap(map);
}
public Map get() {
return map;
}
/** XML converter class. */
public static class MetadataConverter implements Converter {
@Override
public Metadata read(InputNode node) throws Exception {
Map map = new HashMap<>();
while (true) {
InputNode childNode = node.getNext();
if (childNode == null) {
break;
}
map.put(childNode.getName(), childNode.getValue());
}
if (map.size() > 0) {
return new Metadata(map);
}
return null;
}
@Override
public void write(OutputNode node, Metadata metadata) throws Exception {
for (Map.Entry entry : metadata.get().entrySet()) {
OutputNode childNode = node.getChild(entry.getKey());
childNode.setValue(entry.getValue());
}
node.commit();
}
}
}