Package org.jampa.engine.mplayer

Source Code of org.jampa.engine.mplayer.MPlayerEngineTester

/*
* Jampa
* Copyright (C) 2008-2009 J. Devauchelle and contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*/

package org.jampa.engine.mplayer;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.jampa.logging.Log;

public class MPlayerEngineTester {

  private String _mplayerPath; 
 
  public MPlayerEngineTester(String mplayerPath) {
    _mplayerPath = mplayerPath;
  }
 
  private boolean doTestProcess() {
    Process mplayerProcess;
    BufferedReader outputStream;
    List<String> processOutput = new ArrayList<String>();
    ProcessBuilder pb = new ProcessBuilder();
    List<String> command = new ArrayList<String>();

    command.add(_mplayerPath);
   
    try {
      mplayerProcess = pb.command(command).start();
     
      outputStream = new BufferedReader(new InputStreamReader(mplayerProcess.getInputStream()));
     
      String line = null;
      while ((line = outputStream.readLine()) != null) {
        processOutput.add(line);
      }
     
    } catch (IOException e) {     
      Log.getInstance(MPlayerEngineTester.class).warn(e.toString());
      return false;
    }
   
    if ((processOutput.size() > 0) &&
        (processOutput.get(0).toLowerCase().contains("mplayer"))) { //$NON-NLS-1$
      return true;
    } else {
      return false;
    }
  }
 
  private boolean doTestPath() {
    boolean result;
   
    File testFile = new File(_mplayerPath);
   
    if ((testFile.exists()) &&
      (testFile.isFile()) &&
      (testFile.canExecute())) {
      result = true;
    } else {
      result = false;
    }
   
    return result;
  }
 
  public boolean doTest() {
    return doTestPath() && doTestProcess();
  }
 
}
TOP

Related Classes of org.jampa.engine.mplayer.MPlayerEngineTester

TOP
Copyright © 2018 www.massapi.com. 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.