Package de.fu_berlin.inf.dpp.net.internal

Examples of de.fu_berlin.inf.dpp.net.internal.StreamSession$StreamSessionInputStream


            log.debug("Method interrupted waiting for archive stream lock.");
        } finally {
            archiveStreamService.startLock.unlock();
        }

        StreamSession newSession = archiveStreamService.streamSession;
        int numOfFiles = archiveStreamService.getFileNum();

        IFile currentFile = null;

        int worked = 0;
        int lastWorked = 0;
        int filesReceived = 0;
        double increment = 0.0;

        InputStream in = newSession.getInputStream(0);
        ZipInputStream zin = new ZipInputStream(in);
        try {

            ZipEntry zipEntry = null;
            monitor.beginTask(null, 100);
            monitor.subTask("Receiving project files...");

            if (numOfFiles >= 1) {
                increment = (double) 100 / numOfFiles;
            } else {
                monitor.worked(100);
            }

            while ((zipEntry = zin.getNextEntry()) != null) {
                // every zipEntry represents/contains exactly one file
                String projectID = new String(zipEntry.getExtra());
                IProject currentProject = localProjects.get(projectID);
                if (currentProject == null) {
                    // this is really unlikely
                    log.error("currentProject is null");
                    throw new SarosCancellationException(
                        "File did not belong to a project that is supposed to be added");
                } else {
                    log.info("everything seems to be normal");
                }
                currentFile = currentProject.getFile(zipEntry.getName());
                monitor.setTaskName(MessageFormat.format("Receiving {0}",
                    zipEntry.getName()));

                if (currentFile.exists()) {
                    log.debug(currentFile
                        + " already exists on invitee. Replacing this file.");
                    currentFile.delete(true, null);
                }

                currentFile.create(new UncloseableInputStream(zin), true, null);

                worked = (int) Math.round(increment * filesReceived);

                if ((worked - lastWorked) > 0) {
                    monitor.worked((worked - lastWorked));
                    lastWorked = worked;
                }

                filesReceived++;

                checkCancellation();
            }
            // Just to be sure we don't have any problems with rounding
            monitor.worked(100);

        } catch (SarosCancellationException e) {
            log.debug("Invitation process was cancelled.");
            localCancel("An invitee cancelled the invitation.",
                CancelOption.NOTIFY_PEER);
            executeCancellation();
        } catch (CoreException e) {
            log.error("Exception while creating file. Message: ", e);
            localCancel(
                "A problem occurred while the project's files were being received: \""
                    + e.getMessage() + "\" The invitation was cancelled.",
                CancelOption.NOTIFY_PEER);
            executeCancellation();
        } catch (EOFException e) {
            log.error("Error while receiving files: " + e.getMessage());
            localCancel(
                "A problem occured when receiving the project files. It is possible that the files were corrupted in transit.\n\nPlease attempt invitation again.",
                CancelOption.NOTIFY_PEER);
            executeCancellation();
        } catch (Exception e) {
            log.error("Unknown exception: ", e);
        } finally {
            IOUtils.closeQuietly(in);
            IOUtils.closeQuietly(zin);
            newSession.stopSession();
        }
    }
View Full Code Here


        try {
            if (videoSharingSessionObservable.getValue() != null) {
                return;
            }
            ConnectionFactory connectionFactory = null;
            StreamSession streamSession = null;

            try {
                if (to.isLocal()) {
                    connectionFactory = new ConnectionFactory();
                    videoSharingSessionObservable
                        .setValue(new VideoSharingSession(connectionFactory, to));
                    return;
                }
                try {
                    streamSession = streamServiceManager.createSession(
                        videoSharingService, to, VideoSharingInit.create(this),
                        null);
                    connectionFactory = new ConnectionFactory(streamSession,
                        Mode.HOST);
                    videoSharingSessionObservable
                        .setValue(new VideoSharingSession(streamSession,
                            connectionFactory, to));
                } catch (InterruptedException e) {
                    log.error("Code not designed to be interrupted: ", e);
                    Thread.currentThread().interrupt();
                    return;
                } catch (ExecutionException e) {
                    Throwable cause = e.getCause();
                    if (cause instanceof SarosCancellationException) {
                        SarosCancellationException cancellation = (SarosCancellationException) cause;
                        throw cancellation;
                    } else {
                        log.error("Unexpected Exception: ", cause);
                    }
                    return;
                } catch (IOException e) {
                    if (streamSession != null)
                        streamSession.dispose();
                } catch (ConnectionException e) {
                    throw new SarosCancellationException("Could not connect.");
                } catch (TimeoutException e) {
                    throw new SarosCancellationException("Request timed out.");
                }
View Full Code Here

TOP

Related Classes of de.fu_berlin.inf.dpp.net.internal.StreamSession$StreamSessionInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.