Example usage for java.io File equals

List of usage examples for java.io File equals

Introduction

In this page you can find the example usage for java.io File equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Tests this abstract pathname for equality with the given object.

Usage

From source file:org.cloudifysource.quality.iTests.test.cli.cloudify.cloud.templates.TemplateCreator.java

public File createPropertiesFileForTemplate(final TemplateDetails template) {
    final Properties props = new Properties();
    if (template.getUploadDirName() != null) {
        props.put(UPLOAD_PROPERTY_NAME, template.getUploadDirName());
    }//www.j av a 2 s  .  c om
    File templateFolder = template.getTemplateFolder();
    File templatePropsFile = template.getTemplatePropertiesFile();
    if (templatePropsFile == null) {
        final String templateFileName = template.getTemplateFile().getName();
        final int templateFileNamePrefixEndIndex = templateFileName.indexOf(".");
        final String templateFileNamePrefix = templateFileName.substring(0, templateFileNamePrefixEndIndex);
        final String proeprtiesFileName = templateFileNamePrefix + DSLUtils.PROPERTIES_FILE_SUFFIX;
        templatePropsFile = new File(templateFolder, proeprtiesFileName);

    } else {
        if (!templatePropsFile.exists()) {
            templatePropsFile = new File(templateFolder, templatePropsFile.getName());
        } else if (!templateFolder.equals(templatePropsFile.getParentFile())) {
            try {
                FileUtils.copyFileToDirectory(templatePropsFile, templateFolder);
            } catch (IOException e) {
                Assert.fail("failed to copy properties file [" + templatePropsFile.getAbsolutePath()
                        + "] to directory [" + templateFolder.getAbsolutePath() + "]. error was: "
                        + e.getMessage());
            }
        }
    }
    try {
        IOUtils.writePropertiesToFile(props, templatePropsFile);
    } catch (IOException e) {
        Assert.fail("failed to write properties to file [" + templatePropsFile.getAbsolutePath());
    }
    return templatePropsFile;
}

From source file:github.daneren2005.dsub.view.CacheLocationPreference.java

@Override
protected void onBindDialogView(View view) {
    super.onBindDialogView(view);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        view.setLayoutParams(new ViewGroup.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                android.view.ViewGroup.LayoutParams.WRAP_CONTENT));

        final EditText editText = (EditText) view.findViewById(android.R.id.edit);
        ViewGroup vg = (ViewGroup) editText.getParent();

        LinearLayout cacheButtonsWrapper = (LinearLayout) LayoutInflater.from(context)
                .inflate(R.layout.cache_location_buttons, vg, true);
        Button internalLocation = (Button) cacheButtonsWrapper.findViewById(R.id.location_internal);
        Button externalLocation = (Button) cacheButtonsWrapper.findViewById(R.id.location_external);

        File[] dirs;/*from   w  w w. jav  a 2 s.c o m*/
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            dirs = context.getExternalMediaDirs();
        } else {
            dirs = ContextCompat.getExternalFilesDirs(context, null);
        }

        // Past 5.0 we can query directly for SD Card
        File internalDir = null, externalDir = null;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            for (int i = 0; i < dirs.length; i++) {
                try {
                    if (dirs[i] != null) {
                        if (Environment.isExternalStorageRemovable(dirs[i])) {
                            if (externalDir != null) {
                                externalDir = dirs[i];
                            }
                        } else {
                            internalDir = dirs[i];
                        }

                        if (internalDir != null && externalDir != null) {
                            break;
                        }
                    }
                } catch (Exception e) {
                    Log.e(TAG, "Failed to check if is external", e);
                }
            }
        }

        // Before 5.0, we have to guess.  Most of the time the SD card is last
        if (externalDir == null) {
            for (int i = dirs.length - 1; i >= 0; i--) {
                if (dirs[i] != null) {
                    externalDir = dirs[i];
                    break;
                }
            }
        }
        if (internalDir == null) {
            for (int i = 0; i < dirs.length; i++) {
                if (dirs[i] != null) {
                    internalDir = dirs[i];
                    break;
                }
            }
        }
        final File finalInternalDir = new File(internalDir, "music");
        final File finalExternalDir = new File(externalDir, "music");

        final EditText editTextBox = (EditText) view.findViewById(android.R.id.edit);
        if (finalInternalDir != null && (finalInternalDir.exists() || finalInternalDir.mkdirs())) {
            internalLocation.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String path = finalInternalDir.getPath();
                    editTextBox.setText(path);
                }
            });
        } else {
            internalLocation.setEnabled(false);
        }

        if (finalExternalDir != null && !finalInternalDir.equals(finalExternalDir)
                && (finalExternalDir.exists() || finalExternalDir.mkdirs())) {
            externalLocation.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String path = finalExternalDir.getPath();
                    editTextBox.setText(path);
                }
            });
        } else {
            externalLocation.setEnabled(false);
        }
    }
}

From source file:com.snowplowanalytics.snowplow.collectors.clojure.SnowplowAccessLogValve.java

/**
 * Move a current but rotated log file back to the unrotated
 * one. Needed if date stamp inclusion is deferred to rotation
 * time./*w  w w  . j a va2s  .com*/
 */
private void restore() {
    File newLogFile = getLogFile(false);
    File rotatedLogFile = getLogFile(true);
    if (rotatedLogFile.exists() && !newLogFile.exists() && !rotatedLogFile.equals(newLogFile)) {
        try {
            if (!rotatedLogFile.renameTo(newLogFile)) {
                log.error(sm.getString("accessLogValve.renameFail", rotatedLogFile, newLogFile));
            }
        } catch (Throwable e) {
            ExceptionUtils.handleThrowable(e);
            log.error(sm.getString("accessLogValve.renameFail", rotatedLogFile, newLogFile), e);
        }
    }
}

From source file:net.pandoragames.far.ui.UIBean.java

/**
 * Cycles through the file list and renames each file to the name specified in 
 * the "newName" property, unless the file is not selected or "newName" is empty.
 * This operation will only change the file name, not the files path. If a file
 * with the desired new name exists, the callback will be used to request user 
 * feedback. If the renaming operation fails for some reason, an error will be
 * written to the respective TargetFile opject. Returns the transformed list of files.
 * @param fileList files to be renamed/*from   w  w  w.  j  a  va  2s.  c  om*/
 * @param callback for user feedback
 * @return transformed list of files
 */
public List<TargetFile> rename(List<TargetFile> fileList, OverwriteFileCallback callback) {
    wasAborted = false;
    messageBox.clear();
    notifyStarted(OperationType.RENAME);
    operationInProgress = OperationType.RENAME;
    lastReplaceForm = null;
    lastFileSet = null;

    // count number of files to be renamed
    int totalExpected = 0;
    for (TargetFile file : fileList) {
        if (file.isSelected() && file.getNewName() != null && file.getNewName().length() > 0
                && !file.getName().equals(file.getNewName())) {
            totalExpected++;
        }
    }

    List<TargetFile> resultList = new ArrayList<TargetFile>();
    int counter = 0;
    int renameCounter = 0;
    for (TargetFile file : fileList) {
        if (wasAborted) {
            file.setNewName(null);
            resultList.add(file);
        } else if (file.isSelected() && file.getNewName() != null && file.getNewName().length() > 0
                && !file.getName().equals(file.getNewName())) {
            counter++;
            File newFile = new File(file.getFile().getParentFile(), file.getNewName());
            boolean doRename = true;
            if (newFile.exists()) {
                if (newFile.isFile()) {
                    // on win it may happen that file names are different but files are equal
                    if (!newFile.equals(file.getFile())) {
                        if (callback.askForOverwrite(newFile)) {
                            if (!newFile.delete()) {
                                logger.error("Could not delete " + newFile.getName()
                                        + " for preparation of rename operation");
                                file.error(localizer.localize("message.could-not-rename"));
                                doRename = false;
                            }
                        } else {
                            doRename = false;
                            logger.debug("Skip renaming " + file.getName() + " to " + file.getNewName());
                            file.setNewName(null);
                        }
                    }
                } else {
                    logger.warn("Could not rename " + file.getName() + " to " + newFile.getPath()
                            + " because a directory, device, symlink or other non-file object exists at the same location.");
                    file.error(localizer.localize("message.could-not-rename"));
                    doRename = false;
                }
            }
            if (doRename) {
                if (file.getFile().renameTo(newFile)) {
                    TargetFile result = new TargetFile(newFile);
                    result.setCharacterset(file.getCharacterset());
                    resultList.add(result);
                    renameCounter++;
                    logger.debug("Renamed " + file.getFile().getPath() + " to " + result.getName());
                } else {
                    file.error(localizer.localize("message.could-not-rename"));
                    resultList.add(file);
                    logger.error("Failed renaming " + file.getName() + " to " + file.getNewName());
                }
            } else {
                resultList.add(file);
            }
        } else {
            file.setNewName(null);
            resultList.add(file);
        }
        notifyCount(counter, totalExpected, OperationType.RENAME);
    }
    notifyTerminated(OperationType.RENAME);
    messageBox.info(localizer.localize("message.files-renamed", renameCounter));
    logger.info(renameCounter + " files renamed, " + (counter - renameCounter) + " errors");
    wasAborted = false;
    operationInProgress = OperationType.NONE;
    return resultList;
}

From source file:forge.gui.ImportSourceAnalyzer.java

private void analyzeQuestDataDir(final File root) {
    analyzeDir(root, new Analyzer() {
        @Override//from w  w w . ja va 2  s.c om
        void onFile(final File file) {
            final String filename = file.getName();
            if (StringUtils.endsWithIgnoreCase(filename, ".dat")) {
                final File targetFile = new File(ForgeConstants.QUEST_SAVE_DIR, lcaseExt(filename));
                if (!file.equals(targetFile)) {
                    cb.addOp(OpType.QUEST_DATA, file, targetFile);
                }
            }
        }
    });
}

From source file:org.omegat.filters2.master.FilterMaster.java

/**
 * OmegaT core calls this method to translate a source file.
 * <ul>/*w w w  .java2  s.  c o m*/
 * <li>OmegaT first looks through registered filter instances to find filter(s) that can handle this file.
 * <li>Tests if filter(s) want to handle it.
 * <li>If the filter accepts the file,
 * <li>Filter is asked to process the file.
 * </ul>
 * If no filter is found, that processes this file, we simply copy it to target folder.
 * 
 * @param sourcedir
 *            The folder of the source inFile.
 * @param filename
 *            The name of the source inFile to process (only the part, relative to source folder).
 * @param targetdir
 *            The folder to place the translated inFile to.
 * @param fc
 *            Filter context.
 */
public void translateFile(String sourcedir, String filename, String targetdir, FilterContext fc,
        ITranslateCallback translateCallback) throws IOException, TranslationException {
    LookupInformation lookup = lookupFilter(new File(sourcedir, filename), fc);
    if (lookup == null) {
        // The file is not supported by any of the filters.
        // Copying it
        FileUtils.copyFile(new File(sourcedir, filename), new File(targetdir, filename));
        return;
    }

    File inFile = new File(sourcedir, filename).getCanonicalFile();
    File outFile = new File(targetdir, getTargetForSource(filename, lookup, fc.getTargetLang()))
            .getCanonicalFile();

    if (inFile.equals(outFile)) {
        throw new TranslationException(StringUtil
                .format(OStrings.getString("FILTERMASTER_ERROR_SRC_TRG_SAME_FILE"), inFile.getPath()));
    }

    fc.setInEncoding(lookup.outFilesInfo.getSourceEncoding());
    fc.setOutEncoding(lookup.outFilesInfo.getTargetEncoding());

    IFilter filterObject = lookup.filterObject;
    try {
        filterObject.translateFile(inFile, outFile, lookup.config, fc, translateCallback);
    } catch (Exception ex) {
        Log.log(ex);
    }
}

From source file:forge.gui.ImportSourceAnalyzer.java

private void analyzeQuestDir(final File root) {
    analyzeDir(root, new Analyzer() {
        @Override//from ww  w  .  j av a 2s. c o  m
        void onFile(final File file) {
            final String filename = file.getName();
            if ("all-prices.txt".equalsIgnoreCase(filename)) {
                final File targetFile = new File(ForgeConstants.DB_DIR, filename.toLowerCase(Locale.ENGLISH));
                if (!file.equals(targetFile)) {
                    cb.addOp(OpType.DB_FILE, file, targetFile);
                }
            }
        }

        @Override
        boolean onDir(final File dir) {
            if ("data".equalsIgnoreCase(dir.getName())) {
                analyzeQuestDataDir(dir);
                return true;
            }
            return false;
        }
    });
}

From source file:org.orbisgis.view.map.MapEditor.java

/**
 * The DefaultMapContext property of {@link MapEditorPersistence} has been updated, load this map
 *///  w ww.  j  ava 2  s  . c  o  m
public void onSerialisationMapChange() {
    ViewWorkspace viewWorkspace = Services.getService(ViewWorkspace.class);
    String fileName = mapEditorPersistence.getDefaultMapContext();
    File mapFilePath = new File(viewWorkspace.getMapContextPath(), fileName);
    if (!mapFilePath.exists()) {
        return;
    }
    if (mapElement != null && mapFilePath.equals(mapElement.getMapContextFile())) {
        return;
    }
    MapElement mapElement = new MapElement(mapFilePath);
    BackgroundManager backgroundManager = Services.getService(BackgroundManager.class);
    backgroundManager.backgroundOperation(new ReadMapContextJob(mapElement));
}

From source file:net.sf.nmedit.nomad.core.Nomad.java

public Document setSelectedDocumentByFile(File file) {
    if (file == null)
        return null;

    for (Document d : pageContainer.getDocuments()) {
        if (file.equals(d.getFile())) {
            pageContainer.setSelection(d);
            return d;
        }//  www . ja v a2 s.  com
    }
    return null;
}

From source file:org.apache.jackrabbit.core.data.LocalCache.java

/**
 * This method add file to {@link LocalCache} and tries that file can be
 * added to {@link AsyncUploadCache}. If file is added to
 * {@link AsyncUploadCache} successfully, it sets
 * {@link AsyncUploadResult#setAsyncUpload(boolean)} to true.
 *
 * @param fileName name of the file.//from  w  w  w.j  a  va  2s . com
 * @param src source file.
 * @param tryForAsyncUpload If true it tries to add fileName to
 *            {@link AsyncUploadCache}
 * @return {@link AsyncUploadCacheResult}. This method sets
 *         {@link AsyncUploadResult#setAsyncUpload(boolean)} to true, if
 *         fileName is added to {@link AsyncUploadCache} successfully else
 *         it sets {@link AsyncUploadCacheResult#setAsyncUpload(boolean)} to
 *         false. {@link AsyncUploadCacheResult#getFile()} contains cached
 *         file, if it is added to {@link LocalCache} or original file.
 * @throws IOException
 */
public synchronized AsyncUploadCacheResult store(String fileName, File src, boolean tryForAsyncUpload)
        throws IOException {
    fileName = fileName.replace("\\", "/");
    File dest = getFile(fileName);
    File parent = dest.getParentFile();
    AsyncUploadCacheResult result = new AsyncUploadCacheResult();
    result.setFile(src);
    result.setAsyncUpload(false);
    boolean destExists = false;
    if ((destExists = dest.exists()) || (src.exists() && !dest.exists() && !src.equals(dest)
            && canAdmitFile(src.length()) && (parent.exists() || parent.mkdirs()) && (src.renameTo(dest)))) {
        if (destExists) {
            dest.setLastModified(System.currentTimeMillis());
        }
        cache.put(fileName, dest.length());
        LOG.debug("file [{}] added to local cache.", fileName);
        result.setFile(dest);
        if (tryForAsyncUpload) {
            result.setAsyncUpload(asyncUploadCache.add(fileName).canAsyncUpload());
        }
    }
    cache.tryPurge();
    return result;
}