gzip
This commit is contained in:
parent
b654faa55b
commit
f39cbf08a9
|
@ -23,6 +23,7 @@ import eu.dnetlib.apps.oai.domain.OaiPage;
|
|||
import eu.dnetlib.apps.oai.domain.OaiRecord;
|
||||
import eu.dnetlib.apps.oai.domain.OaiSet;
|
||||
import eu.dnetlib.apps.oai.utils.DateUtils;
|
||||
import eu.dnetlib.apps.oai.utils.GzipUtils;
|
||||
import eu.dnetlib.apps.oai.utils.XsltTransformerFactory;
|
||||
|
||||
@Service
|
||||
|
@ -136,9 +137,11 @@ public class OaiService {
|
|||
private RowMapper<OaiRecord> rowMapper(final String metadataPrefix) {
|
||||
final Function<String, String> mapper = prepareXsltMapper(metadataPrefix);
|
||||
return (rs, rowNum) -> {
|
||||
final String xml = GzipUtils.decompress(rs.getBytes("body"));
|
||||
|
||||
final OaiRecord r = new OaiRecord();
|
||||
r.setId(rs.getString("id"));
|
||||
r.setBody(mapper != null ? mapper.apply(rs.getString("body")) : rs.getString("body"));
|
||||
r.setBody(mapper != null ? mapper.apply(xml) : xml);
|
||||
r.setDate(Instant.ofEpochMilli(rs.getLong("date"))
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.toLocalDateTime());
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package eu.dnetlib.apps.oai.utils;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class GzipUtils {
|
||||
|
||||
public static byte[] compress(final String data) {
|
||||
if (StringUtils.isBlank(data)) { return null; }
|
||||
|
||||
try (final ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length());
|
||||
final GZIPOutputStream gzip = new GZIPOutputStream(bos)) {
|
||||
gzip.write(data.getBytes());
|
||||
gzip.flush();
|
||||
return bos.toByteArray();
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException("error in gzip", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String decompress(final byte[] bytes) {
|
||||
if (bytes == null || bytes.length == 0) { return null; }
|
||||
try (final ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
|
||||
final GZIPInputStream gis = new GZIPInputStream(bis)) {
|
||||
return IOUtils.toString(gis, "UTF-8");
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException("error in gunzip", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
CREATE TABLE oai_data(
|
||||
id text PRIMARY KEY,
|
||||
body text,
|
||||
body bytea,
|
||||
date timestamp NOT NULL DEFAULT now(),
|
||||
sets text[] NOT NULL DEFAULT '{}'
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue