<commit_before>package org.codehaus.plexus.archiver.tar;

/**
 *
 * Copyright 2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.GZIPInputStream;

import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.bzip2.CBZip2InputStream;
import org.codehaus.plexus.archiver.zip.AbstractZipUnArchiver;
import org.codehaus.plexus.archiver.util.EnumeratedAttribute;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Revision$ $Date$
 */
public class TarUnArchiver extends AbstractZipUnArchiver
{
    /**
     *   compression method
     */
    private UntarCompressionMethod compression = new UntarCompressionMethod();

    /**
     * Set decompression algorithm to use; default=none.
     *
     * Allowable values are
     * <ul>
     *   <li>none - no compression
     *   <li>gzip - Gzip compression
     *   <li>bzip2 - Bzip2 compression
     * </ul>
     *
     * @param method compression method
     */
    public void setCompression(UntarCompressionMethod method)
    {
        compression = method;
    }

    /**
     * No encoding support in Untar.
     */
    public void setEncoding(String encoding)
    {
        getLogger().warn("The TarUnArchiver doesn't support the encoding attribute");
    }

    protected void execute() throws ArchiverException, IOException
    {
        TarInputStream tis = null;
        try
        {
            getLogger().info( "Expanding: " + getSourceFile() + " into " + getDestDirectory() );
            tis = new TarInputStream( compression.decompress( getSourceFile(),
                    new BufferedInputStream( new FileInputStream( getSourceFile() ) ) ) );
            TarEntry te = null;

            while ( ( te = tis.getNextEntry() ) != null )
            {
                extractFile( getSourceFile(), getDestDirectory(), tis, te.getName(), te.getModTime(), te.isDirectory());
            }
            getLogger().debug( "expand complete" );

        }
        catch ( IOException ioe )
        {
            throw new ArchiverException( "Error while expanding " + getSourceFile().getAbsolutePath(), ioe );
        }
        finally
        {
            if ( tis != null )
            {
                try
                {
                    tis.close();
                }
                catch (IOException e)
                {
                    // ignore
                }
            }
        }
    }

    /**
     * Valid Modes for Compression attribute to Untar Task
     *
     */
    public static final class UntarCompressionMethod
        extends EnumeratedAttribute
    {

        // permissible values for compression attribute
        /**
         *  No compression
         */
        private static final String NONE = "none";
        /**
         *  GZIP compression
         */
        private static final String GZIP = "gzip";
        /**
         *  BZIP2 compression
         */
        private static final String BZIP2 = "bzip2";


        /**
         *  Constructor
         */
        public UntarCompressionMethod()
        {
            super();
            try
            {
                setValue( NONE );
            }
            catch ( ArchiverException ae )
            {
                //Do nothing
            }
        }

        /**
         * Get valid enumeration values
         *
         * @return valid values
         */
        public String[] getValues()
        {
            return new String[] { NONE, GZIP, BZIP2 };
        }

        /**
         *  This method wraps the input stream with the
         *     corresponding decompression method
         *
         *  @param file provides location information for BuildException
         *  @param istream input stream
         *  @return input stream with on-the-fly decompression
         *  @exception IOException thrown by GZIPInputStream constructor
         *  @exception BuildException thrown if bzip stream does not
         *     start with expected magic values
         */
        private InputStream decompress( final File file, final InputStream istream )
            throws IOException, ArchiverException
        {<commit_msg>Add a new contructor for simplify user code.<commit_after>package org.codehaus.plexus.archiver.tar;

/**
 *
 * Copyright 2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.GZIPInputStream;

import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.bzip2.CBZip2InputStream;
import org.codehaus.plexus.archiver.zip.AbstractZipUnArchiver;
import org.codehaus.plexus.archiver.util.EnumeratedAttribute;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Revision$ $Date$
 */
public class TarUnArchiver extends AbstractZipUnArchiver
{
    /**
     *   compression method
     */
    private UntarCompressionMethod compression = new UntarCompressionMethod();

    /**
     * Set decompression algorithm to use; default=none.
     *
     * Allowable values are
     * <ul>
     *   <li>none - no compression
     *   <li>gzip - Gzip compression
     *   <li>bzip2 - Bzip2 compression
     * </ul>
     *
     * @param method compression method
     */
    public void setCompression(UntarCompressionMethod method)
    {
        compression = method;
    }

    /**
     * No encoding support in Untar.
     */
    public void setEncoding(String encoding)
    {
        getLogger().warn("The TarUnArchiver doesn't support the encoding attribute");
    }

    protected void execute() throws ArchiverException, IOException
    {
        TarInputStream tis = null;
        try
        {
            getLogger().info( "Expanding: " + getSourceFile() + " into " + getDestDirectory() );
            tis = new TarInputStream( compression.decompress( getSourceFile(),
                    new BufferedInputStream( new FileInputStream( getSourceFile() ) ) ) );
            TarEntry te = null;

            while ( ( te = tis.getNextEntry() ) != null )
            {
                extractFile( getSourceFile(), getDestDirectory(), tis, te.getName(), te.getModTime(), te.isDirectory());
            }
            getLogger().debug( "expand complete" );

        }
        catch ( IOException ioe )
        {
            throw new ArchiverException( "Error while expanding " + getSourceFile().getAbsolutePath(), ioe );
        }
        finally
        {
            if ( tis != null )
            {
                try
                {
                    tis.close();
                }
                catch (IOException e)
                {
                    // ignore
                }
            }
        }
    }

    /**
     * Valid Modes for Compression attribute to Untar Task
     *
     */
    public static final class UntarCompressionMethod
        extends EnumeratedAttribute
    {

        // permissible values for compression attribute
        /**
         *  No compression
         */
        private static final String NONE = "none";
        /**
         *  GZIP compression
         */
        private static final String GZIP = "gzip";
        /**
         *  BZIP2 compression
         */
        private static final String BZIP2 = "bzip2";


        /**
         *  Constructor
         */
        public UntarCompressionMethod()
        {
            super();
            try
            {
                setValue( NONE );
            }
            catch ( ArchiverException ae )
            {
                //Do nothing
            }
        }

        /**
         *  Constructor
         */
        public UntarCompressionMethod( String method )
        {
            super();
            try
            {
                setValue( method );
            }
            catch ( ArchiverException ae )
            {
                //Do nothing
            }
        }

        /**
         * Get valid enumeration values
         *
         * @return valid values
         */
        public String[] getValues()
        {
            return new String[] { NONE, GZIP, BZIP2 };
        }

        /**
         *  This method wraps the input stream with the
         *     corresponding decompression method
         *
         *  @param file provides location information for BuildException
         *  @param istream input stream
         *  @return input stream with on-the-fly decompression
         *  @exception IOException thrown by GZIPInputStream constructor
         *  @exception BuildException thrown if bzip stream does not
         *     start with expected magic values
         */
        private InputStream decompress( final File file, final InputStream istream )
            throws IOException, ArchiverException
        {
{'fraction_non_alphanumeric': 0.08627179080824089, 'fraction_numerical': 0.003169572107765452, 'mean_word_length': 1.7663013698630137, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '138431', 'n_tokens_mistral': 2632, 'n_tokens_neox': 2549, 'n_words': 749}