Copyright (c) 2013 Lorenz Lehmann
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Sof...
If you think the Android project sodf listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package lal.sodf.framework.compressor;
/*www.java2s.com*/import lal.sodf.framework.exceptions.CompressionAlgorithmNotFoundException;
/**
* Compresses or decompresses a SODF ontology given as string
* @author Lorenz Lehmann
*
*/publicclass Compressor {
/**
* Compress an ontology with a given algorithm
* @param ontology The ontology in string representaion, which will be compressed
* @param algorithm The algorithm as string, which will be used for the compression
* @return A compressed version of the string
* @throws CompressionAlgorithmNotFoundException
*/publicbyte[] compress(String ontology, String algorithm) throws CompressionAlgorithmNotFoundException{
return compress(ontology, Compressor.alogrithmSelector(algorithm));
}
/**
* Compress an ontology with a given algorithm
* @param ontology The ontology in string representaion, which will be compressed
* @param algorithm The algorithm as string, which will be used for the compression
* @return A compressed version of the string
*/publicbyte[] compress(String ontology, CompressionAlgorithm algorithm){
if (algorithm == null) return null;
//let the algorithm do the work
return algorithm.compress(ontology);
}
/**
* Decompress an ontology with a given algorithm
* @param ontology The ontology in string representaion, which will be decompressed
* @param algorithm The algorithm as string, which will be used for the decompression
* @return A decompressed version of the string
* @throws CompressionAlgorithmNotFoundException
*/public String decompress(byte[] ontology, String algorithm) throws CompressionAlgorithmNotFoundException{
return decompress(ontology, Compressor.alogrithmSelector(algorithm));
}
/**
* Decompress an ontology with a given algorithm
* @param ontology The ontology in string representaion, which will be decompressed
* @param algorithm The algorithm as string, which will be used for the decompression
* @return A decompressed version of the string
*/public String decompress(byte[] ontology, CompressionAlgorithm algorithm){
if (algorithm == null) return null;
//let the algorithm do the work
return algorithm.decompress(ontology);
}
/** Select the correct algorithm based on the provided string */publicstatic CompressionAlgorithm alogrithmSelector(String algorithm) throws CompressionAlgorithmNotFoundException{
String val = algorithm.toLowerCase();
if (val.equals("gzip")) returnnew Gzip();
elsethrownew CompressionAlgorithmNotFoundException();
}
}