当前位置: 首页>>代码示例>>Java>>正文


Java GzipUtils类代码示例

本文整理汇总了Java中org.apache.commons.compress.compressors.gzip.GzipUtils的典型用法代码示例。如果您正苦于以下问题:Java GzipUtils类的具体用法?Java GzipUtils怎么用?Java GzipUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


GzipUtils类属于org.apache.commons.compress.compressors.gzip包,在下文中一共展示了GzipUtils类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: compressFile

import org.apache.commons.compress.compressors.gzip.GzipUtils; //导入依赖的package包/类
/**
 * Compress a file
 * @param inFile
 * @param outFile
 * @throws FileNotFoundException
 * @throws IOException
 */
public static String compressFile(String inFile) throws FileNotFoundException, IOException {
    
    byte[] buffer = new byte[BUFFER_SIZE];
    
    String outFile = GzipUtils.getCompressedFilename(inFile);
    
    log.info("Compressing file: " + inFile + ", to file: " + outFile);
    
    try(GZIPOutputStream gzos = 
            new GZIPOutputStream(new FileOutputStream(outFile), Constants.GZIP_BUF_SIZE);
        FileInputStream in = new FileInputStream(inFile);) {
 
        int len;
        while ((len = in.read(buffer)) > 0) {
            gzos.write(buffer, 0, len);
        }
         
        gzos.finish();
    }
    
    return outFile;
}
 
开发者ID:omerio,项目名称:ecarf,代码行数:30,代码来源:Utils.java

示例2: getReader

import org.apache.commons.compress.compressors.gzip.GzipUtils; //导入依赖的package包/类
/**
 * Returns a reader for the given file.<br/>
 * In case of files with extensions: gz and zip the reader is
 * built upon {@link GZIPInputStream} and {@link ZipInputStream} respectively. <br/>
 * The reader gets/reads only first zip entry in case of zip files<br/>
 * The reader uses the UTF-8 encoding by default. It can be changed by {@link #setFileCharset(String)}.
 * 
 * @throws ImportException in case of any exception
 * 
 */
public Reader getReader(File file) throws ImportException {
    try {
        InputStream inputStream = new FileInputStream(file);
        if (GzipUtils.isCompressedFilename(file.getName())) {
            inputStream = new GZIPInputStream(inputStream);
        } else if (FilenameUtils.getExtension(file.getName()).equals("zip")) {
            inputStream = new ZipInputStream(inputStream);
            ((ZipInputStream)inputStream).getNextEntry();
            
        }
        
        return new InputStreamReader(inputStream, fileCharset);
        
    } catch (Exception e) {
        throw new ImportException(e);
    }
}
 
开发者ID:CeON,项目名称:saos,代码行数:28,代码来源:ImportFileUtils.java

示例3: gzipFile

import org.apache.commons.compress.compressors.gzip.GzipUtils; //导入依赖的package包/类
private static void gzipFile(File file) throws IOException {
    if (file == null) {
        return;
    }
    String name = GzipUtils.getCompressedFilename(file.getName());
    File dest = new File(file.getParentFile(), name);
    try (FileOutputStream os = new FileOutputStream(dest)) {
        // read the contents
        String contents = FileUtils.readFileToString(file, Charsets.UTF_8);
        try (OutputStream gzip = new GzipCompressorOutputStream(os)) {
            // write / compress
            IOUtils.write(contents, gzip, Charsets.UTF_8);
        }

    } finally {
        file.delete(); // delete the file
    }
}
 
开发者ID:killjoy1221,项目名称:TabbyChat-2,代码行数:19,代码来源:ChatLogging.java

示例4: unCompressFile

import org.apache.commons.compress.compressors.gzip.GzipUtils; //导入依赖的package包/类
/**
 * (Gzip) Uncompress a compressed file
 * @param filename
 * @return
 * @throws IOException
 */
public static String unCompressFile(String filename) throws IOException {
    
    
    byte[] buffer = new byte[BUFFER_SIZE];
    String outFile = GzipUtils.getUncompressedFilename(filename);
    
    log.info("Uncompressing file: " + filename + ", to file: " + outFile);
    
    try(GZIPInputStream gzis = 
            new GZIPInputStream(new FileInputStream(filename), Constants.GZIP_BUF_SIZE);
            BufferedOutputStream out = 
                    new BufferedOutputStream(new FileOutputStream(outFile), Constants.GZIP_BUF_SIZE);) {

        int len;
        while ((len = gzis.read(buffer)) > 0) {
            out.write(buffer, 0, len);
        }

    }
    /*
    FileInputStream fin = new FileInputStream(filename);
    BufferedInputStream in = new BufferedInputStream(fin);
    
    try(FileOutputStream out = new FileOutputStream(outFile);
            GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in)) {
        final byte[] buffer = new byte[BUFFER];
        int n = 0;
        while (-1 != (n = gzIn.read(buffer))) {
            out.write(buffer, 0, n);
        }
    }*/
    return outFile;
}
 
开发者ID:omerio,项目名称:ecarf,代码行数:40,代码来源:Utils.java

示例5: run

import org.apache.commons.compress.compressors.gzip.GzipUtils; //导入依赖的package包/类
@Override
public void run() throws IOException {
	
	log.info("Processing schema terms");
	
	//String schemaFile = metadata.getValue(EcarfMetaData.ECARF_SCHEMA);
	//String bucket = metadata.getBucket();
	// check if we have a source bucket for backward compatibility
	if(StringUtils.isBlank(sourceBucket)) {
	    log.warn("sourceBucket is empty, using bucket: " + bucket);
	    this.sourceBucket = bucket;
	}
	
	String localSchemaFile = Utils.TEMP_FOLDER + schemaFile;
	// download the file from the cloud storage
	this.getCloudService().downloadObjectFromCloudStorage(schemaFile, localSchemaFile, sourceBucket);
	
	// uncompress if compressed
	if(GzipUtils.isCompressedFilename(schemaFile)) {
		localSchemaFile = GzipUtils.getUncompressedFilename(localSchemaFile);
	}
	
	Set<String> terms = TermUtils.getRelevantSchemaTerms(localSchemaFile, TermUtils.RDFS_TBOX);
	
	log.info("Total relevant schema terms: " + terms.size());
	
	String schemaTermsFile = Utils.TEMP_FOLDER + Constants.SCHEMA_TERMS_JSON;
	
	// save to file
	FileUtils.objectToJsonFile(schemaTermsFile, terms);
	
	// upload the file to cloud storage
	this.getCloudService().uploadFileToCloudStorage(schemaTermsFile, bucket);
	
	// add value to the output
	this.addOutput("schemaTermsFile", Constants.SCHEMA_TERMS_JSON);
	
	log.info("Successfully processed schema terms");
}
 
开发者ID:omerio,项目名称:ecarf,代码行数:40,代码来源:CountSchemaTermTask.java

示例6: detectCompression

import org.apache.commons.compress.compressors.gzip.GzipUtils; //导入依赖的package包/类
/**
 * Detect the compression format from the filename, or null in case auto-detection failed.
 * @param file
 * @return
 */
private String detectCompression(File file) {
    if(BZip2Utils.isCompressedFilename(file.getName())) {
        return CompressorStreamFactory.BZIP2;
    } else if(GzipUtils.isCompressedFilename(file.getName())) {
        return CompressorStreamFactory.GZIP;
    } else if(XZUtils.isCompressedFilename(file.getName())) {
        return CompressorStreamFactory.XZ;
    } else {
        return null;
    }
}
 
开发者ID:apache,项目名称:marmotta,代码行数:17,代码来源:MarmottaLoader.java

示例7: uncompressedName

import org.apache.commons.compress.compressors.gzip.GzipUtils; //导入依赖的package包/类
private String uncompressedName(File file) {
    if(BZip2Utils.isCompressedFilename(file.getAbsolutePath())) {
        return BZip2Utils.getUncompressedFilename(file.getName());
    } else if(GzipUtils.isCompressedFilename(file.getAbsolutePath())) {
        return GzipUtils.getUncompressedFilename(file.getName());
    } else if(XZUtils.isCompressedFilename(file.getAbsolutePath())) {
        return XZUtils.getUncompressedFilename(file.getName());
    } else {
        return file.getName();
    }
}
 
开发者ID:apache,项目名称:marmotta,代码行数:12,代码来源:MarmottaLoader.java

示例8: openStream

import org.apache.commons.compress.compressors.gzip.GzipUtils; //导入依赖的package包/类
private InputStream openStream(Path file) throws IOException {
    final String fName = file.getFileName().toString();
    final FileInputStream fis = new FileInputStream(file.toFile());
    
    if (GzipUtils.isCompressedFilename(fName)) {
        log.trace("{} looks GZIP compressed,", file);
        return new GZIPInputStream(fis);
    } else if (BZip2Utils.isCompressedFilename(fName)) {
        log.trace("{} looks BZ2 compressed", file);
        return new BZip2CompressorInputStream(fis);
    } else {
        return fis;
    }
}
 
开发者ID:apache,项目名称:marmotta,代码行数:15,代码来源:ImportWatchServiceImpl.java

示例9: fileExists

import org.apache.commons.compress.compressors.gzip.GzipUtils; //导入依赖的package包/类
private static boolean fileExists(File file) {
    if (!file.exists()) {
        String gzip = GzipUtils.getCompressedFilename(file.getName());
        file = new File(file.getParentFile(), gzip);
    }
    return file.exists();
}
 
开发者ID:killjoy1221,项目名称:TabbyChat-2,代码行数:8,代码来源:ChatLogging.java

示例10: initializeFileValues

import org.apache.commons.compress.compressors.gzip.GzipUtils; //导入依赖的package包/类
public void initializeFileValues(FileDescriptor src) {
  	this.ufile = new FileDescriptor();
  	
if (StringUtil.isNotEmpty(this.nameHint)) 
	this.ufile.setPath("/" +  this.nameHint);
else if (src.hasPath()) 
	this.ufile.setPath("/" +  GzipUtils.getUncompressedFilename(src.path().getFileName()));
else
	this.ufile.setPath("/" + FileUtil.randomFilename("bin"));    	

this.ufile.setModTime(src.getModTime());
this.ufile.setPermissions(src.getPermissions());
  }
 
开发者ID:Gadreel,项目名称:divconq,代码行数:14,代码来源:UngzipStream.java

示例11: BinaryReader

import org.apache.commons.compress.compressors.gzip.GzipUtils; //导入依赖的package包/类
protected BinaryReader(@NonNull File file) {
    try {
        stream = new DataInputStream(new BufferedInputStream(GzipUtils.isCompressedFilename(file.getName())
                        ? new GZIPInputStream(new FileInputStream(file)) : new FileInputStream(file)));

        numWords = Integer.parseInt(readString(stream));
        vectorLength = Integer.parseInt(readString(stream));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:12,代码来源:WordVectorSerializer.java

示例12: setup

import org.apache.commons.compress.compressors.gzip.GzipUtils; //导入依赖的package包/类
/**
 * Carryout the setup of the schema terms
 * @param cloud
 * @throws IOException
 */
private void setup(GoogleCloudService cloud) throws IOException {
    
    Set<String> termsSet;
       
       if(terms == null) {
           // too large, probably saved as a file

           log.info("Using json file for terms: " + termsFile);
           Validate.notNull(termsFile);
           
           String localTermsFile = Utils.TEMP_FOLDER + termsFile;
           cloud.downloadObjectFromCloudStorage(termsFile, localTermsFile, bucket);

           // convert from JSON
           termsSet = io.cloudex.framework.utils.FileUtils.jsonFileToSet(localTermsFile);
           
       } else {
           termsSet = ObjectUtils.csvToSet(terms);
       }
       
       String localSchemaFile = Utils.TEMP_FOLDER + schemaFile;
       // download the file from the cloud storage
       cloud.downloadObjectFromCloudStorage(schemaFile, localSchemaFile, bucket);

       // uncompress if compressed
       if(GzipUtils.isCompressedFilename(schemaFile)) {
           localSchemaFile = GzipUtils.getUncompressedFilename(localSchemaFile);
       }

       Map<Long, Set<Triple>> allSchemaTriples = 
               TripleUtils.getRelevantSchemaETriples(localSchemaFile, TermUtils.RDFS_TBOX);

       // get all the triples we care about
       schemaTerms = new HashMap<>();

       for(String termStr: termsSet) {
           
           Long term = Long.parseLong(termStr);
           
           if(allSchemaTriples.containsKey(term)) {
               schemaTerms.put(term, allSchemaTriples.get(term));
           }
       }
    
}
 
开发者ID:omerio,项目名称:ecarf,代码行数:51,代码来源:DoReasonTask9.java

示例13: isCompressed

import org.apache.commons.compress.compressors.gzip.GzipUtils; //导入依赖的package包/类
public static boolean isCompressed (String name) {
	return GzipUtils.isCompressedFilename(name) || BZip2Utils.isCompressedFilename(name) || XZUtils.isCompressedFilename(name);
}
 
开发者ID:alexyz,项目名称:logsearch,代码行数:4,代码来源:LogSearchUtil.java


注:本文中的org.apache.commons.compress.compressors.gzip.GzipUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。