Example usage for java.io File canRead

List of usage examples for java.io File canRead

Introduction

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

Prototype

public boolean canRead() 

Source Link

Document

Tests whether the application can read the file denoted by this abstract pathname.

Usage

From source file:eu.eubrazilcc.lvl.storage.UrlShortenerTest.java

@BeforeClass
public static void setUp() throws IOException {
    final File file = new File(
            concat(DEFAULT_LOCATION, TEST_CONFIG_ROOT + separator + "etc" + separator + REST_SERVICE_CONFIG));
    if (file.canRead()) {
        final List<URL> urls = newArrayList(getDefaultConfiguration());
        for (final ListIterator<URL> it = urls.listIterator(); it.hasNext();) {
            final URL url = it.next();
            if (url.getPath().endsWith(REST_SERVICE_CONFIG)) {
                it.remove();/*from w ww  .  j  ava 2s.c o m*/
                it.add(toURLs(new File[] { file })[0]);
            }
        }
        CONFIG_MANAGER.setup(urls);
        hasToClean = true;
    }
}

From source file:Main.java

public static boolean canImport() {
    String itemsFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + '/' + APP_PATH + '/'
            + ITEMS_CSVFILENAME;//  w ww . ja va  2  s. c o  m
    File itemsFile = new File(itemsFilePath);

    String placesFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + '/' + APP_PATH + '/'
            + PLACES_CSVFILENAME;
    File placesFile = new File(placesFilePath);

    return (itemsFile.canRead() && placesFile.canRead());
}

From source file:fm.last.commons.io.LastFileUtils.java

public static boolean canRead(File file) {
    return file != null && file.exists() && file.canRead();
}

From source file:com.recomdata.transmart.data.export.util.ZipUtil.java

/**
 * This method will bundle all the files into a zip file. 
 * If there are 2 files with the same name, only the first file is part of the zip.
 * //from  w  ww .  j  ava 2 s.c o m
 * @param zipFileName
 * @param files
 * 
 * @return zipFile absolute path
 * 
 */
public static String bundleZipFile(String zipFileName, List<File> files) {
    File zipFile = null;
    Map<String, File> filesMap = new HashMap<String, File>();

    if (StringUtils.isEmpty(zipFileName))
        return null;

    try {
        zipFile = new File(zipFileName);
        if (zipFile.exists() && zipFile.isFile() && zipFile.delete()) {
            zipFile = new File(zipFileName);
        }

        ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile));
        zipOut.setLevel(ZipOutputStream.DEFLATED);
        byte[] buffer = new byte[BUFFER_SIZE];

        for (File file : files) {
            if (filesMap.containsKey(file.getName())) {
                continue;
            } else if (file.exists() && file.canRead()) {
                filesMap.put(file.getName(), file);
                zipOut.putNextEntry(new ZipEntry(file.getName()));
                FileInputStream fis = new FileInputStream(file);
                int bytesRead;
                while ((bytesRead = fis.read(buffer)) != -1) {
                    zipOut.write(buffer, 0, bytesRead);
                }
                zipOut.flush();
                zipOut.closeEntry();
            }
        }
        zipOut.finish();
        zipOut.close();
    } catch (IOException e) {
        //log.error("Error while creating Zip file");
    }

    return (null != zipFile) ? zipFile.getAbsolutePath() : null;
}

From source file:com.log4ic.compressor.utils.FileUtils.java

/**
 * ?//from   w  w w. ja va 2s  . c  om
 *
 * @param file
 * @return
 */
public static String readFile(File file) throws IOException {
    if (!file.exists() || file.isDirectory() || !file.canRead()) {
        return null;
    }
    FileInputStream fileInputStream = new FileInputStream(file);
    return readFile(fileInputStream);
}

From source file:ezbake.deployer.impl.Files.java

public static boolean isReadable(File file) {
    return file.canRead();
}

From source file:ch.elexis.importer.div.Helpers.java

public static void parseOneHL7file(HL7Parser hlp, File f, boolean deleteAll, boolean alsoFailing)
        throws IOException {
    String name = f.getAbsolutePath();
    if (f.canRead() && (name.toLowerCase().endsWith(".hl7"))) {
        if (f.getName().equalsIgnoreCase("01TEST5005.hl7")
                || f.getName().equalsIgnoreCase("1_Kunde_20090612083757162_10009977_.HL7")) {
            if (!alsoFailing) {
                // System.out.println("Skipping " + name);
                return;
            }/*from ww w.ja  va2s.co m*/
        }
        // System.out.println("parseOneHL7file " + name + "  " + f.length() + " bytes ");
        Result<?> rs = hlp.importFile(f, f.getParentFile(), true);
        if (!rs.isOK()) {
            String info = "Datei " + name + " fehlgeschlagen";
            System.out.println(info);
            fail(info);
        } else {
            assertTrue(true); // To show that we were successfull
            // System.out.println("Datei " + name +
            // " erfolgreich verarbeitet");
            Query<LabResult> qr = new Query<LabResult>(LabResult.class);
            List<LabResult> qrr = qr.execute();
            if (qrr.size() <= 0)
                fail("NoLabResult");
            if (deleteAll) {
                removeAllPatientsAndDependants();
            }
        }
    } else {
        System.out.println("Skipping Datei " + name);
    }
}

From source file:com.codercowboy.photo.organizer.service.PhotoIndexer.java

public static List<Photo> indexDirectory(String directoryAbsolutePath) throws Exception {
    File directory = new File(directoryAbsolutePath);
    if (!directory.exists()) {
        throw new IOException("Directory for indexing does not exist: " + directoryAbsolutePath);
    }/*from   w  w  w  . ja  va  2s.  co  m*/
    if (!directory.canRead()) {
        throw new IOException(
                "Cannot read directory for indexing, permission denied: " + directoryAbsolutePath);
    }
    List<Photo> photos = new LinkedList<>();
    for (File f : FileUtils.listFiles(directory, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) {
        //TODO: this should be externally configurable
        if (".DS_Store".equals(f.getName())) {
            continue;
        }
        photos.add(indexFile(f));
    }
    return photos;
}

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. j ava  2 s. com
                } catch (FileNotFoundException e) {
                    // This cannot happen
                }

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

From source file:de.micromata.genome.util.runtime.Log4JInitializer.java

private static boolean initializeLog4JIntern() {
    LocalSettings ls = LocalSettings.get();
    File log4jfile = new File(ls.get(LOG4J_PROPERTY_FILE, LOG4J_PROPERTY_FILE));
    if (log4jfile.exists() == true && log4jfile.canRead() == true) {
        return initViaFile(log4jfile);
    }//from   w ww .j a v a 2 s . c om

    return initViaCp();

}