本文整理汇总了Java中org.apache.commons.compress.compressors.gzip.GzipUtils.isCompressedFilename方法的典型用法代码示例。如果您正苦于以下问题:Java GzipUtils.isCompressedFilename方法的具体用法?Java GzipUtils.isCompressedFilename怎么用?Java GzipUtils.isCompressedFilename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.compress.compressors.gzip.GzipUtils
的用法示例。
在下文中一共展示了GzipUtils.isCompressedFilename方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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");
}
示例3: 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;
}
}
示例4: 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();
}
}
示例5: 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;
}
}
示例6: 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);
}
}
示例7: 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));
}
}
}
示例8: 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);
}