Compression Types
Built-In Types
ODS allows for many different compression formats to be used. All versions of ODS have 3 built-in options for compression:
- No Compression
- GZIP Compression
- ZLIB Compression
You can pick the compression format that you want to use in the ObjectDataStructure
constructor.
- Java
- C#
ObjectDataStructure ods = new ObjectDataStructure(new File("test.ods"), new GZIPCompression());
ObjectDataStructure ods = new ObjectDataStructure(new FileInfo("test.ods"), new GZIPCompression());
Additional Compression Types
Addons are available for specific versions. The Java version has ODSCompressionPlus, which provides additional compression types.
Custom Compression Types
ODS allows for custom compression types to be used. This is achieved by implementing the Compressor
interface and returning the input streams.
- Java
- C#
import me.ryandw11.ods.compression.Compressor;
public class CustomCompression implements Compressor {
@Override
public InputStream getInputStream(InputStream file) throws IOException {
// Return your compression input stream.
return new GZIPInputStream(file);
}
@Override
public OutputStream getOutputStream(OutputStream file) throws IOException {
// Return your compression output stream.
return new GZIPOutputStream(file);
}
}
using ODS.Compression;
namespace Custom.Compression
{
public class CustomCompression : ICompressor
{
public Stream GetCompressStream(Stream stream)
{
// Return your compression input stream.
return new GZipStream(stream, CompressionMode.Compress, true);
}
public Stream GetDecompressStream(Stream stream)
{
// Return your compression output stream.
return new GZipStream(stream, CompressionMode.Decompress, true);
}
}
}
You can then use your compression format as you would with any of the built-in ones.