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.lunifera.examples.vaaclipse.demo1.e4.views.VirtualFilesystemView.java

private void selectTreeNode(MInputPart inputPart) {
    File f = new File(inputPart.getInputURI());
    File dir = f.getParentFile();
    List<File> pathToParent = new ArrayList<File>();
    pathToParent.add(dir);/*from  w w  w . j  av  a2  s . co  m*/
    while (!dir.equals(demoRoot) && dir != null) {
        dir = dir.getParentFile();
        pathToParent.add(dir);
    }
    Collections.reverse(pathToParent);
    for (File d : pathToParent) {
        tree.expandItem(d);
    }
    tree.select(f);
}

From source file:com.chinamobile.bcbsp.fault.storage.ManageFaultLog.java

/**
 * each time the new directory is created ,the method is called . record the
 * file and compress the front file. local disk store 3 month data files ,and
 * the other store in the hdfs that save 12 month data file;
 * @param file//www . j  a  v  a2  s  .c om
 *        file to record.
 */
public void record(File file) {
    int compressindex = 0;
    File previousFile = dr.getLocalFile(((dr.getIndexl() - 1) + dr.getLocalFileNum()) % dr.getLocalFileNum());
    /*prevent from duplicate write the same Dir in the record;*/
    if (previousFile != null && previousFile.equals(file)) {
        return;
    }
    compressindex = dr.pushLocalFile(file);
    if (dr.isCopyFlag()) {
        dr.setCopyFlag(false);
        saveRecord();
        return;
    }
    if (dr.getLocalFile(compressindex) != null) {
        compress(dr.getLocalFile(compressindex));
    }
    saveRecord();
}

From source file:com.manydesigns.portofino.modules.PageactionsModule.java

protected void preloadPageActions(File directory) {
    for (File file : directory.listFiles()) {
        logger.debug("visit {}", file);
        if (file.isDirectory()) {
            if (!file.equals(directory) && !file.equals(directory.getParentFile())) {
                preloadPageActions(file);
            }//from  w  w w. j a v a  2s.c om
        } else if ("action.groovy".equals(file.getName())) {
            logger.debug("Preloading page: {}", file);
            try {
                Class<?> clazz = DispatcherLogic.getActionClass(configuration, directory);
                clazz.newInstance();
            } catch (Throwable t) {
                logger.warn("PageAction preload failed for page " + file.getAbsolutePath(), t);
            }
        }
    }
}

From source file:com.manydesigns.portofino.modules.PageactionsModule.java

protected void preloadGroovyClasses(File directory, String pkg) {
    for (File file : directory.listFiles()) {
        logger.debug("visit {}", file);
        if (file.isDirectory()) {
            if (!file.equals(directory) && !file.equals(directory.getParentFile())) {
                preloadGroovyClasses(file, pkg + file.getName() + ".");
            }//from  w  ww .ja  v  a 2 s.c  om
        } else {
            String name = file.getName();
            String className = pkg + name.substring(0, name.length() - ".groovy".length());
            logger.debug("Preloading " + className);
            try {
                classLoader.loadClass(className, true, false, true);
            } catch (Throwable t) {
                logger.warn("Groovy class preload failed for class " + className, t);
            }
        }
    }
}

From source file:info.varden.anatychia.Main.java

public static MaterialDataList materialList(SaveData save, ProgressUpdater pu, MaterialData[] filters) {
    Random random = new Random();
    boolean filtersNull = filters == null;
    pu.updated(0, 1);//  w w  w .  j  a v  a2  s  .  c  o m
    pu.updated(-3, 1);
    MaterialDataList mdl = new MaterialDataList();
    File saveDir = save.getLocation();
    File[] regionFolders = listRegionContainers(saveDir);
    int depth = Integer.MAX_VALUE;
    File shallowest = null;
    for (File f : regionFolders) {
        String path = f.getAbsolutePath();
        Pattern p = Pattern.compile(Pattern.quote(File.separator));
        Matcher m = p.matcher(path);
        int count = 0;
        while (m.find()) {
            count++;
        }
        if (count < depth) {
            depth = count;
            if (shallowest == null || f.getName().equalsIgnoreCase("region")) {
                shallowest = f;
            }
        }
    }
    pu.updated(-1, 1);
    ArrayList<File> regions = new ArrayList<File>();
    int tfs = 0;
    for (File f : regionFolders) {
        String dimName = f.getParentFile().getName();
        boolean deleted = false;
        if (f.equals(shallowest)) {
            dimName = "DIM0";
        }
        if (!filtersNull) {
            for (MaterialData type : filters) {
                if (type.getType() == MaterialType.DIMENSION && type.getName().equals(dimName)) {
                    System.out.println("Deleting: " + dimName);
                    deleted = recursiveDelete(f);
                }
            }
        }
        if (deleted)
            continue;
        mdl.increment(new MaterialData(MaterialType.DIMENSION, dimName, 1L));
        File[] r = f.listFiles(new FilenameFilter() {

            @Override
            public boolean accept(File dir, String name) {
                return name.endsWith(".mca");
            }

        });
        int max = r.length;
        int cur = 0;
        for (File valid : r) {
            cur++;
            try {
                BufferedInputStream bis = new BufferedInputStream(new FileInputStream(valid));
                byte[] offsetHeader = new byte[4096];
                bis.read(offsetHeader, 0, 4096);
                bis.close();
                ByteBuffer bb = ByteBuffer.wrap(offsetHeader);
                IntBuffer ib = bb.asIntBuffer();
                while (ib.remaining() > 0) {
                    if (ib.get() != 0) {
                        tfs++;
                    }
                }
                bb = null;
                ib = null;
            } catch (IOException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
            // tfs += Math.floor(valid.length() / 1000D);
            pu.updated(cur, max);
        }
        regions.addAll(Arrays.asList(r));
    }
    if (regions.size() <= 0) {
        pu.updated(1, 1);
        return mdl;
    }
    pu.updated(-2, 1);
    int fc = 0;
    int fs = 0;
    for (File region : regions) {
        fc++;
        //fs += Math.floor(region.length() / 1000D);
        try {
            RegionFile anvil = new RegionFile(region);
            for (int x = 0; x < 32; x++) {
                for (int z = 0; z < 32; z++) {
                    InputStream is = anvil.getChunkDataInputStream(x, z);
                    if (is == null)
                        continue;
                    NBTInputStream nbti = new NBTInputStream(is, CompressionMode.NONE);
                    CompoundTag root = (CompoundTag) nbti.readTag();
                    String rootName = root.getName();
                    CompoundTag level = (CompoundTag) root.getValue().get("Level");
                    Map<String, Tag> levelTags = level.getValue();
                    ListTag sectionTag = (ListTag) levelTags.get("Sections");
                    ArrayList<Tag> sections = new ArrayList<Tag>(sectionTag.getValue());
                    for (int i = 0; i < sections.size(); i++) {
                        mdl.setSectorsRelative(1);
                        CompoundTag sect = (CompoundTag) sections.get(i);
                        Map<String, Tag> sectTags = sect.getValue();
                        ByteArrayTag blockArray = (ByteArrayTag) sectTags.get("Blocks");
                        byte[] add = new byte[0];
                        boolean hasAdd = false;
                        if (sectTags.containsKey("Add")) {
                            hasAdd = true;
                            ByteArrayTag addArray = (ByteArrayTag) sectTags.get("Add");
                            add = addArray.getValue();
                        }
                        byte[] blocks = blockArray.getValue();
                        for (int j = 0; j < blocks.length; j++) {
                            short id;
                            byte aid = (byte) 0;
                            if (hasAdd) {
                                aid = ChunkFormat.Nibble4(add, j);
                                id = (short) ((blocks[j] & 0xFF) + (aid << 8));
                            } else {
                                id = (short) (blocks[j] & 0xFF);
                            }
                            if (!filtersNull) {
                                for (MaterialData type : filters) {
                                    if (type.getType() == MaterialType.BLOCK
                                            && type.getName().equals(String.valueOf(blocks[j] & 0xFF))
                                            && (type.getRemovalChance() == 1D
                                                    || random.nextDouble() < type.getRemovalChance())) {
                                        blocks[j] = (byte) 0;
                                        if (aid != 0) {
                                            add[j / 2] = (byte) (add[j / 2] & (j % 2 == 0 ? 0xF0 : 0x0F));
                                        }
                                        id = (short) 0;
                                    }
                                }
                            }
                            mdl.increment(new MaterialData(MaterialType.BLOCK, String.valueOf(id), 1L));
                        }
                        if (!filtersNull) {
                            HashMap<String, Tag> rSectTags = new HashMap<String, Tag>();
                            rSectTags.putAll(sectTags);
                            ByteArrayTag bat = new ByteArrayTag("Blocks", blocks);
                            rSectTags.put("Blocks", bat);
                            if (hasAdd) {
                                ByteArrayTag adt = new ByteArrayTag("Add", add);
                                rSectTags.put("Add", adt);
                            }
                            CompoundTag rSect = new CompoundTag(sect.getName(), rSectTags);
                            sections.set(i, rSect);
                        }
                    }
                    ListTag entitiesTag = (ListTag) levelTags.get("Entities");
                    ArrayList<Tag> entities = new ArrayList<Tag>(entitiesTag.getValue());
                    for (int i = entities.size() - 1; i >= 0; i--) {
                        CompoundTag entity = (CompoundTag) entities.get(i);
                        Map<String, Tag> entityTags = entity.getValue();
                        if (entityTags.containsKey("id")) {
                            StringTag idTag = (StringTag) entityTags.get("id");
                            String id = idTag.getValue();
                            boolean removed = false;
                            if (!filtersNull) {
                                for (MaterialData type : filters) {
                                    if (type.getType() == MaterialType.ENTITY
                                            && (type.getName().equals(id) || type.getName().equals(""))
                                            && (type.getRemovalChance() == 1D
                                                    || random.nextDouble() < type.getRemovalChance())) {
                                        if (type.fulfillsRequirements(entity)) {
                                            entities.remove(i);
                                            removed = true;
                                        }
                                    }
                                }
                            }
                            if (!removed) {
                                mdl.increment(new MaterialData(MaterialType.ENTITY, id, 1L));
                            }
                        }
                    }
                    nbti.close();
                    is.close();
                    if (!filtersNull) {
                        HashMap<String, Tag> rLevelTags = new HashMap<String, Tag>();
                        rLevelTags.putAll(levelTags);
                        ListTag rSectionTag = new ListTag("Sections", CompoundTag.class, sections);
                        rLevelTags.put("Sections", rSectionTag);
                        ListTag rEntityTag = new ListTag("Entities", CompoundTag.class, entities);
                        rLevelTags.put("Entities", rEntityTag);
                        final CompoundTag rLevel = new CompoundTag("Level", rLevelTags);
                        HashMap<String, Tag> rRootTags = new HashMap<String, Tag>() {
                            {
                                put("Level", rLevel);
                            }
                        };
                        CompoundTag rRoot = new CompoundTag(rootName, rRootTags);
                        OutputStream os = anvil.getChunkDataOutputStream(x, z);
                        NBTOutputStream nbto = new NBTOutputStream(os, CompressionMode.NONE);
                        nbto.writeTag(rRoot);
                        nbto.close();
                    }
                    fs++;
                    pu.updated(fs, tfs);
                }
            }
            anvil.close();
        } catch (Exception ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    MaterialData[] data = mdl.toArray();
    System.out.println("FILES SCANNED: " + fc);
    for (MaterialData d : data) {
        System.out.println(d.getType().getName() + ": " + d.getName() + " (" + d.getQuantity() + ")");
    }
    return mdl;
}

From source file:org.pepstock.jem.notify.engine.EmailTemplateReader.java

/**
 * Called if the parameter file <code>file</code> is deleated. <br>
 * If the file deleted is the email template file, this method warns the
 * deletion.// w ww .  jav a  2  s . c o  m
 * 
 * @param file the <code>File</code> deleted.
 * @see FileAlterationListener#onFileDelete(File)
 * @override
 */
public void onFileDelete(File file) {
    if (file.equals(this.emailTemplateFile)) {
        LogAppl.getInstance().emit(NotifyMessage.JEMN011W,
                new Object[] { this.emailTemplateFile, this.emailTemplateFile.getParentFile() });
    }
}

From source file:com.twosigma.beaker.autocomplete.ClasspathScanner.java

private String createClassName(File root, File file) {
    StringBuffer sb = new StringBuffer();
    String fileName = file.getName();
    sb.append(fileName.substring(0, fileName.lastIndexOf(".class")));
    file = file.getParentFile();//ww  w . j  a v a 2s  . c om
    while (file != null && !file.equals(root)) {
        sb.insert(0, '.').insert(0, file.getName());
        file = file.getParentFile();
    }
    return sb.toString();
}

From source file:org.jumpmind.symmetric.io.stage.StagedResource.java

public void setState(State state) {
    if (file.exists()) {
        File newFile = buildFile(state);
        if (!newFile.equals(file)) {
            if (newFile.exists()) {
                if (writer != null || outputStream != null) {
                    throw new IoException("Could not write '{}' it is currently being written to",
                            newFile.getAbsolutePath());
                }/*from w  ww.  j a v  a2  s  .c  o  m*/

                if (!FileUtils.deleteQuietly(newFile)) {
                    log.warn("Failed to delete '{}' in preparation for renaming '{}'",
                            newFile.getAbsolutePath(), file.getAbsoluteFile());
                    if (readers.size() > 0) {
                        for (Thread thread : readers.keySet()) {
                            BufferedReader reader = readers.get(thread);
                            log.warn("Closing unwanted reader for '{}' that had been created on thread '{}'",
                                    newFile.getAbsolutePath(), thread.getName());
                            IOUtils.closeQuietly(reader);
                        }
                    }

                    if (!FileUtils.deleteQuietly(newFile)) {
                        log.warn("Failed to delete '{}' for a second time", newFile.getAbsolutePath());
                    }
                }
            }
            if (!file.renameTo(newFile)) {
                String msg = String.format(
                        "Had trouble renaming file.  The current name is %s and the desired state was %s",
                        file.getAbsolutePath(), state);
                log.warn(msg);
                throw new IllegalStateException(msg);
            } else {
                this.file = newFile;
            }
        }
    } else if (memoryBuffer != null && state == State.DONE) {
        this.memoryBuffer.setLength(0);
        this.memoryBuffer = null;
    }
    refreshLastUpdateTime();
    this.state = state;
}

From source file:org.pepstock.jem.notify.engine.EmailTemplateReader.java

/**
 * Called if the parameter file <code>file</code> is changed. <br>
 * If the file changed is the email template file, reloads the email
 * template file./*from w  ww . j a va  2s  .c  om*/
 * 
 * @param file the <code>File</code> changed.
 * @see FileAlterationListener#onFileChange(File)
 * @override
 */
public void onFileChange(File file) {
    if (file.equals(this.emailTemplateFile)) {
        try {
            this.readEmailTemplate();
        } catch (EmailConfigurationException ex) {
            LogAppl.getInstance().emit(NotifyMessage.JEMN008E, ex);
        }
    }
}

From source file:org.pepstock.jem.notify.engine.EmailTemplateReader.java

/**
 * Called if the parameter file <code>file</code> is created. <br>
 * If the file created is the email template file, reloads the email
 * template file./*from  w  ww .j a  v a  2 s . co  m*/
 * 
 * @param file the <code>File</code> created.
 * @see FileAlterationListener#onFileCreate(File)
 * @override
 */
public void onFileCreate(File file) {
    if (file.equals(this.emailTemplateFile)) {
        try {
            this.readEmailTemplate();
        } catch (EmailConfigurationException ex) {
            LogAppl.getInstance().emit(NotifyMessage.JEMN008E, ex);
        }
    }
}