refactoring of GzipUtils

This commit is contained in:
Michele Artini 2024-05-08 11:28:25 +02:00
parent 0ee3f7d0a9
commit 910aeb22de
3 changed files with 222 additions and 211 deletions

View File

@ -1,13 +1,13 @@
package eu.dnetlib.apps.oai.utils; package eu.dnetlib.apps.oai.utils;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.nio.charset.Charset;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
public class GzipUtils { public class GzipUtils {
@ -15,36 +15,26 @@ public class GzipUtils {
public static byte[] compress(final String str) { public static byte[] compress(final String str) {
if (StringUtils.isBlank(str)) { return null; } if (StringUtils.isBlank(str)) { return null; }
try { try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
final ByteArrayOutputStream obj = new ByteArrayOutputStream(); try (final GZIPOutputStream gzip = new GZIPOutputStream(baos)) {
final GZIPOutputStream gzip = new GZIPOutputStream(obj); IOUtils.write(str.getBytes(Charset.defaultCharset()), gzip);
gzip.write(str.getBytes("UTF-8")); }
gzip.flush(); return baos.toByteArray();
gzip.close();
return obj.toByteArray();
} catch (final IOException e) { } catch (final IOException e) {
throw new RuntimeException("error in gzip", e); throw new RuntimeException("error in gzip", e);
} }
} }
public static String decompress(final byte[] compressed) { public static String decompress(final byte[] compressed) {
final StringBuilder outStr = new StringBuilder();
if (compressed == null || compressed.length == 0) { return null; } if (compressed == null || compressed.length == 0) { return null; }
try { if (isCompressed(compressed)) {
if (isCompressed(compressed)) { try (final GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(compressed))) {
final GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(compressed)); return IOUtils.toString(gis, Charset.defaultCharset());
final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(gis, "UTF-8")); } catch (final IOException e) {
throw new RuntimeException("error in gunzip", e);
String line;
while ((line = bufferedReader.readLine()) != null) {
outStr.append(line);
}
} else {
outStr.append(compressed);
} }
return outStr.toString(); } else {
} catch (final IOException e) { return new String(compressed);
throw new RuntimeException("error in gunzip", e);
} }
} }

View File

@ -5,6 +5,10 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.nio.charset.Charset;
import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -24,6 +28,18 @@ public class GzipUtilsTest {
assertEquals(message, GzipUtils.decompress(bytes)); assertEquals(message, GzipUtils.decompress(bytes));
} }
@Test
final void testCompressAndDecompress_2() throws IOException {
final String message = IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/apps/oai/record01.xml"), Charset.defaultCharset());
final byte[] bytes = GzipUtils.compress(message);
assertNotNull(bytes);
assertTrue(bytes.length > 0);
assertTrue(bytes.length <= message.getBytes().length);
assertEquals(message, GzipUtils.decompress(bytes));
}
@Test @Test
final void testCompressNull() { final void testCompressNull() {
assertNull(GzipUtils.compress(null)); assertNull(GzipUtils.compress(null));

View File

@ -1,188 +1,193 @@
<result xmlns="http://namespace.openaire.eu/oaf "
<oaf:entity xmlns:oaf="http://namespace.openaire.eu/oaf"
schemaLocation="http://namespace.openaire.eu/oaf https://www.openaire.eu/schema/1.0/oaf-1.0.xsd"> schemaLocation="http://namespace.openaire.eu/oaf https://www.openaire.eu/schema/1.0/oaf-1.0.xsd">
<collectedfrom <oaf:result>
name="Waterford Institute of Technology - Open Access Repository" <collectedfrom
id="opendoar____::50c1f44e426560f3f2cdcb3e19e39903" /> name="Waterford Institute of Technology - Open Access Repository"
<collectedfrom name="SETU Open Access Repository" id="opendoar____::50c1f44e426560f3f2cdcb3e19e39903" />
id="opendoar____::4daa3db355ef2b0e64b472968cb70f0d" /> <collectedfrom name="SETU Open Access Repository"
<originalId>50|od______6005::55a12e2e0fee45ce8005633c6c17fe9f id="opendoar____::4daa3db355ef2b0e64b472968cb70f0d" />
</originalId> <originalId>50|od______6005::55a12e2e0fee45ce8005633c6c17fe9f
<originalId>oai:repository.wit.ie:3029</originalId> </originalId>
<originalId>50|od_______934::e7162a5632264cd622ee7180ca66fdce <originalId>oai:repository.wit.ie:3029</originalId>
</originalId> <originalId>50|od_______934::e7162a5632264cd622ee7180ca66fdce
<originalId>oai:generic.eprints.org:3029</originalId> </originalId>
<originalId>50|od_______934::55a12e2e0fee45ce8005633c6c17fe9f <originalId>oai:generic.eprints.org:3029</originalId>
</originalId> <originalId>50|od_______934::55a12e2e0fee45ce8005633c6c17fe9f
<measure id="influence" score="3.1177596E-9" class="C5" /> </originalId>
<measure id="popularity" score="1.2305752E-9" class="C5" /> <measure id="influence" score="3.1177596E-9" class="C5" />
<measure id="influence_alt" score="0" class="C5" /> <measure id="popularity" score="1.2305752E-9" class="C5" />
<measure id="popularity_alt" score="0.0" class="C5" /> <measure id="influence_alt" score="0" class="C5" />
<measure id="impulse" score="0" class="C5" /> <measure id="popularity_alt" score="0.0" class="C5" />
<fulltext>http://repository.wit.ie/3029/1/Research%20Day%202015%20-%20Poster%20Tadhg%20Blommerde.pdf <measure id="impulse" score="0" class="C5" />
</fulltext> <fulltext>http://repository.wit.ie/3029/1/Research%20Day%202015%20-%20Poster%20Tadhg%20Blommerde.pdf
<title classid="main title" classname="main title" </fulltext>
schemeid="dnet:dataCite_title" schemename="dnet:dataCite_title" <title classid="main title" classname="main title"
inferred="false" provenanceaction="sysimport:crosswalk:repository" schemeid="dnet:dataCite_title" schemename="dnet:dataCite_title"
trust="0.9">A service innovation capability maturity model for SMEs</title> inferred="false" provenanceaction="sysimport:crosswalk:repository"
<bestaccessright classid="OPEN" classname="Open Access" trust="0.9">A service innovation capability maturity model for SMEs</title>
schemeid="dnet:access_modes" schemename="dnet:access_modes" /> <bestaccessright classid="OPEN"
<creator rank="1" name="Tadhg" surname="Blommerde">Blommerde, Tadhg classname="Open Access" schemeid="dnet:access_modes"
</creator> schemename="dnet:access_modes" />
<creator rank="2" name="Patrick" surname="Lynch">Lynch, Patrick <creator rank="1" name="Tadhg" surname="Blommerde">Blommerde, Tadhg
</creator> </creator>
<country classid="IE" classname="Ireland" <creator rank="2" name="Patrick" surname="Lynch">Lynch, Patrick
schemeid="dnet:countries" schemename="dnet:countries" /> </creator>
<dateofacceptance>2015-04-28</dateofacceptance> <country classid="IE" classname="Ireland"
<description>There is general consensus that service innovations are schemeid="dnet:countries" schemename="dnet:countries" />
prerequisite to sustained competitive advantage and are an essential <dateofacceptance>2015-04-28</dateofacceptance>
mechanism for responding to changes in customer needs and the <description>There is general consensus that service innovations are
operating environment of firms (Giannopoulou et al., 2011; Stryja et prerequisite to sustained competitive advantage and are an essential
al., 2013). Services have been described as ubiquitous in their role mechanism for responding to changes in customer needs and the
of generating economic growth and wellbeing and represent over 70% of operating environment of firms (Giannopoulou et al., 2011; Stryja et
employment and GDP in developed nations (Janssen et al., 2012; al., 2013). Services have been described as ubiquitous in their role
Mustak, 2014). As a consequence, service innovations must be a core of generating economic growth and wellbeing and represent over 70% of
ambition of all countries, regions, and firms wishing to remain employment and GDP in developed nations (Janssen et al., 2012;
competitive (van Ark et al., 2003). While acknowledging the Mustak, 2014). As a consequence, service innovations must be a core
importance of once-off innovations, more critical still is the ambition of all countries, regions, and firms wishing to remain
capability to repeatedly introduce and exploit service innovations competitive (van Ark et al., 2003). While acknowledging the
(Siguaw et al., 2006). This is generally referred to as service importance of once-off innovations, more critical still is the
innovation capability (SIC) and describes the repeatable routines and capability to repeatedly introduce and exploit service innovations
behaviours that organisations have in place to transform ideas and (Siguaw et al., 2006). This is generally referred to as service
knowledge into innovations (Basterretxea and Martínez, 2012). innovation capability (SIC) and describes the repeatable routines and
However, despite links between SIC and continuous, sustainable, and behaviours that organisations have in place to transform ideas and
consistent service innovations, there is evidence that many knowledge into innovations (Basterretxea and Martínez, 2012).
organisations struggle with its effective management (Adams et al., However, despite links between SIC and continuous, sustainable, and
2006; den Hertog et al., 2010). This is often attributed to the lack consistent service innovations, there is evidence that many
of formal guidance available and the absence of metrics to determine organisations struggle with its effective management (Adams et al.,
an organisations SIC performance (Hogan et al., 2011; Szczygielski, 2006; den Hertog et al., 2010). This is often attributed to the lack
2011). Maturity modelling research in this discipline remains at an of formal guidance available and the absence of metrics to determine
embryonic stage, thus far presenting only conceptual and opaque an organisations SIC performance (Hogan et al., 2011; Szczygielski,
discussions that fail to address the necessity for an assessment and 2011). Maturity modelling research in this discipline remains at an
strategic management framework (Gryszkiewicz et al., 2013; Hipp and embryonic stage, thus far presenting only conceptual and opaque
Grupp, 2005). Therefore, the purpose of this ongoing research project discussions that fail to address the necessity for an assessment and
is to evaluate the maturity of an organisations SIC to inform its strategic management framework (Gryszkiewicz et al., 2013; Hipp and
effective management and enhancement. To achieve this it Grupp, 2005). Therefore, the purpose of this ongoing research project
dimensionalises the concept into four constituent capabilities, is to evaluate the maturity of an organisations SIC to inform its
specifically, strategising, customer involvement, knowledge effective management and enhancement. To achieve this it
management, and networking (Blommerde and Lynch, 2014). The study dimensionalises the concept into four constituent capabilities,
then tracks the maturity of these capabilities as they progress specifically, strategising, customer involvement, knowledge
through eight evolutionary plateaus towards a fully developed or management, and networking (Blommerde and Lynch, 2014). The study
optimal state. This is accomplished through a capability maturity then tracks the maturity of these capabilities as they progress
model that enables organisations to rapidly diagnose key areas of through eight evolutionary plateaus towards a fully developed or
strength and weakness to systematically cultivate behaviours that optimal state. This is accomplished through a capability maturity
leverage their untapped innovative potential (Wendler, 2012; Essmann model that enables organisations to rapidly diagnose key areas of
and du Preez, 2010). As a result of the immense knowledge vacuum strength and weakness to systematically cultivate behaviours that
characteristic of this discipline, it is anticipated that this leverage their untapped innovative potential (Wendler, 2012; Essmann
ongoing research project will make a substantial contribution to both and du Preez, 2010). As a result of the immense knowledge vacuum
academic understanding and take strides towards filling the void in characteristic of this discipline, it is anticipated that this
practical support (Rapaccini et al., 2013). It expands the service ongoing research project will make a substantial contribution to both
innovation literature by detailing key service innovation levers, academic understanding and take strides towards filling the void in
bolsters the discipline through clear definitions of terminology, practical support (Rapaccini et al., 2013). It expands the service
provides a powerful explanation of the development of SICs, and innovation literature by detailing key service innovation levers,
operationalises the dynamic capabilities view through a novel bolsters the discipline through clear definitions of terminology,
self-assessment reference model (Jochem et al., 2011). The next step provides a powerful explanation of the development of SICs, and
in the project is the evaluation of the, as yet, conceptual service operationalises the dynamic capabilities view through a novel
innovation capability maturity model. Adopting a positivistic self-assessment reference model (Jochem et al., 2011). The next step
philosophical stance, the study proposes the use of structural in the project is the evaluation of the, as yet, conceptual service
equation modelling on data gathered through an extensive survey to innovation capability maturity model. Adopting a positivistic
confirm the model and support theoretical assumptions. philosophical stance, the study proposes the use of structural
</description> equation modelling on data gathered through an extensive survey to
<subject classid="keyword" classname="keyword" confirm the model and support theoretical assumptions.
schemeid="dnet:result_subject" schemename="dnet:result_subject" </description>
inferred="false" provenanceaction="sysimport:crosswalk:repository" <subject classid="keyword" classname="keyword"
trust="0.9">RIKON (Research in Inovation, Knowledge &amp; Organisational schemeid="dnet:result_subject" schemename="dnet:result_subject"
Networks) inferred="false" provenanceaction="sysimport:crosswalk:repository"
</subject> trust="0.9">RIKON (Research in Inovation, Knowledge &amp; Organisational
<language classid="eng" classname="English" Networks)
schemeid="dnet:languages" schemename="dnet:languages" /> </subject>
<format>application/pdf</format> <language classid="eng" classname="English"
<resulttype classid="publication" classname="publication" schemeid="dnet:languages" schemename="dnet:languages" />
schemeid="dnet:result_typologies" schemename="dnet:result_typologies" /> <format>application/pdf</format>
<resourcetype classid="UNKNOWN" classname="UNKNOWN" <resulttype classid="publication" classname="publication"
schemeid="dnet:dataCite_resource" schemename="dnet:dataCite_resource" /> schemeid="dnet:result_typologies" schemename="dnet:result_typologies" />
<isgreen>false</isgreen> <resourcetype classid="UNKNOWN" classname="UNKNOWN"
<isindiamondjournal>false</isindiamondjournal> schemeid="dnet:dataCite_resource" schemename="dnet:dataCite_resource" />
<publiclyfunded>true</publiclyfunded> <isgreen>false</isgreen>
<context id="eu-conexus" <isindiamondjournal>false</isindiamondjournal>
label="European University for Smart Urban Coastal Sustainability" <publiclyfunded>true</publiclyfunded>
type="community" /> <context id="eu-conexus"
<context id="tunet" label="TU-NET" type="community" /> label="European University for Smart Urban Coastal Sustainability"
<datainfo> type="community" />
<inferred>true</inferred> <context id="tunet" label="TU-NET" type="community" />
<deletedbyinference>false</deletedbyinference> <datainfo>
<trust>0.8</trust> <inferred>true</inferred>
<inferenceprovenance>dedup-result-decisiontree-v4 <deletedbyinference>false</deletedbyinference>
</inferenceprovenance> <trust>0.8</trust>
<provenanceaction classid="sysimport:dedup" <inferenceprovenance>dedup-result-decisiontree-v4
classname="Inferred by OpenAIRE" schemeid="dnet:provenanceActions" </inferenceprovenance>
schemename="dnet:provenanceActions" /> <provenanceaction classid="sysimport:dedup"
</datainfo> classname="Inferred by OpenAIRE" schemeid="dnet:provenanceActions"
<rels> schemename="dnet:provenanceActions" />
<rel inferred="true" trust="0.85" </datainfo>
inferenceprovenance="propagation" <rels>
provenanceaction="result:organization:instrepo"> <rel inferred="true" trust="0.85"
<to class="hasAuthorInstitution" inferenceprovenance="propagation"
scheme="dnet:result_organization_relations" type="organization">openorgs____::54cd984fc7d3b153ec2181f985041f02 provenanceaction="result:organization:instrepo">
</to> <to class="hasAuthorInstitution"
<country classid="IE" classname="Ireland" scheme="dnet:result_organization_relations" type="organization">openorgs____::54cd984fc7d3b153ec2181f985041f02
schemeid="dnet:countries" schemename="dnet:countries" /> </to>
<legalshortname>WIT</legalshortname> <country classid="IE" classname="Ireland"
<legalname>South East Technological University</legalname> schemeid="dnet:countries" schemename="dnet:countries" />
</rel> <legalshortname>WIT</legalshortname>
</rels> <legalname>South East Technological University</legalname>
<children> </rel>
<result </rels>
objidentifier="od_______934::e7162a5632264cd622ee7180ca66fdce"> <children>
<title classid="main title" classname="main title" <result
schemeid="dnet:dataCite_title" schemename="dnet:dataCite_title" objidentifier="od_______934::e7162a5632264cd622ee7180ca66fdce">
inferred="false" provenanceaction="sysimport:crosswalk:repository" <title classid="main title" classname="main title"
trust="0.9">A service innovation capability maturity model for SMEs schemeid="dnet:dataCite_title" schemename="dnet:dataCite_title"
</title> inferred="false" provenanceaction="sysimport:crosswalk:repository"
<dateofacceptance>2015-04-28</dateofacceptance> trust="0.9">A service innovation capability maturity model for SMEs
<collectedfrom name="SETU Open Access Repository" </title>
id="opendoar____::4daa3db355ef2b0e64b472968cb70f0d" /> <dateofacceptance>2015-04-28</dateofacceptance>
</result> <collectedfrom name="SETU Open Access Repository"
<result id="opendoar____::4daa3db355ef2b0e64b472968cb70f0d" />
objidentifier="od______6005::55a12e2e0fee45ce8005633c6c17fe9f"> </result>
<title classid="main title" classname="main title" <result
schemeid="dnet:dataCite_title" schemename="dnet:dataCite_title" objidentifier="od______6005::55a12e2e0fee45ce8005633c6c17fe9f">
inferred="false" provenanceaction="sysimport:crosswalk:repository" <title classid="main title" classname="main title"
trust="0.9">A service innovation capability maturity model for SMEs schemeid="dnet:dataCite_title" schemename="dnet:dataCite_title"
</title> inferred="false" provenanceaction="sysimport:crosswalk:repository"
<dateofacceptance>2015-04-28</dateofacceptance> trust="0.9">A service innovation capability maturity model for SMEs
<collectedfrom </title>
name="Waterford Institute of Technology - Open Access Repository" <dateofacceptance>2015-04-28</dateofacceptance>
id="opendoar____::50c1f44e426560f3f2cdcb3e19e39903" /> <collectedfrom
</result> name="Waterford Institute of Technology - Open Access Repository"
<result id="opendoar____::50c1f44e426560f3f2cdcb3e19e39903" />
objidentifier="od_______934::55a12e2e0fee45ce8005633c6c17fe9f"> </result>
<title classid="main title" classname="main title" <result
schemeid="dnet:dataCite_title" schemename="dnet:dataCite_title" objidentifier="od_______934::55a12e2e0fee45ce8005633c6c17fe9f">
inferred="false" provenanceaction="sysimport:crosswalk:repository" <title classid="main title" classname="main title"
trust="0.9">A service innovation capability maturity model for SMEs schemeid="dnet:dataCite_title" schemename="dnet:dataCite_title"
</title> inferred="false" provenanceaction="sysimport:crosswalk:repository"
<dateofacceptance>2015-04-28</dateofacceptance> trust="0.9">A service innovation capability maturity model for SMEs
<collectedfrom name="SETU Open Access Repository" </title>
id="opendoar____::4daa3db355ef2b0e64b472968cb70f0d" /> <dateofacceptance>2015-04-28</dateofacceptance>
</result> <collectedfrom name="SETU Open Access Repository"
<instance> id="opendoar____::4daa3db355ef2b0e64b472968cb70f0d" />
<accessright classid="OPEN" classname="Open Access" </result>
schemeid="dnet:access_modes" schemename="dnet:access_modes" /> <instance>
<collectedfrom name="SETU Open Access Repository" <accessright classid="OPEN" classname="Open Access"
id="opendoar____::4daa3db355ef2b0e64b472968cb70f0d" /> schemeid="dnet:access_modes" schemename="dnet:access_modes" />
<hostedby name="SETU Open Access Repository" <collectedfrom name="SETU Open Access Repository"
id="opendoar____::4daa3db355ef2b0e64b472968cb70f0d" /> id="opendoar____::4daa3db355ef2b0e64b472968cb70f0d" />
<dateofacceptance>2015-04-28</dateofacceptance> <hostedby name="SETU Open Access Repository"
<instancetype classid="0004" id="opendoar____::4daa3db355ef2b0e64b472968cb70f0d" />
classname="Conference object" schemeid="dnet:publication_resource" <dateofacceptance>2015-04-28</dateofacceptance>
schemename="dnet:publication_resource" /> <instancetype classid="0004"
<refereed classid="0002" classname="nonPeerReviewed" classname="Conference object" schemeid="dnet:publication_resource"
schemeid="dnet:review_levels" schemename="dnet:review_levels" /> schemename="dnet:publication_resource" />
<fulltext>http://repository.wit.ie/3029/1/Research%20Day%202015%20-%20Poster%20Tadhg%20Blommerde.pdf <refereed classid="0002" classname="nonPeerReviewed"
</fulltext> schemeid="dnet:review_levels" schemename="dnet:review_levels" />
<webresource> <fulltext>http://repository.wit.ie/3029/1/Research%20Day%202015%20-%20Poster%20Tadhg%20Blommerde.pdf
<url>http://repository.wit.ie/3029/</url> </fulltext>
</webresource> <webresource>
</instance> <url>http://repository.wit.ie/3029/</url>
</children> </webresource>
</result> </instance>
</children>
</oaf:result>
</oaf:entity>