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:gov.redhawk.core.filemanager.filesystem.JavaFileSystem.java

@Override
public FileInformationType[] list(final String fullPattern) throws FileException, InvalidFileName {
    final int index = fullPattern.lastIndexOf('/');
    final File container;
    if (index > 0) {
        container = new File(this.root, fullPattern.substring(0, index));
    } else {/*from w w w  .  j a  v  a 2  s.  c om*/
        container = this.root;
    }

    final String pattern = fullPattern.substring(index + 1, fullPattern.length());

    final String[] fileNames;

    if (pattern.length() == 0) {
        fileNames = new String[] { "" };
    } else {
        fileNames = container.list(new FilenameFilter() {

            @Override
            public boolean accept(final File dir, final String name) {
                if (!dir.equals(container)) {
                    return false;
                }
                return FilenameUtils.wildcardMatch(name, pattern);
            }
        });
    }

    if (fileNames == null) {
        return new FileInformationType[0];
    }

    final FileInformationType[] retVal = new FileInformationType[fileNames.length];
    for (int i = 0; i < fileNames.length; i++) {
        final FileInformationType fileInfo = new FileInformationType();
        final File file = new File(container, fileNames[i]);
        fileInfo.name = file.getName();
        fileInfo.size = file.length();
        if (file.isFile()) {
            fileInfo.kind = FileType.PLAIN;
        } else {
            fileInfo.kind = FileType.DIRECTORY;
        }
        final Any any = this.orb.create_any();
        any.insert_ulonglong(file.lastModified() / JavaFileSystem.MILLIS_PER_SEC);
        final DataType modifiedTime = new DataType("MODIFIED_TIME", any);

        fileInfo.fileProperties = new DataType[] { modifiedTime };

        retVal[i] = fileInfo;
    }
    return retVal;
}

From source file:edu.lternet.pasta.portal.DesktopCleaner.java

/**
 * Callback method that determines how to process a directory.
 *///from w  w w  .j  a v a 2s  . c om
protected boolean handleDirectory(File directory, int depth, Collection<File> results) {
    boolean result = false;

    /*
     * Don't delete the top-level data directory regardless of how
     * old it is. Only delete the filtered directories below it.
     */
    if (!directory.equals(this.topDirectory)) {

        try {
            FileUtils.deleteDirectory(directory);
            results.add(directory);
        } catch (IOException e) {
            logger.error(e.getMessage());
            e.printStackTrace();
        }
    } else {
        result = true; // true means that this dir should be walked
    }

    return result;
}

From source file:net.sourceforge.subsonic.service.metadata.MetaDataParser.java

private boolean isRoot(File file) {
    SettingsService settings = ServiceLocator.getSettingsService();
    List<MusicFolder> folders = settings.getAllMusicFolders(false, true);
    for (MusicFolder folder : folders) {
        if (file.equals(folder.getPath())) {
            return true;
        }//ww w. j  a  va2  s.  c  om
    }
    return false;
}

From source file:net.sourceforge.vulcan.core.support.AbstractFileStore.java

@Override
public boolean isWorkingCopyLocationInvalid(String location) {
    final File file = new File(location);

    if (file.equals(configRoot) || file.equals(getProjectsRoot())
            || file.getParentFile().equals(getProjectsRoot())) {
        return true;
    }/*from  w  ww  .j av  a 2 s . c om*/
    return false;
}

From source file:com.gitblit.auth.HtpasswdAuthProvider.java

/**
 * Reads the realm file and rebuilds the in-memory lookup tables.
 *//*w  ww .j a  va2 s.c  om*/
protected synchronized void read() {
    boolean forceReload = false;
    File file = getFileOrFolder(KEY_HTPASSWD_FILE, DEFAULT_HTPASSWD_FILE);
    if (!file.equals(htpasswdFile)) {
        this.htpasswdFile = file;
        this.htUsers.clear();
        forceReload = true;
    }

    if (htpasswdFile.exists() && (forceReload || (htpasswdFile.lastModified() != lastModified))) {
        lastModified = htpasswdFile.lastModified();
        htUsers.clear();

        Pattern entry = Pattern.compile("^([^:]+):(.+)");

        Scanner scanner = null;
        try {
            scanner = new Scanner(new FileInputStream(htpasswdFile));
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine().trim();
                if (!line.isEmpty() && !line.startsWith("#")) {
                    Matcher m = entry.matcher(line);
                    if (m.matches()) {
                        htUsers.put(m.group(1), m.group(2));
                    }
                }
            }
        } catch (Exception e) {
            logger.error(MessageFormat.format("Failed to read {0}", htpasswdFile), e);
        } finally {
            if (scanner != null) {
                scanner.close();
            }
        }
    }
}

From source file:com.sat.sonata.MenuActivity.java

private void processPictureWhenReady(final String picturePath) {
    final File pictureFile = new File(picturePath);

    if (pictureFile.exists()) {
        // The picture is ready; process it.
    } else {/* w w  w. j a va 2  s .  co  m*/
        // The file does not exist yet. Before starting the file observer, you
        // can update your UI to let the user know that the application is
        // waiting for the picture (for example, by displaying the thumbnail
        // image and a progress indicator).

        final File parentDirectory = pictureFile.getParentFile();
        FileObserver observer = new FileObserver(parentDirectory.getPath()) {
            // Protect against additional pending events after CLOSE_WRITE is
            // handled.
            private boolean isFileWritten;

            @Override
            public void onEvent(int event, String path) {
                if (!isFileWritten) {
                    // For safety, make sure that the file that was created in
                    // the directory is actually the one that we're expecting.
                    File affectedFile = new File(parentDirectory, path);
                    isFileWritten = (event == FileObserver.CLOSE_WRITE && affectedFile.equals(pictureFile));

                    if (isFileWritten) {
                        stopWatching();

                        // Now that the file is ready, recursively call
                        // processPictureWhenReady again (on the UI thread).
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                processPictureWhenReady(picturePath);
                            }
                        });
                    }
                }
            }
        };
        observer.startWatching();
    }
}

From source file:org.commonjava.maven.ext.cli.CliTest.java

@Test
public void checkTargetMatchesWithRun() throws Exception {
    Cli c = new Cli();
    File pom1 = temp.newFile();

    executeMethod(c, "run", new Object[] { new String[] { "-f", pom1.toString() } });

    assertTrue("Session file should match",
            pom1.equals(((ManipulationSession) FieldUtils.readField(c, "session", true)).getPom()));
}

From source file:com.greenpepper.repository.FileSystemRepository.java

private Vector<Object> generateDocumentNode(File file, Hashtable<String, Vector<?>> pageBranch)
        throws IOException {
    Vector<Object> page = new Vector<Object>();
    page.add(file.equals(root) ? root.getName() : relativePath(file));
    page.add(file.isFile());// w ww . j av  a  2s .co m
    page.add(Boolean.FALSE);
    Hashtable<String, Vector<?>> subPageBranch = new Hashtable<String, Vector<?>>();
    page.add(subPageBranch);
    // Add source path
    page.add(file.getAbsolutePath());
    if (pageBranch != null) {
        pageBranch.put(relativePath(file), page);
    }
    if (file.isDirectory()) {
        navigateInto(file, subPageBranch);
    }
    return page;
}

From source file:com.archimatetool.jasperreports.JasperReportsExporter.java

JasperPrint createJasperPrint(IProgressMonitor monitor, File tmpFolder) throws JRException {
    // Set the location of the default Jasper Properties File
    File propsFile = new File(JasperReportsPlugin.INSTANCE.getPluginFolder(), "jasperreports.properties"); //$NON-NLS-1$
    System.setProperty(DefaultJasperReportsContext.PROPERTIES_FILE, propsFile.getAbsolutePath());

    // Set the location of the Images
    System.setProperty("JASPER_IMAGE_PATH", tmpFolder.getPath()); //$NON-NLS-1$

    // Declare Parameters passed to JasperFillManager
    Map<String, Object> params = new HashMap<String, Object>();

    // Parameters referenced in Report
    params.put("REPORT_TITLE", fReportTitle); //$NON-NLS-1$
    //params.put(JRParameter.REPORT_LOCALE, Locale.US);

    // Path to main.jrxml
    params.put("REPORT_PATH", fMainTemplateFile.getParent() + File.separator); //$NON-NLS-1$

    if (monitor != null) {
        monitor.worked(1);//ww  w.j av  a 2  s .  com
    }

    // Compile Main Report
    //System.out.println("Compiling Main Report");
    if (monitor != null) {
        monitor.subTask(Messages.JasperReportsExporter_10);
    }
    JasperReport mainReport = JasperCompileManager.compileReport(fMainTemplateFile.getPath());

    // Compile sub-reports
    File folder = fMainTemplateFile.getParentFile();
    for (File file : folder.listFiles()) {
        if (!file.equals(fMainTemplateFile) && file.getName().endsWith(".jrxml")) { //$NON-NLS-1$
            //System.out.println("Compiling Sub-Report: " + file);
            JasperReport jr = JasperCompileManager.compileReport(file.getPath());
            params.put(jr.getName(), jr);
        }
    }

    if (monitor != null) {
        monitor.worked(1);
    }

    // Fill Report
    //System.out.println("Filling Report");
    if (monitor != null) {
        monitor.subTask(Messages.JasperReportsExporter_11);
    }

    return JasperFillManager.fillReport(mainReport, params, new ArchimateModelDataSource(fModel));
}

From source file:com.yifanlu.PSXperiaTool.Extractor.CrashBandicootExtractor.java

private void patchEmulator() throws IOException {
    Logger.info("Verifying the emulator binary.");
    Properties config = new Properties();
    config.loadFromXML(new FileInputStream(new File(mOutputDir, "/config/config.xml")));
    String emulatorName = config.getProperty("emulator_name", "libjava-activity.so");
    File origEmulator = new File(mOutputDir, "/lib/armeabi/" + emulatorName);
    String emulatorCRC32 = Long.toHexString(FileUtils.checksumCRC32(origEmulator));
    if (!emulatorCRC32.equalsIgnoreCase(config.getProperty("emulator_crc32")))
        throw new UnsupportedOperationException(
                "The emulator checksum is invalid. Cannot patch. CRC32: " + emulatorCRC32);
    File newEmulator = new File(mOutputDir, "/lib/armeabi/libjava-activity-patched.so");
    File emulatorPatch = new File(mOutputDir, "/config/" + config.getProperty("emulator_patch", ""));
    if (emulatorPatch.equals("")) {
        Logger.info("No patch needed.");
        FileUtils.moveFile(origEmulator, newEmulator);
    } else {/*from  w w  w . j a v  a 2 s.  c  o m*/
        Logger.info("Patching emulator.");
        newEmulator.createNewFile();
        JBPatch.bspatch(origEmulator, newEmulator, emulatorPatch);
        emulatorPatch.delete();
    }
    FileUtils.copyInputStreamToFile(
            PSXperiaTool.class.getResourceAsStream("/resources/libjava-activity-wrapper.so"), origEmulator);
}