protected void unpack()

in flex-maven-tools/flex-sdk-converter/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/BaseRetriever.java [37:128]


    protected void unpack(File inputArchive, File targetDirectory) throws RetrieverException {
        if (!targetDirectory.mkdirs()) {
            throw new RetrieverException(
                    "Unable to create extraction directory " + targetDirectory.getAbsolutePath());
        }

        ArchiveInputStream archiveInputStream = null;
        ArchiveEntry entry;
        FileInputStream fileInputStream = null;
        try {

            fileInputStream = new FileInputStream(inputArchive);
            final CountingInputStream inputStream = new CountingInputStream(fileInputStream);

            final long inputFileSize = inputArchive.length();

            if(inputArchive.getName().endsWith(".tbz2")) {
                archiveInputStream = new TarArchiveInputStream(
                        new BZip2CompressorInputStream(inputStream));
            } else {
                archiveInputStream = new ArchiveStreamFactory().createArchiveInputStream(
                        new BufferedInputStream(inputStream));
            }

            final ProgressBar progressBar = new ProgressBar(inputFileSize);
            while ((entry = archiveInputStream.getNextEntry()) != null) {
                final File outputFile = new File(targetDirectory, entry.getName());

                // Entry is a directory.
                if (entry.isDirectory()) {
                    if (!outputFile.exists()) {
                        if(!outputFile.mkdirs()) {
                            throw new RetrieverException(
                                    "Could not create output directory " + outputFile.getAbsolutePath());
                        }
                    }
                }

                // Entry is a file.
                else {
                    final byte[] data = new byte[BUFFER_MAX];
                    FileOutputStream fos = null;
                    try {
                        fos = new FileOutputStream(outputFile);

                        BufferedOutputStream dest = null;
                        try {
                            dest = new BufferedOutputStream(fos, BUFFER_MAX);

                            int count;
                            while ((count = archiveInputStream.read(data, 0, BUFFER_MAX)) != -1) {
                                dest.write(data, 0, count);
                                progressBar.updateProgress(inputStream.getBytesRead());
                            }
                        } finally {
                            if (dest != null) {
                                dest.flush();
                                dest.close();
                            }
                        }
                    } finally {
                        if(fos != null) {
                            fos.close();
                        }
                    }
                }

                progressBar.updateProgress(inputStream.getBytesRead());
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ArchiveException e) {
            e.printStackTrace();
        } finally {
            if(archiveInputStream != null) {
                try {
                    archiveInputStream.close();
                } catch(IOException e) {
                    // Ignore...
                }
            }
            if(fileInputStream != null) {
                try {
                    fileInputStream.close();
                } catch(IOException e) {
                    // Ignore...
                }
            }
        }
    }