List of usage examples for java.io File equals
public boolean equals(Object obj)
From source file:org.apache.maven.plugin.cxx.VeraxxMojo.java
@Override protected OutputStream getOutputStreamErr() { String outputReportName = new String(); if (reportsfileDir.isAbsolute()) { outputReportName = reportsfileDir.getAbsolutePath() + File.separator + getReportFileName(); } else {/* w w w. j a v a 2 s .c o m*/ outputReportName = basedir.getAbsolutePath() + File.separator + reportsfileDir.getPath() + File.separator + getReportFileName(); } getLog().info("Vera++ report location " + outputReportName); OutputStream output = System.err; File file = new File(outputReportName); try { new File(file.getParent()).mkdirs(); file.createNewFile(); output = new FileOutputStream(file); } catch (IOException e) { getLog().error("Vera++ report redirected to stderr since " + outputReportName + " can't be opened"); return output; } final DataOutputStream out = new DataOutputStream(output); try { out.writeBytes("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); out.writeBytes("<checkstyle version=\"5.0\">\n"); } catch (IOException e) { getLog().error("Vera++ xml report write failure"); } OutputStream outErrFilter = new OutputStream() { StringBuffer sb = new StringBuffer(); public void write(int b) throws IOException { if ((b == '\n') || (b == '\r')) { transformCurrentLine(); // cleanup for next line sb.delete(0, sb.length()); } else { sb.append((char) b); } } public void flush() throws IOException { transformCurrentLine(); getLog().debug("Vera++ xml flush() called"); if (!StringUtils.isEmpty(lastfile)) { out.writeBytes("\t</file>\n"); } out.writeBytes("</checkstyle>\n"); out.flush(); } String lastfile; private void transformCurrentLine() { if (sb.length() > 0) { // parse current line // try to replace ' (RULENumber) ' with 'RULENumber:' String p = "^(.+) \\((.+)\\) (.+)$"; Pattern pattern = Pattern.compile(p); Matcher matcher = pattern.matcher(sb); getLog().debug("match " + sb + " on " + p); boolean bWinPath = false; if (sb.charAt(1) == ':') { bWinPath = true; sb.setCharAt(1, '_'); } if (matcher.matches()) { String sLine = matcher.group(1) + matcher.group(2) + ":" + matcher.group(3); getLog().debug("rebuild line = " + sLine); // extract informations pattern = Pattern.compile(":"); String[] items = pattern.split(sLine); String file, line, rule, comment, severity; file = items.length > 0 ? items[0] : ""; line = items.length > 1 ? items[1] : ""; rule = items.length > 2 ? items[2] : ""; comment = items.length > 3 ? items[3] : ""; severity = "warning"; if (bWinPath) { StringBuilder s = new StringBuilder(file); s.setCharAt(1, ':'); file = s.toString(); } // output Xml errors try { // handle <file/> tags if (!file.equals(lastfile)) { if (!StringUtils.isEmpty(lastfile)) { out.writeBytes("\t</file>\n"); } out.writeBytes("\t<file name=\"" + file + "\">\n"); lastfile = file; } out.writeBytes("\t\t<error line=\"" + line + "\" severity=\"" + severity + "\" message=\"" + comment + "\" source=\"" + rule + "\"/>\n"); } catch (IOException e) { getLog().error("Vera++ xml report write failure"); } } } } }; return outErrFilter; }
From source file:de.huxhorn.lilith.swing.MainFrame.java
public ViewContainer<?> resolveViewContainer(File dataFile) { { // logging/*w ww .j av a2 s . co m*/ Map<EventSource<LoggingEvent>, ViewContainer<LoggingEvent>> views = loggingEventViewManager.getViews(); for (Map.Entry<EventSource<LoggingEvent>, ViewContainer<LoggingEvent>> current : views.entrySet()) { ViewContainer<LoggingEvent> view = current.getValue(); EventWrapperViewPanel<LoggingEvent> defaultView = view.getDefaultView(); EventSource<LoggingEvent> es = defaultView.getEventSource(); if (es != null) { Buffer<EventWrapper<LoggingEvent>> buffer = es.getBuffer(); if (buffer instanceof CodecFileBuffer) { CodecFileBuffer cfb = (CodecFileBuffer) buffer; if (dataFile.equals(cfb.getDataFile())) { return view; } } } } } { // access Map<EventSource<AccessEvent>, ViewContainer<AccessEvent>> views = accessEventViewManager.getViews(); for (Map.Entry<EventSource<AccessEvent>, ViewContainer<AccessEvent>> current : views.entrySet()) { ViewContainer<AccessEvent> view = current.getValue(); EventWrapperViewPanel<AccessEvent> defaultView = view.getDefaultView(); EventSource<AccessEvent> es = defaultView.getEventSource(); if (es != null) { Buffer<EventWrapper<AccessEvent>> buffer = es.getBuffer(); if (buffer instanceof CodecFileBuffer) { CodecFileBuffer cfb = (CodecFileBuffer) buffer; if (dataFile.equals(cfb.getDataFile())) { return view; } } } } } return null; }
From source file:org.opendatakit.briefcase.util.TransferFromODK.java
@Override public boolean doAction() { boolean allSuccessful = true; for (FormStatus fs : formsToTransfer) { boolean isSuccessful = true; try {/*w w w.ja v a2 s . co m*/ if (terminationFuture.isCancelled()) { fs.setStatusString("aborted. Skipping fetch of form and submissions...", true); EventBus.publish(new FormStatusEvent(fs)); return false; } BriefcaseFormDefinition briefcaseLfd = doResolveOdkCollectFormDefinition(fs); if (briefcaseLfd == null) { allSuccessful = isSuccessful = false; continue; } OdkCollectFormDefinition odkFormDef = (OdkCollectFormDefinition) fs.getFormDefinition(); File odkFormDefFile = odkFormDef.getFormDefinitionFile(); final String odkFormName = odkFormDefFile.getName().substring(0, odkFormDefFile.getName().lastIndexOf(".")); DatabaseUtils formDatabase = null; try { formDatabase = new DatabaseUtils( FileSystemUtils.getFormDatabase(briefcaseLfd.getFormDirectory())); File destinationFormInstancesDir; try { destinationFormInstancesDir = FileSystemUtils .getFormInstancesDirectory(briefcaseLfd.getFormDirectory()); } catch (FileSystemException e) { e.printStackTrace(); allSuccessful = isSuccessful = false; fs.setStatusString("unable to create instances folder: " + e.getMessage(), false); EventBus.publish(new FormStatusEvent(fs)); continue; } // we have the needed directory structure created... fs.setStatusString("preparing to retrieve instance data", true); EventBus.publish(new FormStatusEvent(fs)); // construct up the list of folders that might have ODK form data. File odkFormInstancesDir = new File(odkFormDefFile.getParentFile().getParentFile(), "instances"); // rely on ODK naming conventions to identify form data files... File[] odkFormInstanceDirs = odkFormInstancesDir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { boolean beginsWithFormName = pathname.getName().startsWith(odkFormName); if (!beginsWithFormName) return false; // skip the separator character, as it varies between 1.1.5, 1.1.6 and 1.1.7 String afterName = pathname.getName().substring(odkFormName.length() + 1); // aftername should be a reasonable date though we allow extra stuff at the end... // protects against someone having "formname" and "formname_2" // and us mistaking "formname_2_2009-01-02_15_10_03" as containing // instance data for "formname" instead of "formname_2" boolean outcome = afterName .matches("^[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}-[0-9]{2}-[0-9]{2}.*"); return outcome; } }); if (odkFormInstanceDirs != null) { int instanceCount = 1; for (File dir : odkFormInstanceDirs) { if (terminationFuture.isCancelled()) { allSuccessful = isSuccessful = false; fs.setStatusString("aborting retrieving submissions...", true); EventBus.publish(new FormStatusEvent(fs)); return false; } // 1.1.8 -- submission is saved as submission.xml. // full instance data is stored as directoryName.xml (as is the convention in 1.1.5, 1.1.7) // File fullXml = new File(dir, dir.getName() + ".xml"); File xml = new File(dir, "submission.xml"); if (!xml.exists() && fullXml.exists()) { xml = fullXml; // e.g., 1.1.5, 1.1.7 } // this is a hack added to support easier generation of large test cases where we // copy a single instance directory repeatedly. Normally the xml submission file // has the name of the enclosing directory, but if you copy directories, this won't // be the case. In this instance, if there is one xml file in the directory, // rename it to match the directory name. if (!xml.exists()) { File[] xmlFiles = dir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".xml"); } }); if (xmlFiles.length == 1) { try { FileUtils.moveFile(xmlFiles[0], xml); } catch (IOException e) { e.printStackTrace(); allSuccessful = isSuccessful = false; fs.setStatusString("unable to rename form instance xml: " + e.getMessage(), false); EventBus.publish(new FormStatusEvent(fs)); continue; } } } if (xml.exists()) { // OK, we can copy the directory off... // Briefcase instances directory name is arbitrary. // Rename the xml within that to always be "submission.xml" // to remove the correspondence to the directory name. File scratchInstance = FileSystemUtils .getFormSubmissionDirectory(destinationFormInstancesDir, dir.getName()); String safeName = scratchInstance.getName(); int i = 2; while (scratchInstance.exists()) { String[] contents = scratchInstance.list(); if (contents == null || contents.length == 0) break; scratchInstance = new File(destinationFormInstancesDir, safeName + "-" + Integer.toString(i)); i++; } try { FileUtils.copyDirectory(dir, scratchInstance); } catch (IOException e) { e.printStackTrace(); allSuccessful = isSuccessful = false; fs.setStatusString("unable to copy saved instance: " + e.getMessage(), false); EventBus.publish(new FormStatusEvent(fs)); continue; } if (xml.equals(fullXml)) { // need to rename File odkSubmissionFile = new File(scratchInstance, fullXml.getName()); File scratchSubmissionFile = new File(scratchInstance, "submission.xml"); try { FileUtils.moveFile(odkSubmissionFile, scratchSubmissionFile); } catch (IOException e) { e.printStackTrace(); allSuccessful = isSuccessful = false; fs.setStatusString("unable to rename submission file to submission.xml: " + e.getMessage(), false); EventBus.publish(new FormStatusEvent(fs)); continue; } } else { // delete the full xml file (keep only the submission.xml) File odkSubmissionFile = new File(scratchInstance, fullXml.getName()); odkSubmissionFile.delete(); } fs.setStatusString(String.format("retrieving (%1$d)", instanceCount), true); EventBus.publish(new FormStatusEvent(fs)); ++instanceCount; } } } } catch (FileSystemException e) { e.printStackTrace(); allSuccessful = isSuccessful = false; fs.setStatusString("unable to open form database: " + e.getMessage(), false); EventBus.publish(new FormStatusEvent(fs)); continue; } finally { if (formDatabase != null) { try { formDatabase.close(); } catch (SQLException e) { e.printStackTrace(); allSuccessful = isSuccessful = false; fs.setStatusString("unable to close form database: " + e.getMessage(), false); EventBus.publish(new FormStatusEvent(fs)); continue; } } } } finally { if (isSuccessful) { fs.setStatusString("SUCCESS!", true); EventBus.publish(new FormStatusEvent(fs)); } else { fs.setStatusString("FAILED.", true); EventBus.publish(new FormStatusEvent(fs)); } } } return allSuccessful; }
From source file:org.cirdles.chroni.FilePickerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTheme(android.R.style.Theme_Holo); // Set the view to be shown if the list is empty LayoutInflater inflator = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View emptyView = inflator.inflate(R.layout.file_picker_empty_view, null); ((ViewGroup) getListView().getParent()).addView(emptyView); getListView().setEmptyView(emptyView); // adds a RelativeLayout to wrap the listView so that a button can be placed at the bottom RelativeLayout outerLayout = (RelativeLayout) inflator.inflate(R.layout.file_picker_regular_view, null); ((ViewGroup) getListView().getParent()).addView(outerLayout); // sets the margin for the listView so that the bottom item isn't covered FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); params.setMargins(0, 0, 0, 100);/*from w ww . j a va 2 s . co m*/ getListView().setLayoutParams(params); // defines the action for the bottom button Button previousFolderButton = (Button) findViewById(R.id.filePickerPreviousButton); previousFolderButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // moves to the previous directory (if it exists) and refreshes the list of files if (mainDirectory.getParentFile() != null) { mainDirectory = mainDirectory.getParentFile(); refreshFilesList(); // goes through and remo any stubborn delete imageViews ViewGroup list = getListView(); int number = list.getChildCount(); // gets rid of all the delete images for (int i = 0; i < number; i++) { View child = list.getChildAt(i); View checkbox = child.findViewById(R.id.checkBoxFilePicker); checkbox.setVisibility(View.GONE); } // sets the action bar at the top so that it tells the user what the current directory is actionBar = getActionBar(); if (actionBar != null) actionBar.setTitle("/" + mainDirectory.getName()); } // if in delete mode or move mode, resets back to normal mode if (inDeleteMode) toggleDelete(); if (inMovePickMode) toggleMove(false); // pass false, not actually executing the move } }); // defines what happens to a list item on a long press getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, final View view, int position, long id) { // stores the address of the file/folder that has been chosen final File chosenFile = (File) parent.getItemAtPosition(position); if (!choosingDirectory) { // only gives options if the chosen file is NOT a directory if (!chosenFile.isDirectory()) { // brings up a Dialog box and asks the user if they want to copy or delete the file CharSequence[] options = { "Copy", "Move", "Delete" }; // the user's options new AlertDialog.Builder(FilePickerActivity.this) .setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { // copy has been chosen // resets cutFiles if it contains files if (cutFiles != null) cutFiles = null; copiedFile = chosenFile; Toast.makeText(FilePickerActivity.this, "File Copied!", Toast.LENGTH_SHORT).show(); // sets the pasteButton's visibility to visible once the file has been copied Button pasteButton = (Button) findViewById(R.id.filePickerPasteButton); pasteButton.setVisibility(View.VISIBLE); dialog.dismiss(); } else if (which == 1) { // move has been chosen // resets copiedFile if it has a file in it if (copiedFile != null) copiedFile = null; cutFiles = new ArrayList<>(); cutFiles.add(chosenFile); Toast.makeText(FilePickerActivity.this, "File Copied!", Toast.LENGTH_SHORT).show(); // sets the pasteButton's visibility to visible once the file has been copied Button pasteButton = (Button) findViewById(R.id.filePickerPasteButton); pasteButton.setVisibility(View.VISIBLE); dialog.dismiss(); } else if (which == 2) { // delete has been chosen // shows a new dialog asking if the user would like to delete the file or not new AlertDialog.Builder(FilePickerActivity.this) .setMessage("Are you sure you want to delete this file?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // if deleting the currently copied file, un-copy it if (copiedFile != null && chosenFile.equals(copiedFile)) { copiedFile = null; Button pasteButton = (Button) findViewById( R.id.filePickerPasteButton); pasteButton.setVisibility(View.GONE); } // deletes the file and updates the adapter chosenFile.delete(); mAdapter.remove(chosenFile); dialog.dismiss(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).show(); dialog.dismiss(); } } }).show(); } else if (chosenFile.list().length == 0) { // can only delete directory if it's empty // brings up a Dialog box and asks the user if they want to copy or delete the file CharSequence[] options = { "Delete" }; // the user's options new AlertDialog.Builder(FilePickerActivity.this) .setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // shows a new dialog asking if the user would like to delete the file or not new AlertDialog.Builder(FilePickerActivity.this) .setMessage("Are you sure you want to delete this file?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // if deleting a currently copied or cut file, un-copy it if ((copiedFile != null && chosenFile.equals(copiedFile)) || (cutFiles != null && cutFiles.contains(chosenFile))) { // resets the copied/cut file(s) if (copiedFile != null) copiedFile = null; if (cutFiles != null) cutFiles = null; // and gets rid of the paste button on the bottom Button pasteButton = (Button) findViewById( R.id.filePickerPasteButton); pasteButton.setVisibility(View.GONE); } // deletes the file and updates the adapter chosenFile.delete(); mAdapter.remove(chosenFile); Toast.makeText(FilePickerActivity.this, "File Deleted!", Toast.LENGTH_SHORT).show(); dialog.dismiss(); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).show(); } }).show(); } } return true; } }); // Obtain content from the current intent for later use intentContent = getIntent().getStringExtra("Default_Directory"); // Set initial directory if it hasn't been already defined if (mainDirectory == null) { mainDirectory = Environment.getExternalStorageDirectory(); // Takes user to root directory folder // Sets the initial directory based on what file the user is looking for (Aliquot or Report Settings) if (intentContent.contentEquals("Aliquot_Directory") || intentContent.contentEquals("From_Aliquot_Directory")) mainDirectory = new File(mainDirectory + "/CHRONI/Aliquot"); // Takes user to the Aliquot folder // Report Settings Menu if coming from a Dropdown Menu or the Report Settings Menu else if (intentContent.contentEquals("Report_Settings_Directory") || intentContent.contentEquals("From_Report_Directory")) mainDirectory = new File(mainDirectory + "/CHRONI/Report Settings"); else if (intentContent.contentEquals("Parent_Directory")) choosingDirectory = true; // choosing a directory rather than a file // if none of these are true, the directory will be CHRONI's parent directory (externalStorageDirectory) } // sets the action bar at the top so that it tells the user what the current directory is actionBar = getActionBar(); if (actionBar != null) actionBar.setTitle("/" + mainDirectory.getName()); // Initialize the ArrayList mFiles = new ArrayList<>(); // Set the ListAdapter mAdapter = new FilePickerListAdapter(this, mFiles); setListAdapter(mAdapter); // Initialize the extensions array to allow any file extensions acceptedFileExtensions = new String[] {}; // Get intent extras if (getIntent().hasExtra(EXTRA_SHOW_HIDDEN_FILES)) { mShowHiddenFiles = getIntent().getBooleanExtra(EXTRA_SHOW_HIDDEN_FILES, false); } if (getIntent().hasExtra(EXTRA_ACCEPTED_FILE_EXTENSIONS)) { ArrayList<String> collection = getIntent().getStringArrayListExtra(EXTRA_ACCEPTED_FILE_EXTENSIONS); acceptedFileExtensions = collection.toArray(new String[collection.size()]); } // if no file permissions, asks for them if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE }, 1); } }
From source file:de.mkrtchyan.recoverytools.ScriptManagerFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mRootView = inflater.inflate(R.layout.fragment_script_manager, container, false); mFileNameAdapter = new ArrayAdapter<>(mContext, R.layout.custom_list_item); mFileList = new ArrayList<>(); mQueue = (ListView) mRootView.findViewById(R.id.lvQueue); mQueue.setAdapter(mFileNameAdapter); mQueue.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override/* ww w . j ava 2 s .c o m*/ public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mFileList.remove(position); mFileNameAdapter.clear(); for (File i : mFileList) { mFileNameAdapter.add(i.getName()); } } }); if (mStartFile != null) { if (mStartFile.exists()) { if (Common.stringEndsWithArray(mStartFile.getName(), mAllowedEXT)) { addFileToQueue(mStartFile); } else { Toast.makeText(mContext, R.string.wrong_format, Toast.LENGTH_SHORT).show(); } } } AppCompatButton AddZip = (AppCompatButton) mRootView.findViewById(R.id.addZip); AddZip.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mFileChooser = new FileChooserDialog(mContext); File startFolder = new File("/"); if (mFileList.size() > 0) { startFolder = mFileList.get(mFileList.size() - 1); if (startFolder.isFile()) { startFolder = startFolder.getParentFile(); } } mFileChooser.setStartFolder(startFolder); mFileChooser.setOnFileChooseListener(new FileChooserDialog.OnFileChooseListener() { @Override public void OnFileChoose(File file) { addFileToQueue(file); } }); mFileChooser.setAllowedEXT(mAllowedEXT); mFileChooser.setBrowseUpAllowed(true); mFileChooser.setWarn(false); mFileChooser.show(); } }); AppCompatButton FlashZip = (AppCompatButton) mRootView.findViewById(R.id.bFlashZip); FlashZip.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AppCompatCheckBox cbBakSystem = (AppCompatCheckBox) mRootView.findViewById(R.id.cbBackupSystem); AppCompatCheckBox cbBakData = (AppCompatCheckBox) mRootView.findViewById(R.id.cbBackupData); AppCompatCheckBox cbBakCache = (AppCompatCheckBox) mRootView.findViewById(R.id.cbBackupCache); AppCompatCheckBox cbBakRecovery = (AppCompatCheckBox) mRootView.findViewById(R.id.cbBackupRecovery); AppCompatCheckBox cbBakBoot = (AppCompatCheckBox) mRootView.findViewById(R.id.cbBackupBoot); AppCompatCheckBox cbSkipMD5 = (AppCompatCheckBox) mRootView.findViewById(R.id.cbSkipMD5); AppCompatEditText etBakName = (AppCompatEditText) mRootView.findViewById(R.id.etBackupName); AppCompatCheckBox cbWipeCache = (AppCompatCheckBox) mRootView.findViewById(R.id.cbWipeCache); AppCompatCheckBox cbWipeDalvik = (AppCompatCheckBox) mRootView.findViewById(R.id.cbWipeDalvik); AppCompatCheckBox cbWipeData = (AppCompatCheckBox) mRootView.findViewById(R.id.cbWipeData); final StringBuilder command = new StringBuilder(); command.append("echo #####Script created by Rashr#####;"); if (cbBakBoot.isChecked() || cbBakCache.isChecked() || cbBakData.isChecked() || cbBakRecovery.isChecked() || cbBakSystem.isChecked()) { command.append("backup "); if (cbBakBoot.isChecked()) command.append("B"); if (cbBakCache.isChecked()) command.append("C"); if (cbBakData.isChecked()) command.append("D"); if (cbBakRecovery.isChecked()) command.append("R"); if (cbBakSystem.isChecked()) command.append("S"); if (cbSkipMD5.isChecked()) command.append("M"); CharSequence BackupName = etBakName.getText(); if (BackupName != null && !BackupName.equals("")) { command.append(" "); command.append(BackupName); } command.append(CMD_END); } if (cbWipeCache.isChecked()) command.append("wipe cache;"); if (cbWipeDalvik.isChecked()) command.append("wipe dalvik;"); if (cbWipeData.isChecked()) command.append("wipe data;"); for (File i : mFileList) { command.append("install "); command.append(i.getAbsolutePath()); command.append(CMD_END); } if (!command.toString().equals("")) { String commands = ""; int index = 0; for (String i : command.toString().split(CMD_END)) { if (!i.equals("")) { if (index > 0) { commands += index++ + ". " + i + "\n"; } else { index++; } } } final AlertDialog.Builder CommandsPreview = new AlertDialog.Builder(mContext); CommandsPreview.setTitle(R.string.recovery_script_review); CommandsPreview.setPositiveButton(R.string.run, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { for (String split : command.toString().split(";")) { if (!split.equals("")) { mShell.execCommand( "echo " + split + " >> /cache/recovery/openrecoveryscript"); } } new Toolbox(mShell).reboot(Toolbox.REBOOT_RECOVERY); } catch (Exception e) { e.printStackTrace(); } } }); CommandsPreview.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); CommandsPreview.setMessage(commands); CommandsPreview.show(); } else { Toast.makeText(mContext, "No job to do :)", Toast.LENGTH_LONG).show(); } } }); return mRootView; }
From source file:org.apache.geode.internal.cache.GemFireCacheImpl.java
public URL getCacheXmlURL() { if (this.getMyId().getVmKind() == DistributionManager.LOCATOR_DM_TYPE) { return null; }//from w ww . j a v a 2 s. co m File xmlFile = testCacheXml; if (xmlFile == null) { xmlFile = this.system.getConfig().getCacheXmlFile(); } if ("".equals(xmlFile.getName())) { return null; } URL url = null; if (!xmlFile.exists() || !xmlFile.isFile()) { // do a resource search String resource = xmlFile.getPath(); resource = resource.replaceAll("\\\\", "/"); if (resource.length() > 1 && resource.startsWith("/")) { resource = resource.substring(1); } url = ClassPathLoader.getLatest().getResource(getClass(), resource); } else { try { url = xmlFile.toURL(); } catch (IOException ex) { throw new CacheXmlException(LocalizedStrings.GemFireCache_COULD_NOT_CONVERT_XML_FILE_0_TO_AN_URL .toLocalizedString(xmlFile), ex); } } if (url == null) { File defaultFile = DistributionConfig.DEFAULT_CACHE_XML_FILE; if (!xmlFile.equals(defaultFile)) { if (!xmlFile.exists()) { throw new CacheXmlException( LocalizedStrings.GemFireCache_DECLARATIVE_CACHE_XML_FILERESOURCE_0_DOES_NOT_EXIST .toLocalizedString(xmlFile)); } else /* if (!xmlFile.isFile()) */ { throw new CacheXmlException(LocalizedStrings.GemFireCache_DECLARATIVE_XML_FILE_0_IS_NOT_A_FILE .toLocalizedString(xmlFile)); } } } return url; }
From source file:fr.amap.lidar.amapvox.gui.MainFrameController.java
public TaskElement addFileToTaskList(final File file) { ObservableList<TaskElement> taskElements = listViewTaskList.getItems(); int idxCfgToReplace = -1; //don't add the task if it is already inside the task list int index = 0; for (TaskElement taskElement : taskElements) { if (file.equals(taskElement.getLinkedFile())) { idxCfgToReplace = index;//from w w w . j av a 2 s . com break; } index++; } //get the task type String type; try { type = Configuration.readType(file); } catch (JDOMException | IOException ex) { showErrorDialog(ex); return null; } TaskElement element = null; switch (type) { case "voxelisation-ALS": element = new TaskElement(file, new ServiceProvider() { @Override public Service provide() { return new ALSVoxelizationService(file); } }); //element = new TaskElement(s, file); element.setTaskIcon(TaskElement.VOXELIZATION_IMG); element.addTaskListener(new TaskAdapter() { @Override public void onSucceeded(Service service) { Platform.runLater(new Runnable() { @Override public void run() { File outputFile = ((ALSVoxelizationService) service).getValue(); if (outputFile != null) { addFileToProductsList(outputFile); } } }); } }); break; case "voxelisation-TLS": final TLSVoxCfg tLSVoxCfg = new TLSVoxCfg(); try { tLSVoxCfg.readConfiguration(file); } catch (Exception ex) { showErrorDialog(ex); return null; } switch (tLSVoxCfg.getInputType()) { case RSP_PROJECT: element = new TaskElement(file, new ServiceProvider() { @Override public Service provide() { if (tlsVoxNbThreads == -1) { return new RSPVoxelizationService(file, (int) sliderRSPCoresToUse.getValue()); } else { return new RSPVoxelizationService(file, tlsVoxNbThreads); } } }); element.setTaskIcon(TaskElement.VOXELIZATION_IMG); element.addTaskListener(new TaskAdapter() { @Override public void onSucceeded(Service service) { Platform.runLater(new Runnable() { @Override public void run() { List<File> voxFiles = ((RSPVoxelizationService) service).getValue(); for (File voxFile : voxFiles) { addFileToProductsList(voxFile); } } }); } }); break; case RXP_SCAN: element = new TaskElement(file, new ServiceProvider() { @Override public Service provide() { return new RXPVoxelizationService(file); } }); element.setTaskIcon(TaskElement.VOXELIZATION_IMG); element.addTaskListener(new TaskAdapter() { @Override public void onSucceeded(Service service) { Platform.runLater(new Runnable() { @Override public void run() { addFileToProductsList(tLSVoxCfg.getOutputFile()); } }); } }); break; case PTG_PROJECT: element = new TaskElement(file, new ServiceProvider() { @Override public Service provide() { if (tlsVoxNbThreads == -1) { return new PTGVoxelizationService(file, (int) sliderRSPCoresToUse.getValue()); } else { return new PTGVoxelizationService(file, tlsVoxNbThreads); } } }); element.setTaskIcon(TaskElement.VOXELIZATION_IMG); element.addTaskListener(new TaskAdapter() { @Override public void onSucceeded(Service service) { Platform.runLater(new Runnable() { @Override public void run() { List<File> voxFiles = ((PTGVoxelizationService) service).getValue(); for (File voxFile : voxFiles) { addFileToProductsList(voxFile); } } }); } }); break; case PTX_PROJECT: element = new TaskElement(file, new ServiceProvider() { @Override public Service provide() { if (tlsVoxNbThreads == -1) { return new PTXVoxelizationService(file, (int) sliderRSPCoresToUse.getValue()); } else { return new PTXVoxelizationService(file, tlsVoxNbThreads); } } }); element.setTaskIcon(TaskElement.VOXELIZATION_IMG); element.addTaskListener(new TaskAdapter() { @Override public void onSucceeded(Service service) { Platform.runLater(new Runnable() { @Override public void run() { List<File> voxFiles = ((PTXVoxelizationService) service).getValue(); for (File voxFile : voxFiles) { addFileToProductsList(voxFile); } } }); } }); break; } break; case "transmittance": /*TransmittanceCfg transCfg = new TransmittanceCfg(new TransmittanceParameters()); try { transCfg.readConfiguration(file); } catch (JDOMException | IOException ex) { showErrorDialog(ex); return null; }*/ element = new TaskElement(file, new ServiceProvider() { @Override public Service provide() { return new TransmittanceSimService(file); } }); element.setTaskIcon(TaskElement.TRANSMITTANCE_IMG); element.addTaskListener(new TaskAdapter() { @Override public void onSucceeded(Service service) { Platform.runLater(new Runnable() { @Override public void run() { //if(transCfg.getParameters().isGenerateBitmapFile()){ List<File> bitmapFiles = ((TransmittanceSimService) service).getValue() .getOutputBitmapFiles(); if (bitmapFiles != null) { for (File file : bitmapFiles) { addFileToProductsList(file); } } //} } }); } }); break; case "LAI2000": case "LAI2200": element = new TaskElement(file, new ServiceProvider() { @Override public Service provide() { return new Lai2xxxSimService(file); } }); element.setTaskIcon(TaskElement.CANOPEE_ANALYZER_IMG); break; case "Hemi-Photo": element = new TaskElement(file, new ServiceProvider() { @Override public Service provide() { return new HemiPhotoSimService(file); } }); element.setTaskIcon(TaskElement.HEMI_IMG); element.addTaskListener(new TaskAdapter() { @Override public void onSucceeded(Service service) { Platform.runLater(new Runnable() { @Override public void run() { File outputFile = ((HemiPhotoSimService) service).getValue(); if (outputFile != null) { addFileToProductsList(outputFile); } } }); } }); break; case "merging": element = new TaskElement(file, new ServiceProvider() { @Override public Service provide() { return new VoxFileMergingService(file); } }); element.setTaskIcon(TaskElement.MISC_IMG); element.addTaskListener(new TaskAdapter() { @Override public void onSucceeded(Service service) { Platform.runLater(new Runnable() { @Override public void run() { File outputFile = ((VoxFileMergingService) service).getValue(); if (outputFile != null) { addFileToProductsList(outputFile); } } }); } }); break; case "butterfly-removing": element = new TaskElement(file, new ServiceProvider() { @Override public Service provide() { return new ButterflyRemoverService(file); } }); element.setTaskIcon(TaskElement.MISC_IMG); element.addTaskListener(new TaskAdapter() { @Override public void onSucceeded(Service service) { Platform.runLater(new Runnable() { @Override public void run() { File outputFile = ((ButterflyRemoverService) service).getValue(); if (outputFile != null) { addFileToProductsList(outputFile); } } }); } }); break; } if (element != null) { if (idxCfgToReplace != -1) { if (listViewTaskList.getItems().get(idxCfgToReplace) .getButtonType() == TaskElement.ButtonType.CANCEL) { Alert alert = new Alert(AlertType.WARNING); alert.setContentText("This task is currently running, cancel the operation first."); alert.show(); } else { listViewTaskList.getItems().set(idxCfgToReplace, element); } } else { listViewTaskList.getItems().add(element); } element.addTaskListener(new TaskAdapter() { @Override public void onFailed(Exception ex) { showErrorDialog(ex); } }); } return element; }