38 lines
888 B
Java
38 lines
888 B
Java
package org.gcube.phd;
|
|
|
|
import java.io.StringWriter;
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import org.gcube.common.resources.gcore.Resource;
|
|
import org.gcube.common.resources.gcore.Resources;
|
|
|
|
public class ResourceInfo<R extends Resource> {
|
|
|
|
private R r;
|
|
private String unmarshalledResource;
|
|
private Integer size;
|
|
|
|
public ResourceInfo(R r) {
|
|
this.r = r;
|
|
}
|
|
|
|
protected String getUnmarshalledResource() {
|
|
if(unmarshalledResource==null) {
|
|
StringWriter stringWriter = new StringWriter();
|
|
Resources.marshal(r, stringWriter);
|
|
unmarshalledResource = stringWriter.toString();
|
|
}
|
|
return unmarshalledResource;
|
|
}
|
|
|
|
public int getSize() throws UnsupportedEncodingException {
|
|
if(size==null) {
|
|
String unmarshalledR = getUnmarshalledResource();
|
|
final byte[] grUTF8Bytes = unmarshalledR.getBytes("UTF-8");
|
|
size = grUTF8Bytes.length;
|
|
}
|
|
return size;
|
|
}
|
|
|
|
}
|