Example usage for org.apache.commons.compress.compressors.bzip2 BZip2Utils getUncompressedFilename

List of usage examples for org.apache.commons.compress.compressors.bzip2 BZip2Utils getUncompressedFilename

Introduction

In this page you can find the example usage for org.apache.commons.compress.compressors.bzip2 BZip2Utils getUncompressedFilename.

Prototype

public static String getUncompressedFilename(String filename) 

Source Link

Document

Maps the given name of a bzip2-compressed file to the name that the file should have after uncompression.

Usage

From source file:net.sf.util.zip.FileNameUtil.java

/**
 *
 * @param fileName  the file name/*w  ww . j av  a  2s .co  m*/
 * @return   Compressed file type, as defined in CompressorStreamFactory
 */
public static String[] getCompressFileType(String fileName) {
    String s = fileName.toLowerCase();
    String[] ret = { null, null };
    if (GzipUtils.isCompressedFilename(s)) {
        ret[0] = CompressorStreamFactory.GZIP;
        ret[1] = GzipUtils.getUncompressedFilename(fileName);
    } else if (BZip2Utils.isCompressedFilename(s)) {
        ret[0] = CompressorStreamFactory.BZIP2;
        ret[1] = BZip2Utils.getUncompressedFilename(fileName);
    } else if (XZUtils.isCompressedFilename(s)) {
        ret[0] = CompressorStreamFactory.XZ;
        ret[1] = XZUtils.getUncompressedFilename(fileName);
    }

    return ret;
}

From source file:net.yacy.document.parser.bzipParser.java

@Override
public Document[] parse(final DigestURL location, final String mimeType, final String charset,
        final VocabularyScraper scraper, final int timezoneOffset, final InputStream source)
        throws Parser.Failure, InterruptedException {

    File tempFile = null;//from   w  ww  . j  a  v  a 2s .  com
    Document maindoc = null;
    try {
        int read = 0;
        final byte[] data = new byte[1024];
        // BZip2CompressorInputStream checks filecontent (magic start-bytes "BZh") and throws ioexception if no match
        final BZip2CompressorInputStream zippedContent = new BZip2CompressorInputStream(source);

        tempFile = File.createTempFile("bunzip", "tmp");

        // creating a temp file to store the uncompressed data
        final FileOutputStream out = new FileOutputStream(tempFile);

        // reading bzip file and store it uncompressed
        while ((read = zippedContent.read(data, 0, 1024)) != -1) {
            out.write(data, 0, read);
        }
        zippedContent.close();
        out.close();
        final String filename = location.getFileName();
        // create maindoc for this bzip container, register with supplied url & mime
        maindoc = new Document(location, mimeType, charset, this, null, null,
                AbstractParser.singleList(
                        filename.isEmpty() ? location.toTokens() : MultiProtocolURL.unescape(filename)), // title
                null, null, null, null, 0.0d, 0.0d, (Object) null, null, null, null, false, new Date());
        // creating a new parser class to parse the unzipped content
        final String contentfilename = BZip2Utils.getUncompressedFilename(location.getFileName());
        final String mime = TextParser.mimeOf(DigestURL.getFileExtension(contentfilename));
        final Document[] docs = TextParser.parseSource(location, mime, null, scraper, timezoneOffset, 999,
                tempFile);
        if (docs != null)
            maindoc.addSubDocuments(docs);
    } catch (final Exception e) {
        if (e instanceof InterruptedException)
            throw (InterruptedException) e;
        if (e instanceof Parser.Failure)
            throw (Parser.Failure) e;

        throw new Parser.Failure("Unexpected error while parsing bzip file. " + e.getMessage(), location);
    } finally {
        if (tempFile != null)
            FileUtils.deletedelete(tempFile);
    }
    return maindoc == null ? null : new Document[] { maindoc };
}

From source file:org.apache.marmotta.loader.core.MarmottaLoader.java

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 {// w  w  w.j  a v a  2s  . c  o m
        return file.getName();
    }
}

From source file:org.kyupi.misc.FileTools.java

/**
 * guesses a file type from the extension.
 * //from   w  w w  .j ava 2  s .  c om
 * @param f
 * @return The FILE_TYPE constant corresponding to the recognized
 *         type, or 0 if type is unknown.
 */
public static int fileType(File f) {
    String n = f.getName();
    if (BZip2Utils.isCompressedFilename(n))
        n = BZip2Utils.getUncompressedFilename(n);
    if (GzipUtils.isCompressedFilename(n))
        n = GzipUtils.getUncompressedFilename(n);
    if (n.endsWith(".isc"))
        return FileTools.FILE_TYPE_ISCAS;
    if (n.endsWith(".bench"))
        return FileTools.FILE_TYPE_BENCH;
    if (n.endsWith(".vhdl"))
        return FileTools.FILE_TYPE_VHDL;
    if (n.endsWith(".vhd"))
        return FileTools.FILE_TYPE_VHDL;
    if (n.endsWith(".kdb"))
        return FileTools.FILE_TYPE_KDB;
    if (n.endsWith(".dot"))
        return FileTools.FILE_TYPE_DOT;
    if (n.endsWith(".v"))
        return FileTools.FILE_TYPE_VERILOG;
    if (n.endsWith(".vg"))
        return FileTools.FILE_TYPE_VERILOG;
    return FileTools.FILE_TYPE_UNKNOWN;
}