@Override
 public void calcData(DataKey key, DataSink sink) {
   super.calcData(key, sink);
   if (key.equals(PlatformDataKeys.DELETE_ELEMENT_PROVIDER) && myDeleteProvider != null) {
     sink.put(key, myDeleteProvider);
   } else if (key.equals(CommonDataKeys.VIRTUAL_FILE_ARRAY)) {
     sink.put(key, ArrayUtil.toObjectArray(getSelectedChanges(), VirtualFile.class));
   }
 }
 public void calcData(DataKey key, DataSink sink) {
   if (OpenFileDescriptor.NAVIGATE_IN_EDITOR == key) {
     sink.put(OpenFileDescriptor.NAVIGATE_IN_EDITOR, myConsoleEditor);
     return;
   } else if (getProject().isInitialized()) {
     FileEditorManager editorManager = FileEditorManager.getInstance(getProject());
     final Object o =
         ((FileEditorManagerImpl) editorManager)
             .getData(key.getName(), myConsoleEditor, myVirtualFile);
     sink.put(key, o);
   }
 }
  private InputStream getInputStream(
      String urlStr, Format outputFormat, ContentDescriptor outputContentDescriptor)
      throws Exception {
    final ProcessorModel processorModel =
        new ProcessorModel(
            new MediaLocator(urlStr),
            outputFormat == null ? null : new Format[] {outputFormat},
            outputContentDescriptor);

    final Processor processor = Manager.createRealizedProcessor(processorModel);

    final DataSource ds = processor.getDataOutput();

    final DataSink[] streamDataSinkHolder = new DataSink[] {null};
    // connect the data output of the processor to a StreamDataSink, which
    // will make the data available to PipedInputStream, which we return.
    final PipedInputStream in =
        new PipedInputStream() {
          // override close to clean up everything when the media has been
          // served.
          @Override
          public void close() throws IOException {
            super.close();
            logger.fine("Closed input stream");
            logger.fine("Stopping processor");
            processor.stop();
            logger.fine("Closing processor");
            processor.close();
            logger.fine("Deallocating processor");
            processor.deallocate();
            if (streamDataSinkHolder[0] != null) {
              logger.fine("Closing StreamDataSink");
              streamDataSinkHolder[0].close();
            }
          }
        };
    final PipedOutputStream out = new PipedOutputStream(in);
    final DataSink streamDataSink = new StreamDataSink(out);
    streamDataSinkHolder[0] = streamDataSink;

    streamDataSink.setSource(ds);
    streamDataSink.open();
    streamDataSink.start();

    logger.info("Starting processor");
    processor.start();

    // TODO: if there is an error, make sure we clean up.
    // for example, if the client breaks the connection.
    // we need a controller listener to listen for errors.

    return in;
  }
 @Override
 public void calcData(DataKey key, DataSink sink) {
   if (UsageView.USAGE_SCOPE.equals(key)) {
     SearchScope scope = getScopeFromModel(myProject, myFindModel);
     sink.put(UsageView.USAGE_SCOPE, scope);
   }
 }
Ejemplo n.º 5
0
 private void writePending() {
   //        Log.i("NIO", "Writing to buffer...");
   if (mPendingWrites != null) {
     mDataSink.write(mPendingWrites);
     if (mPendingWrites.remaining() == 0) mPendingWrites = null;
   }
   if (mPendingWrites == null && mWritable != null) mWritable.onWriteable();
 }
Ejemplo n.º 6
0
  /**
   * Finds the <tt>ReceiveStreamDesc</tt> with a particular <tt>DataSink</tt>
   *
   * @param dataSink The <tt>DataSink</tt> to match.
   * @return the <tt>ReceiveStreamDesc</tt> with a particular <tt>DataSink</tt>, or <tt>null</tt>.
   */
  private ReceiveStreamDesc findReceiveStream(DataSink dataSink) {
    if (dataSink == null) return null;

    synchronized (receiveStreams) {
      for (ReceiveStreamDesc r : receiveStreams) if (dataSink.equals(r.dataSink)) return r;
    }

    return null;
  }
Ejemplo n.º 7
0
 public BufferedDataSink(DataSink datasink) {
   mDataSink = datasink;
   mDataSink.setWriteableCallback(
       new WritableCallback() {
         @Override
         public void onWriteable() {
           writePending();
         }
       });
 }
    @Override
    public void calcData(final DataKey key, final DataSink sink) {
      Node node = getSelectedNode();

      if (key == PlatformDataKeys.PROJECT) {
        sink.put(PlatformDataKeys.PROJECT, myProject);
      } else if (key == USAGE_VIEW_KEY) {
        sink.put(USAGE_VIEW_KEY, UsageViewImpl.this);
      } else if (key == PlatformDataKeys.NAVIGATABLE_ARRAY) {
        sink.put(PlatformDataKeys.NAVIGATABLE_ARRAY, getNavigatablesForNodes(getSelectedNodes()));
      } else if (key == PlatformDataKeys.EXPORTER_TO_TEXT_FILE) {
        sink.put(PlatformDataKeys.EXPORTER_TO_TEXT_FILE, myTextFileExporter);
      } else if (key == USAGES_KEY) {
        final Set<Usage> selectedUsages = getSelectedUsages();
        sink.put(
            USAGES_KEY,
            selectedUsages != null
                ? selectedUsages.toArray(new Usage[selectedUsages.size()])
                : null);
      } else if (key == USAGE_TARGETS_KEY) {
        sink.put(USAGE_TARGETS_KEY, getSelectedUsageTargets());
      } else if (key == PlatformDataKeys.VIRTUAL_FILE_ARRAY) {
        final Set<Usage> usages = getSelectedUsages();
        Usage[] ua = usages != null ? usages.toArray(new Usage[usages.size()]) : null;
        VirtualFile[] data = UsageDataUtil.provideVirtualFileArray(ua, getSelectedUsageTargets());
        sink.put(PlatformDataKeys.VIRTUAL_FILE_ARRAY, data);
      } else if (key == PlatformDataKeys.HELP_ID) {
        sink.put(PlatformDataKeys.HELP_ID, HELP_ID);
      } else if (key == PlatformDataKeys.COPY_PROVIDER) {
        sink.put(PlatformDataKeys.COPY_PROVIDER, this);
      } else if (node != null) {
        Object userObject = node.getUserObject();
        if (userObject instanceof TypeSafeDataProvider) {
          ((TypeSafeDataProvider) userObject).calcData(key, sink);
        } else if (userObject instanceof DataProvider) {
          DataProvider dataProvider = (DataProvider) userObject;
          Object data = dataProvider.getData(key.getName());
          if (data != null) {
            sink.put(key, data);
          }
        }
      }
    }
 @Override
 public void calcData(DataKey key, DataSink sink) {
   if (key == CommonDataKeys.NAVIGATABLE_ARRAY) {
     List<Navigatable> navigatables = getNavigatables();
     if (!navigatables.isEmpty()) {
       sink.put(
           CommonDataKeys.NAVIGATABLE_ARRAY,
           navigatables.toArray(new Navigatable[navigatables.size()]));
     }
   }
 }
Ejemplo n.º 10
0
 /** Stops the transmission if already started */
 public void stop() {
   synchronized (this) {
     if (processor != null) {
       processor.stop();
       processor.close();
       processor = null;
       rtptransmitter.close();
       rtptransmitter = null;
     }
   }
 }
Ejemplo n.º 11
0
 @Override
 public void calcData(final DataKey key, final DataSink sink) {
   if (key.equals(LangDataKeys.PSI_ELEMENT)) {
     if (mySelectedElements != null && !mySelectedElements.isEmpty()) {
       T selectedElement = mySelectedElements.iterator().next();
       if (selectedElement instanceof ClassMemberWithElement) {
         sink.put(
             LangDataKeys.PSI_ELEMENT, ((ClassMemberWithElement) selectedElement).getElement());
       }
     }
   }
 }
  /** Create the DataSink. */
  DataSink createDataSink(Processor p, MediaLocator outML) {
    DataSource ds;

    if ((ds = p.getDataOutput()) == null) {
      System.err.println(
          "Something is really wrong: the processor does not have an output DataSource");
      return null;
    }

    DataSink dsink;

    try {
      System.err.println("- Create DataSink for: " + outML);
      dsink = Manager.createDataSink(ds, outML);
      dsink.open();
    } catch (Exception e) {
      System.err.println("Cannot create the DataSink: " + e);
      return null;
    }

    return dsink;
  }
Ejemplo n.º 13
0
  @Override
  public void write(ByteBufferList bb) {
    if (mPendingWrites == null) mDataSink.write(bb);
    //        else
    //            Assert.assertTrue(mPendingWrites.remaining() <= mMaxBuffer);

    if (bb.remaining() > 0) {
      int toRead = Math.min(bb.remaining(), mMaxBuffer);
      if (toRead > 0) {
        if (mPendingWrites == null) mPendingWrites = new ByteBufferList();
        mPendingWrites.add(bb.get(toRead));
      }
    }
  }
Ejemplo n.º 14
0
  // Creates an RTP transmit data sink. This is the easiest way to create
  // an RTP transmitter. The other way is to use the RTPSessionManager API.
  // Using an RTP session manager gives you more control if you wish to
  // fine tune your transmission and set other parameters.
  private String createTransmitter() {
    // Create a media locator for the RTP data sink.
    // For example:
    //    rtp://129.130.131.132:42050/video
    String rtpURL = "rtp://" + ipAddress + ":" + port + "/video";
    MediaLocator outputLocator = new MediaLocator(rtpURL);

    // Create a data sink, open it and start transmission. It will wait
    // for the processor to start sending data. So we need to start the
    // output data source of the processor. We also need to start the
    // processor itself, which is done after this method returns.
    try {
      rtptransmitter = Manager.createDataSink(dataOutput, outputLocator);
      rtptransmitter.open();
      rtptransmitter.start();
      dataOutput.start();
    } catch (MediaException me) {
      return "Couldn't create RTP data sink";
    } catch (IOException ioe) {
      return "Couldn't create RTP data sink";
    }

    return null;
  }
Ejemplo n.º 15
0
 @Override
 public CompletedCallback getClosedCallback() {
   return mDataSink.getClosedCallback();
 }
Ejemplo n.º 16
0
 @Override
 public AsyncServer getServer() {
   return mDataSink.getServer();
 }
 @Override
 public void calcData(DataKey key, DataSink sink) {
   if (key == VcsDataKeys.CHANGES) {
     sink.put(VcsDataKeys.CHANGES, getSelectedChanges());
   } else if (key == VcsDataKeys.CHANGE_LEAD_SELECTION) {
     sink.put(VcsDataKeys.CHANGE_LEAD_SELECTION, getLeadSelection());
   } else if (key == VcsDataKeys.CHANGE_LISTS) {
     sink.put(VcsDataKeys.CHANGE_LISTS, getSelectedChangeLists());
   } else if (key == PlatformDataKeys.VIRTUAL_FILE_ARRAY) {
     sink.put(PlatformDataKeys.VIRTUAL_FILE_ARRAY, getSelectedFiles());
   } else if (key == PlatformDataKeys.NAVIGATABLE) {
     final VirtualFile[] files = getSelectedFiles();
     if (files.length == 1 && !files[0].isDirectory()) {
       sink.put(PlatformDataKeys.NAVIGATABLE, new OpenFileDescriptor(myProject, files[0], 0));
     }
   } else if (key == PlatformDataKeys.NAVIGATABLE_ARRAY) {
     sink.put(
         PlatformDataKeys.NAVIGATABLE_ARRAY,
         ChangesUtil.getNavigatableArray(myProject, getSelectedFiles()));
   } else if (key == PlatformDataKeys.DELETE_ELEMENT_PROVIDER) {
     final TreePath[] paths = getSelectionPaths();
     if (paths != null) {
       for (TreePath path : paths) {
         ChangesBrowserNode node = (ChangesBrowserNode) path.getLastPathComponent();
         if (!(node.getUserObject() instanceof ChangeList)) {
           sink.put(PlatformDataKeys.DELETE_ELEMENT_PROVIDER, new VirtualFileDeleteProvider());
           break;
         }
       }
     }
   } else if (key == PlatformDataKeys.COPY_PROVIDER) {
     sink.put(PlatformDataKeys.COPY_PROVIDER, myCopyProvider);
   } else if (key == UNVERSIONED_FILES_DATA_KEY) {
     sink.put(UNVERSIONED_FILES_DATA_KEY, getSelectedUnversionedFiles());
   } else if (key == VcsDataKeys.MODIFIED_WITHOUT_EDITING_DATA_KEY) {
     sink.put(VcsDataKeys.MODIFIED_WITHOUT_EDITING_DATA_KEY, getSelectedModifiedWithoutEditing());
   } else if (key == LOCALLY_DELETED_CHANGES) {
     sink.put(LOCALLY_DELETED_CHANGES, getSelectedLocallyDeletedChanges());
   } else if (key == MISSING_FILES_DATA_KEY) {
     sink.put(MISSING_FILES_DATA_KEY, getSelectedMissingFiles());
   } else if (VcsDataKeys.HAVE_LOCALLY_DELETED == key) {
     sink.put(VcsDataKeys.HAVE_LOCALLY_DELETED, haveLocallyDeleted());
   } else if (VcsDataKeys.HAVE_MODIFIED_WITHOUT_EDITING == key) {
     sink.put(VcsDataKeys.HAVE_MODIFIED_WITHOUT_EDITING, haveLocallyModified());
   } else if (VcsDataKeys.HAVE_SELECTED_CHANGES == key) {
     sink.put(VcsDataKeys.HAVE_SELECTED_CHANGES, haveSelectedChanges());
   } else if (key == HELP_ID_DATA_KEY) {
     sink.put(HELP_ID_DATA_KEY, ourHelpId);
   } else if (key == VcsDataKeys.CHANGES_IN_LIST_KEY) {
     final TreePath selectionPath = getSelectionPath();
     if (selectionPath != null && selectionPath.getPathCount() > 1) {
       ChangesBrowserNode<?> firstNode = (ChangesBrowserNode) selectionPath.getPathComponent(1);
       if (firstNode instanceof ChangesBrowserChangeListNode) {
         final List<Change> list = firstNode.getAllChangesUnder();
         sink.put(VcsDataKeys.CHANGES_IN_LIST_KEY, list);
       }
     }
   }
 }
Ejemplo n.º 18
0
 @Override
 public void calcData(DataKey key, DataSink sink) {
   if (PlatformDataKeys.COPY_PROVIDER == key) {
     sink.put(key, this);
   }
 }
Ejemplo n.º 19
0
 @Override
 public boolean isOpen() {
   return mDataSink.isOpen();
 }
Ejemplo n.º 20
0
 @Override
 public void close() {
   mDataSink.close();
 }
Ejemplo n.º 21
0
 @Override
 public void setClosedCallback(CompletedCallback handler) {
   mDataSink.setClosedCallback(handler);
 }
Ejemplo n.º 22
0
  /**
   * Implements {@link ControllerListener#controllerUpdate(ControllerEvent)}. Handles events from
   * the <tt>Processor</tt>s that this instance uses to transcode media.
   *
   * @param ev the event to handle.
   */
  public void controllerUpdate(ControllerEvent ev) {
    if (ev == null || ev.getSourceController() == null) {
      return;
    }

    Processor processor = (Processor) ev.getSourceController();
    ReceiveStreamDesc desc = findReceiveStream(processor);

    if (desc == null) {
      logger.warn("Event from an orphaned processor, ignoring: " + ev);
      return;
    }

    if (ev instanceof ConfigureCompleteEvent) {
      if (logger.isInfoEnabled()) {
        logger.info(
            "Configured processor for ReceiveStream ssrc="
                + desc.ssrc
                + " ("
                + desc.format
                + ")"
                + " "
                + System.currentTimeMillis());
      }

      boolean audio = desc.format instanceof AudioFormat;

      if (audio) {
        ContentDescriptor cd = processor.setContentDescriptor(AUDIO_CONTENT_DESCRIPTOR);
        if (!AUDIO_CONTENT_DESCRIPTOR.equals(cd)) {
          logger.error(
              "Failed to set the Processor content "
                  + "descriptor to "
                  + AUDIO_CONTENT_DESCRIPTOR
                  + ". Actual result: "
                  + cd);
          removeReceiveStream(desc, false);
          return;
        }
      }

      for (TrackControl track : processor.getTrackControls()) {
        Format trackFormat = track.getFormat();

        if (audio) {
          final long ssrc = desc.ssrc;
          SilenceEffect silenceEffect;
          if (Constants.OPUS_RTP.equals(desc.format.getEncoding())) {
            silenceEffect = new SilenceEffect(48000);
          } else {
            // We haven't tested that the RTP timestamps survive
            // the journey through the chain when codecs other than
            // opus are in use, so for the moment we rely on FMJ's
            // timestamps for non-opus formats.
            silenceEffect = new SilenceEffect();
          }

          silenceEffect.setListener(
              new SilenceEffect.Listener() {
                boolean first = true;

                @Override
                public void onSilenceNotInserted(long timestamp) {
                  if (first) {
                    first = false;
                    // send event only
                    audioRecordingStarted(ssrc, timestamp);
                  } else {
                    // change file and send event
                    resetRecording(ssrc, timestamp);
                  }
                }
              });
          desc.silenceEffect = silenceEffect;
          AudioLevelEffect audioLevelEffect = new AudioLevelEffect();
          audioLevelEffect.setAudioLevelListener(
              new SimpleAudioLevelListener() {
                @Override
                public void audioLevelChanged(int level) {
                  activeSpeakerDetector.levelChanged(ssrc, level);
                }
              });

          try {
            // We add an effect, which will insert "silence" in
            // place of lost packets.
            track.setCodecChain(new Codec[] {silenceEffect, audioLevelEffect});
          } catch (UnsupportedPlugInException upie) {
            logger.warn("Failed to insert silence effect: " + upie);
            // But do go on, a recording without extra silence is
            // better than nothing ;)
          }
        } else {
          // transcode vp8/rtp to vp8 (i.e. depacketize vp8)
          if (trackFormat.matches(vp8RtpFormat)) track.setFormat(vp8Format);
          else {
            logger.error("Unsupported track format: " + trackFormat + " for ssrc=" + desc.ssrc);
            // we currently only support vp8
            removeReceiveStream(desc, false);
            return;
          }
        }
      }

      processor.realize();
    } else if (ev instanceof RealizeCompleteEvent) {
      desc.dataSource = processor.getDataOutput();

      long ssrc = desc.ssrc;
      boolean audio = desc.format instanceof AudioFormat;
      String suffix = audio ? AUDIO_FILENAME_SUFFIX : VIDEO_FILENAME_SUFFIX;

      // XXX '\' on windows?
      String filename = getNextFilename(path + "/" + ssrc, suffix);
      desc.filename = filename;

      DataSink dataSink;
      if (audio) {
        try {
          dataSink = Manager.createDataSink(desc.dataSource, new MediaLocator("file:" + filename));
        } catch (NoDataSinkException ndse) {
          logger.error("Could not create DataSink: " + ndse);
          removeReceiveStream(desc, false);
          return;
        }

      } else {
        dataSink = new WebmDataSink(filename, desc.dataSource);
      }

      if (logger.isInfoEnabled())
        logger.info(
            "Created DataSink ("
                + dataSink
                + ") for SSRC="
                + ssrc
                + ". Output filename: "
                + filename);
      try {
        dataSink.open();
      } catch (IOException e) {
        logger.error("Failed to open DataSink (" + dataSink + ") for" + " SSRC=" + ssrc + ": " + e);
        removeReceiveStream(desc, false);
        return;
      }

      if (!audio) {
        final WebmDataSink webmDataSink = (WebmDataSink) dataSink;
        webmDataSink.setSsrc(ssrc);
        webmDataSink.setEventHandler(eventHandler);
        webmDataSink.setKeyFrameControl(
            new KeyFrameControlAdapter() {
              @Override
              public boolean requestKeyFrame(boolean urgent) {
                return requestFIR(webmDataSink);
              }
            });
      }

      try {
        dataSink.start();
      } catch (IOException e) {
        logger.error(
            "Failed to start DataSink (" + dataSink + ") for" + " SSRC=" + ssrc + ". " + e);
        removeReceiveStream(desc, false);
        return;
      }

      if (logger.isInfoEnabled()) logger.info("Started DataSink for SSRC=" + ssrc);

      desc.dataSink = dataSink;

      processor.start();
    } else if (logger.isDebugEnabled()) {
      logger.debug(
          "Unhandled ControllerEvent from the Processor for ssrc=" + desc.ssrc + ": " + ev);
    }
  }
 @Override
 public void calcData(DataKey key, DataSink sink) {
   if (key == VcsDataKeys.COMMIT_MESSAGE_CONTROL) {
     sink.put(VcsDataKeys.COMMIT_MESSAGE_CONTROL, myCommitMessagePanel);
   }
 }
Ejemplo n.º 24
0
  public static void main(String[] args) {

    // ---------------- CUT HERE START ----------------- //

    Format formats[] = new Format[2];
    formats[0] = new AudioFormat(AudioFormat.IMA4);
    formats[1] = new VideoFormat(VideoFormat.CINEPAK);
    FileTypeDescriptor outputType = new FileTypeDescriptor(FileTypeDescriptor.QUICKTIME);
    Processor p = null;

    try {
      p = Manager.createRealizedProcessor(new ProcessorModel(formats, outputType));
    } catch (IOException e) {
      System.exit(-1);
    } catch (NoProcessorException e) {
      System.exit(-1);
    } catch (CannotRealizeException e) {
      System.exit(-1);
    }
    // get the output of the processor
    DataSource source = p.getDataOutput();
    // create a File protocol MediaLocator with the location of the file to
    // which bits are to be written
    MediaLocator dest = new MediaLocator("file://foo.mov");
    // create a datasink to do the file writing & open the sink to make sure
    // we can write to it.
    DataSink filewriter = null;
    try {
      filewriter = Manager.createDataSink(source, dest);
      filewriter.open();
    } catch (NoDataSinkException e) {
      System.exit(-1);
    } catch (IOException e) {
      System.exit(-1);
    } catch (SecurityException e) {
      System.exit(-1);
    }
    // now start the filewriter and processor
    try {
      filewriter.start();
    } catch (IOException e) {
      System.exit(-1);
    }
    p.start();
    // stop and close the processor when done capturing...
    // close the datasink when EndOfStream event is received...

    // ----------------- CUT HERE END ---------------- //
    try {
      Thread.currentThread().sleep(4000);
    } catch (InterruptedException ie) {
    }
    p.stop();
    p.close();
    try {
      Thread.currentThread().sleep(1000);
    } catch (InterruptedException ie) {
    }
    filewriter.close();
    try {
      Thread.currentThread().sleep(4000);
    } catch (InterruptedException ie) {
    }

    System.exit(0);
  }
  /**
   * Given an array of input media locators and an output locator, this method will concatenate the
   * input media files to generate a single concatentated output.
   */
  public boolean doIt(MediaLocator inML[], MediaLocator outML) {
    // Guess the output content descriptor from the file extension.
    ContentDescriptor cd;

    if ((cd = fileExtToCD(outML.getRemainder())) == null) {
      System.err.println("Couldn't figure out from the file extension the type of output needed!");
      return false;
    }

    // Build the ProcInfo data structure for each processor.
    ProcInfo pInfo[] = new ProcInfo[inML.length];

    for (int i = 0; i < inML.length; i++) {
      pInfo[i] = new ProcInfo();
      pInfo[i].ml = inML[i];

      try {
        System.err.println("- Create processor for: " + inML[i]);
        pInfo[i].p = Manager.createProcessor(inML[i]);
      } catch (Exception e) {
        System.err.println("Yikes!  Cannot create a processor from the given url: " + e);
        return false;
      }
    }

    // Try to match the tracks from different processors.
    if (!matchTracks(pInfo, cd)) {
      System.err.println("Failed to match the tracks.");
      return false;
    }

    // Program each processors to perform the necessary transcoding
    // to concatenate the tracks.
    if (!buildTracks(pInfo)) {
      System.err.println("Failed to build processors for the inputs.");
      return false;
    }

    // Generate a super glue data source from the processors.
    SuperGlueDataSource ds = new SuperGlueDataSource(pInfo);

    // Create the processor to generate the final output.
    Processor p;
    try {
      p = Manager.createProcessor(ds);
    } catch (Exception e) {
      System.err.println("Failed to create a processor to concatenate the inputs.");
      return false;
    }

    p.addControllerListener(this);

    // Put the Processor into configured state.
    if (!waitForState(p, Processor.Configured)) {
      System.err.println("Failed to configure the processor.");
      return false;
    }

    // Set the output content descriptor on the final processor.
    System.err.println("- Set output content descriptor to: " + cd);
    if ((p.setContentDescriptor(cd)) == null) {
      System.err.println("Failed to set the output content descriptor on the processor.");
      return false;
    }

    // We are done with programming the processor. Let's just
    // realize it.
    if (!waitForState(p, Controller.Realized)) {
      System.err.println("Failed to realize the processor.");
      return false;
    }

    // Now, we'll need to create a DataSink.
    DataSink dsink;
    if ((dsink = createDataSink(p, outML)) == null) {
      System.err.println("Failed to create a DataSink for the given output MediaLocator: " + outML);
      return false;
    }

    dsink.addDataSinkListener(this);
    fileDone = false;

    System.err.println("- Start concatenation...");

    // OK, we can now start the actual concatenation.
    try {
      p.start();
      dsink.start();
    } catch (IOException e) {
      System.err.println("IO error during concatenation");
      return false;
    }

    // Wait for EndOfStream event.
    waitForFileDone();

    // Cleanup.
    try {
      dsink.close();
    } catch (Exception e) {
    }
    p.removeControllerListener(this);

    System.err.println("  ...done concatenation.");

    return true;
  }
 public void calcData(DataKey key, DataSink sink) {
   if (key == VcsDataKeys.CHANGES) {
     List<Change> list = getSelectedChanges();
     if (list.isEmpty()) list = getAllChanges();
     sink.put(VcsDataKeys.CHANGES, list.toArray(new Change[list.size()]));
   } else if (key == VcsDataKeys.CHANGES_SELECTION) {
     sink.put(VcsDataKeys.CHANGES_SELECTION, getChangesSelection());
   } else if (key == VcsDataKeys.CHANGE_LISTS) {
     sink.put(VcsDataKeys.CHANGE_LISTS, getSelectedChangeLists());
   } else if (key == VcsDataKeys.CHANGE_LEAD_SELECTION) {
     final Change highestSelection =
         ObjectUtils.tryCast(myViewer.getHighestLeadSelection(), Change.class);
     sink.put(
         VcsDataKeys.CHANGE_LEAD_SELECTION,
         (highestSelection == null) ? new Change[] {} : new Change[] {highestSelection});
   } else if (key == CommonDataKeys.VIRTUAL_FILE_ARRAY) {
     sink.put(CommonDataKeys.VIRTUAL_FILE_ARRAY, getSelectedFiles().toArray(VirtualFile[]::new));
   } else if (key == CommonDataKeys.NAVIGATABLE_ARRAY) {
     sink.put(
         CommonDataKeys.NAVIGATABLE_ARRAY, getNavigatableArray(myProject, getSelectedFiles()));
   } else if (VcsDataKeys.IO_FILE_ARRAY.equals(key)) {
     sink.put(VcsDataKeys.IO_FILE_ARRAY, getSelectedIoFiles());
   } else if (key == DATA_KEY) {
     sink.put(DATA_KEY, this);
   } else if (VcsDataKeys.SELECTED_CHANGES_IN_DETAILS.equals(key)) {
     final List<Change> selectedChanges = getSelectedChanges();
     sink.put(
         VcsDataKeys.SELECTED_CHANGES_IN_DETAILS,
         selectedChanges.toArray(new Change[selectedChanges.size()]));
   } else if (UNVERSIONED_FILES_DATA_KEY.equals(key)) {
     sink.put(
         UNVERSIONED_FILES_DATA_KEY,
         getVirtualFiles(myViewer.getSelectionPaths(), UNVERSIONED_FILES_TAG));
   } else if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.equals(key)) {
     sink.put(PlatformDataKeys.DELETE_ELEMENT_PROVIDER, myDeleteProvider);
   }
 }