34 lines
1.0 KiB
Java
34 lines
1.0 KiB
Java
package eu.dnetlib.scholix.api.index;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import eu.dnetlib.dhp.schema.sx.scholix.Scholix;
|
|
import eu.dnetlib.dhp.schema.sx.scholix.ScholixFlat;
|
|
import org.apache.commons.codec.binary.Base64InputStream;
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
import java.nio.charset.Charset;
|
|
import java.util.zip.GZIPInputStream;
|
|
|
|
public class ScholixUtils {
|
|
|
|
private static ObjectMapper MAPPER = new ObjectMapper();
|
|
|
|
private static String uncompress(final String compressed) throws Exception {
|
|
Base64InputStream bis = new Base64InputStream(new ByteArrayInputStream(compressed.getBytes()));
|
|
GZIPInputStream gzip = new GZIPInputStream(bis);
|
|
return IOUtils.toString(gzip, Charset.defaultCharset());
|
|
}
|
|
|
|
public static Scholix getScholixFromBlob(final ScholixFlat flat) {
|
|
try {
|
|
return MAPPER.readValue(uncompress(flat.getBlob()), Scholix.class);
|
|
} catch (Throwable e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|