Example usage for java.io File getName

List of usage examples for java.io File getName

Introduction

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

Prototype

public String getName() 

Source Link

Document

Returns the name of the file or directory denoted by this abstract pathname.

Usage

From source file:com.turn.ttorrent.cli.TrackerMain.java

private static void addAnnounce(Tracker tracker, File file, int depth) throws IOException, URISyntaxException {
    if (file.isFile()) {
        logger.info("Loading torrent from " + file.getName());
        Torrent torrent = new Torrent(file);
        tracker.announce(new TrackedTorrent(torrent.getName(), torrent.getInfoHash()));
        return;//w  w  w .  jav a2 s  . co  m
    }
    if (depth > 3)
        return;
    FilenameFilter filter = new SuffixFileFilter(".torrent");
    for (File child : file.listFiles(filter))
        addAnnounce(tracker, child, depth + 1);
}

From source file:de.erdesignerng.util.JasperUtils.java

private static void findReports(Map<File, String> aReportMap, File aDirectory) throws JRException {
    Thread.currentThread().setContextClassLoader(JasperUtils.class.getClassLoader());
    if (aDirectory != null && aDirectory.exists() && aDirectory.canRead()) {
        for (File theFile : aDirectory.listFiles()) {
            String theName = theFile.getName();
            if (theName.endsWith(".jrxml") && (!theName.contains("_"))) {
                try {
                    JasperDesign theDesign = JRXmlLoader.load(new FileInputStream(theFile));
                    String theReportName = theDesign.getName();
                    if (StringUtils.isNotEmpty(theReportName)) {
                        aReportMap.put(theFile, theReportName);
                    }/*from  ww  w.  jav  a 2s .  c o m*/
                } catch (FileNotFoundException e) {
                    // This cannot happen
                }

            } else {
                if ((theFile.isDirectory()) && (!".".equals(theName)) && (!"..".equals(theName))) {
                    findReports(aReportMap, theFile);
                }
            }
        }
    }
}

From source file:Main.java

public static List<String> getFile(String path, Integer count, String fileEnd, List<String> result) {
    File f = new File(path);
    File[] files = f.listFiles();

    for (File s : files) {
        if (s.isDirectory()) {
            getFile(s.getAbsolutePath(), count, fileEnd, result);
        } else {//from   w  w  w.j a  va2s  .co  m
            if (s.getName().toLowerCase().endsWith(fileEnd.toLowerCase())) {
                result.add(s.getAbsolutePath());
            }
        }
    }
    return result;
}

From source file:eu.scape_project.arc2warc.Arc2WarcMigration.java

private static void migrate(File dirStructItem) {
    //first do normal migration.
    File output = new File(config.getOutputStr(), dirStructItem.getName().replaceAll("\\.arc(.gz)?$",
            config.createCompressedWarc() ? ".warc.gz" : ".warc"));
    ArcMigrator arcMigrator = new ArcMigrator(config, dirStructItem, output, false);
    arcMigrator.migrateArcFile();/*from  w  w  w  .j a  v a2  s  . co m*/

    if (dirStructItem.getName().contains("-metadata-")) {
        //then make a special deduplication arc file
        output = new File(config.getOutputStr(), output.getName().replace("-metadata-", "-duplications-"));
        arcMigrator = new ArcMigrator(config, dirStructItem, output, true);
        arcMigrator.migrateArcFile();

    }
}

From source file:Main.java

public final static int getNumCores() {
    // Private Class to display only CPU devices in the directory listing
    class CpuFilter implements FileFilter {
        @Override// www.j  a  v a 2s.  co m
        public boolean accept(File pathname) {
            // Check if filename is "cpu", followed by a single digit number
            if (Pattern.matches("cpu[0-9]", pathname.getName())) {
                return true;
            }
            return false;
        }
    }
    try {
        // Get directory containing CPU info
        File dir = new File("/sys/devices/system/cpu/");
        // Filter to only list the devices we care about
        File[] files = dir.listFiles(new CpuFilter());
        // Return the number of cores (virtual CPU devices)
        return files.length;
    } catch (Exception e) {
        return Runtime.getRuntime().availableProcessors();
    }
}

From source file:Utils.java

/**
 * Zip a list of file into one zip file.
 * /*from   w  ww.  j a  v  a  2 s  .  co  m*/
 * @param files
 *          files to zip
 * @param targetZipFile
 *          target zip file
 * @throws IOException
 *           IO error exception can be thrown when copying ...
 */
public static void zipFile(final File[] files, final File targetZipFile) throws IOException {
    try {
        FileOutputStream fos = new FileOutputStream(targetZipFile);
        ZipOutputStream zos = new ZipOutputStream(fos);
        byte[] buffer = new byte[128];
        for (int i = 0; i < files.length; i++) {
            File currentFile = files[i];
            if (!currentFile.isDirectory()) {
                ZipEntry entry = new ZipEntry(currentFile.getName());
                FileInputStream fis = new FileInputStream(currentFile);
                zos.putNextEntry(entry);
                int read = 0;
                while ((read = fis.read(buffer)) != -1) {
                    zos.write(buffer, 0, read);
                }
                zos.closeEntry();
                fis.close();
            }
        }
        zos.close();
        fos.close();
    } catch (FileNotFoundException e) {
        System.out.println("File not found : " + e);
    }

}

From source file:com.gargoylesoftware.htmlunit.source.SVN.java

/**
 * Recursively deletes any '.svn' folder which contains Subversion information.
 * @param dir the directory to recursively delete '.svn' from
 * @throws IOException if an exception happens
 *///from w w w. ja  va 2s . com
public static void deleteSVN(final File dir) throws IOException {
    for (final File f : dir.listFiles()) {
        if (f.isDirectory()) {
            if (".svn".equals(f.getName())) {
                FileUtils.deleteDirectory(f);
            } else {
                deleteSVN(f);
            }
        }
    }
}

From source file:com.googlecode.dex2jar.v3.Main.java

public static void doFile(File srcDex) throws IOException {
    doFile(srcDex,//from w ww. j  a  v a2  s .co m
            new File(srcDex.getParentFile(), FilenameUtils.getBaseName(srcDex.getName()) + "_dex2jar.jar"));
}

From source file:Main.java

private static HashMap<String, Object> getPossibleOriginalXlzSourceFile(File file) {
    HashMap<String, Object> result = new HashMap<String, Object>();
    File wantedFile = file;//from ww w  .j ava  2 s .  c  o  m
    Boolean isFromXlzFile = false;

    try {
        File parentFile = file.getParentFile();
        File grandFile = parentFile.getParentFile();
        File f = new File(grandFile, parentFile.getName() + ".xlz");
        if (f.exists() && f.isFile()) {
            wantedFile = f;
            isFromXlzFile = true;
        }
    } catch (Exception e) {

    }

    result.put("sourceFile", wantedFile);
    result.put("isFromXlzFile", isFromXlzFile);
    return result;
}

From source file:com.baasbox.util.Util.java

public static void createZipFile(String path, File... files) {
    if (BaasBoxLogger.isDebugEnabled())
        BaasBoxLogger.debug("Zipping into:" + path);
    ZipOutputStream zip = null;//from   w  w  w .j a va 2  s .  c  o m
    FileOutputStream dest = null;
    try {
        File f = new File(path);
        dest = new FileOutputStream(f);
        zip = new ZipOutputStream(new BufferedOutputStream(dest));
        for (File file : files) {
            zip.putNextEntry(new ZipEntry(file.getName()));
            zip.write(FileUtils.readFileToByteArray(file));
            zip.closeEntry();
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Unable to create zip file");
    } finally {
        try {
            if (zip != null)
                zip.close();
            if (dest != null)
                dest.close();

        } catch (Exception ioe) {
            //Nothing to do
        }
    }
}