Search in sources :

Example 1 with ObjectIds

use of com.orion.id.ObjectIds in project orion-kit by lijiahangmax.

the class GzDecompressor method doDecompress.

@Override
public void doDecompress() throws Exception {
    OutputStream out = null;
    try {
        if (decompressInputStream != null) {
            this.inputStream = new GzipCompressorInputStream(decompressInputStream);
        } else {
            this.inputStream = new GzipCompressorInputStream(Files1.openInputStreamFast(decompressFile));
        }
        String entityName = Optional.ofNullable(inputStream.getMetaData()).map(GzipParameters::getFilename).orElse(null);
        if (decompressTargetFileName == null) {
            // 配置 > entity > file > objectId
            this.decompressTargetFileName = Objects1.def(entityName, Optional.ofNullable(decompressFile).map(File::getName).map(s -> s.substring(0, s.length() - suffix.length() - 1)).orElseGet(ObjectIds::next));
        }
        if (decompressTargetOutputStream != null) {
            out = decompressTargetOutputStream;
        } else {
            this.decompressTargetFile = new File(decompressTargetPath, decompressTargetFileName);
            out = Files1.openOutputStream(decompressTargetFile);
        }
        Streams.transfer(inputStream, out);
    } finally {
        Streams.close(inputStream);
        if (decompressTargetOutputStream == null) {
            Streams.close(out);
        }
    }
}
Also used : GzipCompressorInputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream) OutputStream(java.io.OutputStream) BaseFileDecompressor(com.orion.utils.io.compress.BaseFileDecompressor) GzipParameters(org.apache.commons.compress.compressors.gzip.GzipParameters) Valid(com.orion.utils.Valid) ObjectIds(com.orion.id.ObjectIds) File(java.io.File) Files1(com.orion.utils.io.Files1) Const(com.orion.constant.Const) Streams(com.orion.utils.io.Streams) Objects1(com.orion.utils.Objects1) Optional(java.util.Optional) GzipCompressorInputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream) InputStream(java.io.InputStream) ObjectIds(com.orion.id.ObjectIds) OutputStream(java.io.OutputStream) File(java.io.File)

Aggregations

Const (com.orion.constant.Const)1 ObjectIds (com.orion.id.ObjectIds)1 Objects1 (com.orion.utils.Objects1)1 Valid (com.orion.utils.Valid)1 Files1 (com.orion.utils.io.Files1)1 Streams (com.orion.utils.io.Streams)1 BaseFileDecompressor (com.orion.utils.io.compress.BaseFileDecompressor)1 File (java.io.File)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Optional (java.util.Optional)1 GzipCompressorInputStream (org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream)1 GzipParameters (org.apache.commons.compress.compressors.gzip.GzipParameters)1