// Extract transcoder to data directory public TranscodeService() { InputStream inputStream = null; OutputStream outputStream; // Get transcoder if (SystemUtils.IS_OS_WINDOWS) { inputStream = getClass().getResourceAsStream("ffmpeg.exe"); } else if (SystemUtils.IS_OS_LINUX) { inputStream = getClass().getResourceAsStream("ffmpeg"); } // Check we found the transcoder if (inputStream == null) { LogService.getInstance().addLogEntry(Level.ERROR, CLASS_NAME, "Transcoder not found!", null); return; } // Copy transcoder to filesystem try { LogService.getInstance().addLogEntry(Level.INFO, CLASS_NAME, "Preparing transcoder.", null); File file = new File(TRANSCODER_FILE); int readBytes; byte[] buffer = new byte[4096]; outputStream = new FileOutputStream(file); while ((readBytes = inputStream.read(buffer)) > 0) { outputStream.write(buffer, 0, readBytes); } // Close streams inputStream.close(); outputStream.close(); // Check file copied successfully if (!file.exists()) { LogService.getInstance() .addLogEntry(Level.ERROR, CLASS_NAME, "Failed to extract transcoder!", null); return; } // Make sure file is executable file.setExecutable(true); } catch (IOException ex) { LogService.getInstance() .addLogEntry(Level.ERROR, CLASS_NAME, "Failed to extract transcoder!", ex); } }
public String getLabel(String name) { try { return resources.getString(name); } catch (Exception exp) { LogService.getInstance().setMessage(exp, name); return name; } }
/* * Returns a file reference to the transcoder. */ public File getTranscoder() { File transcoder = new File(TRANSCODER_FILE); // Check if the transcoder binary exists if (!transcoder.exists()) { LogService.getInstance().addLogEntry(Level.ERROR, CLASS_NAME, "Transcoder not found!", null); return null; } return transcoder; }
protected void loadResources(Class<?> clazz, Properties properties, String name) { ClassLoader loader = clazz.getClassLoader(); String locale = null; try { locale = properties.get("locale").toString(); if (locale == null || locale.trim().length() == 0) locale = "vn"; } catch (Exception exp) { LogService.getInstance().setThrowable(null, exp); locale = "vn"; } resources = ResourceBundle.getBundle("resources.i18n." + locale + "." + name, Locale.ENGLISH, loader); }