Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
private void exportLearningUnitView (File selectedFile) {
    if (learningUnitViewElementsManager.isOriginalElementsOnly ()) {
        String [] elementIds = learningUnitViewElementsManager.getAllLearningUnitViewElementIds ();
        for (int i = 0;
        i < elementIds.length; i ++) {
            FSLLearningUnitViewElement element = learningUnitViewElementsManager.getLearningUnitViewElement (elementIds [i], false);
            if (element.getLastModificationDate () == null) {
                element.setLastModificationDate (String.valueOf (new Date ().getTime ()));
                element.setModified (true);
            }
        }
        learningUnitViewElementsManager.setModified (true);
        learningUnitViewManager.saveLearningUnitViewData ();
        if (selectedFile != null) {
            try {
                File outputFile = selectedFile;
                String fileName = outputFile.getName ();
                StringBuffer extension = new StringBuffer ();
                if (fileName.length () >= 5) {
                    for (int i = 5;
                    i > 0; i --) {
                        extension.append (fileName.charAt (fileName.length () - i));
                    }
                }
                if (! extension.toString ().equals (".fslv")) {
                    outputFile.renameTo (new File (outputFile.getAbsolutePath () + ".fslv"));
                    outputFile = new File (outputFile.getAbsolutePath () + ".fslv");
                }
                File files [] = selectedFile.getParentFile ().listFiles ();
                int returnValue = FLGOptionPane.OK_OPTION;
                for (int i = 0;
                i < files.length; i ++) {
                    if (outputFile.getAbsolutePath ().equals (files [i].getAbsolutePath ())) {
                        returnValue = FLGOptionPane.showConfirmDialog (internationalization.getString ("dialog.exportLearningUnitView.fileExits.message"), internationalization.getString ("dialog.exportLearningUnitView.fileExits.title"), FLGOptionPane.OK_CANCEL_OPTION, FLGOptionPane.QUESTION_MESSAGE);
                        break;
                    }
                }
                if (returnValue == FLGOptionPane.OK_OPTION) {
                    FileOutputStream os = new FileOutputStream (outputFile);
                    ZipOutputStream zipOutputStream = new ZipOutputStream (os);
                    ZipEntry zipEntry = new ZipEntry ("dummy");
                    zipOutputStream.putNextEntry (zipEntry);
                    zipOutputStream.closeEntry ();
                    zipOutputStream.flush ();
                    zipOutputStream.finish ();
                    zipOutputStream.close ();
                    final File outFile = outputFile;
                    (new Thread () {
                        public void run () {
                            try {
                                ZipOutputStream zipOutputStream = new ZipOutputStream (new FileOutputStream (outFile));
                                File [] files = (new File (learningUnitViewManager.getLearningUnitViewOriginalDataDirectory ().getPath ())).listFiles ();
                                int maxSteps = files.length;
                                int step = 1;
                                exportProgressDialog = new FLGImageProgressDialog (null, 0, maxSteps, 0, getClass ().getClassLoader ().getResource ("freestyleLearning/homeCore/images/fsl.gif"), (Color) UIManager.get ("FSLColorBlue"), (Color) UIManager.get ("FSLColorRed"), internationalization.getString ("learningUnitViewExport.rogressbarText"));
                                exportProgressDialog.setCursor (new Cursor (Cursor.WAIT_CURSOR));
                                exportProgressDialog.setBarValue (step);
                                buildExportZipFile ("", zipOutputStream, files, step);
                                zipOutputStream.flush ();
                                zipOutputStream.finish ();
                                zipOutputStream.close ();
                                exportProgressDialog.setBarValue (maxSteps);
                                exportProgressDialog.setCursor (new Cursor (Cursor.DEFAULT_CURSOR));
                                exportProgressDialog.dispose ();
                            } catch (Exception e) {
                                e.printStackTrace ();
                            }
                        }}

                    ).start ();
                    os.close ();
                }
            } catch (Exception exp) {
                exp.printStackTrace ();
            }
        }
    } else {
    }
}

Function 2:
private void performFileStream (StreamService streamService, final StreamSession session, SubMonitor subMonitor, int numberOfFilesToSend) throws SarosCancellationException {
    OutputStream output = session.getOutputStream (0);
    ZipOutputStream zout = new ZipOutputStream (output);
    int worked = 0;
    int lastWorked = 0;
    int filesSent = 0;
    double increment = 0.0;
    if (numberOfFilesToSend >= 1) {
        increment = (double) 100 / numberOfFilesToSend;
        subMonitor.beginTask ("Streaming files...", 100);
    } else {
        subMonitor.worked (100);
    }
    try {
        for (String projectID : this.projectFilesToSend.keySet ()) {
            List < IPath > toSend = this.projectFilesToSend.get (projectID);
            zout = new ZipOutputStream (output);
            for (IPath path : toSend) {
                IFile file = sarosSession.getProject (projectID).getFile (path);
                String absPath = file.getLocation ().toPortableString ();
                byte [] buffer = new byte [streamService.getChunkSize () [0]];
                InputStream input = new FileInputStream (absPath);
                ZipEntry ze = new ZipEntry (path.toPortableString ());
                ze.setExtra (projectID.getBytes ());
                zout.putNextEntry (ze);
                int numRead = 0;
                while ((numRead = input.read (buffer)) > 0) {
                    zout.write (buffer, 0, numRead);
                }
                input.close ();
                zout.flush ();
                zout.closeEntry ();
                worked = (int) Math.round (increment * filesSent);
                if ((worked - lastWorked) > 0) {
                    subMonitor.worked ((worked - lastWorked));
                    lastWorked = worked;
                }
                filesSent ++;
                checkCancellation (CancelOption.NOTIFY_PEER);
            }
        }
    } catch (IOException e) {
        error = true;
        log.error ("Error while sending file: ", e);
        localCancel ("An I/O problem occurred while the project's files were being sent: \"" + e.getMessage () + "\" The invitation was cancelled.", CancelOption.NOTIFY_PEER);
        executeCancellation ();
    } catch (SarosCancellationException e) {
        log.debug ("Invitation process was cancelled.");
    } catch (Exception e) {
        log.error ("Unknown exception: ", e);
    } finally {
        try {
            if (filesSent >= 1) zout.finish ();

        } catch (IOException e) {
            log.warn ("IOException occurred when finishing the ZipOutputStream.");
        }
        IOUtils.closeQuietly (output);
        IOUtils.closeQuietly (zout);
    }
    subMonitor.done ();
}