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:com.zotoh.core.util.FileUte.java

/**
 * @param fp/* w w w  . j  av  a 2  s  .c o  m*/
 * @return
 */
public static boolean isFileKosher(File fp) {
    return fp != null && fp.exists() && fp.canRead() && fp.canWrite();
}

From source file:de.helmholtz_muenchen.ibis.utils.ngs.samsplitter.helpers.FileHelpers.java

public static File checkInFile(String strInFile, boolean printInfo) throws ParameterInvalidException {
    File inFile = new File(strInFile);
    if (!inFile.exists() || !inFile.canRead()) {
        System.err.println("File '" + inFile.getAbsolutePath() + "' does not exist! Aborting!");
        if (FileHelpers.noExitRule) {
            throw new ParameterInvalidException("4: Filehelper: Given InFile does not exist.");
        } else/* w  ww . j  a  va2s.  c o m*/
            System.exit(4);
    }
    if (printInfo)
        System.out.println("Using Infile: " + inFile.getAbsolutePath());
    return inFile;
}

From source file:marytts.server.http.MaryHttpServerUtils.java

public static void fileToHttpResponse(String fullPathFile, HttpResponse response, String contentType,
        boolean useFileChannels) {
    int status;/*  w  ww .  j av  a 2  s  .c o m*/
    final File file = new File(fullPathFile);
    if (!file.exists())
        status = HttpStatus.SC_NOT_FOUND;
    else if (!file.canRead() || file.isDirectory())
        status = HttpStatus.SC_FORBIDDEN;
    else {
        status = HttpStatus.SC_OK;
        NFileEntity entity = new NFileEntity(file, contentType, useFileChannels);
        response.setEntity(entity);
    }

    response.setStatusCode(status);
}

From source file:com.aaasec.sigserv.csspserver.utility.SpServerLogic.java

public static String getServerDocResponse(RequestModel req, String fileName) {
    String filePath = FileOps.getfileNameString(SpModel.getDocDir(), fileName);
    File docFile = new File(filePath);
    if (docFile.canRead()) {
        SigDocumentType docType = DocTypeIdentifier.getDocType(docFile);
        req.getSession().newSigningInstance(docType);
        return getDocSelectResponse(docFile, req);
    }/*from  ww w.  j a va 2s  .  com*/
    return "Error";
}

From source file:com.tc.process.Exec.java

public static String getJavaExecutable() {
    String javaHome = System.getProperty("java.home");
    if (javaHome == null) {
        throw new IllegalStateException("java.home system property not set");
    }//from   www .  jav  a  2s  .  c o m

    File home = new File(javaHome);
    ensureDir(home);

    File bin = new File(home, "bin");
    ensureDir(bin);

    File java = new File(bin, "java" + (System.getProperty("os.name").contains("win") ? ".exe" : ""));
    if (java.exists() && java.canRead()) {
        return java.getAbsolutePath();
    }

    throw new AssertionError(java.getAbsolutePath() + " cannot be read or does not exist");
}

From source file:kindleclippings.quizlet.QuizletSync.java

private static Map<String, List<Clipping>> readClippingsFile() throws IOException {
    // try to find it
    File cl = new File("/Volumes/Kindle/documents/My Clippings.txt");
    if (!cl.canRead()) {
        JFileChooser fc = new JFileChooser();
        fc.setFileFilter(new FileNameExtensionFilter("Kindle Clippings", "txt"));
        int result = fc.showOpenDialog(null);
        if (result != JFileChooser.APPROVE_OPTION) {
            return null;
        }/* w  w w .j av  a 2  s .c  o  m*/
        cl = fc.getSelectedFile();
    }
    Reader f = new InputStreamReader(new FileInputStream(cl), "UTF-8");
    try {
        MyClippingsReader r = new MyClippingsReader(f);

        Map<String, List<Clipping>> books = new TreeMap<String, List<Clipping>>();

        Clipping l;
        while ((l = r.readClipping()) != null) {
            if (l.getType() != ClippingType.highlight && l.getType() != ClippingType.note) {
                System.err.println("ignored " + l.getType() + " [" + l.getBook() + "]");
                continue;
            }
            String lct = l.getContent().trim();
            if (lct.length() == 0) {
                System.err.println("ignored empty " + l.getType() + " [" + l.getBook() + "]");
                continue;
            }
            if (lct.length() < 10 || !lct.contains(" ")) {
                System.err.println(
                        "ignored too short " + l.getType() + " " + l.getContent() + " [" + l.getBook() + "]");
                continue;
            }
            List<Clipping> clippings = books.get(l.getBook());
            if (clippings == null) {
                clippings = new ArrayList<Clipping>();
                books.put(l.getBook(), clippings);
            }
            clippings.add(l);
        }
        return books;
    } finally {
        f.close();
    }
}

From source file:org.eclipse.virgo.ide.jdt.internal.core.util.ClasspathUtils.java

/**
 * Adjusts the last modified timestamp on the source root and META-INF directory to reflect the
 * same date as the MANIFEST.MF.//from   w ww .j a v  a 2s . co  m
 * <p>
 * Note: this is a requirement for the dependency resolution.
 */
public static void adjustLastModifiedDate(IJavaProject javaProject, boolean testBundle) {
    File manifest = BundleManifestUtils.locateManifestFile(javaProject, testBundle);
    if (manifest != null && manifest.canRead()) {
        long lastmodified = manifest.lastModified();
        File metaInfFolder = manifest.getParentFile();
        if (metaInfFolder != null
                && metaInfFolder.getName().equals(BundleManifestCorePlugin.MANIFEST_FOLDER_NAME)
                && metaInfFolder.canWrite()) {
            metaInfFolder.setLastModified(lastmodified);
            File srcFolder = metaInfFolder.getParentFile();
            if (srcFolder != null && srcFolder.canWrite()) {
                srcFolder.setLastModified(lastmodified);
            }
        }
    }
}

From source file:com.zotoh.core.util.FileUte.java

/**
 * @param dir//from   ww w  .ja va 2s  .  com
 * @return
 */
public static boolean isDirKosher(File dir) {
    return dir != null && dir.exists() && dir.canExecute() && dir.canRead() && dir.canWrite();
}

From source file:eu.openanalytics.rsb.config.ConfigurationFactory.java

private static URL getConfigurationUrl() {
    final File configurationFile = new File(RSB_CONFIGURATION_DIRECTORY, getConfigurationFileName());
    if (configurationFile.isFile() && configurationFile.canRead()) {
        try {/*w  ww.ja  va 2s  .c  o  m*/
            return configurationFile.toURI().toURL();
        } catch (final MalformedURLException murle) {
            throw new IllegalStateException("Unexpected toURL failure for file: " + configurationFile, murle);
        }
    } else {
        return Thread.currentThread().getContextClassLoader().getResource(getConfigurationFileName());
    }
}

From source file:com.ikon.util.ArchiveUtils.java

/**
 * Recursively create ZIP archive from directory 
 *///  www.  j  av  a  2 s .com
public static void createZip(File path, String root, OutputStream os) throws IOException {
    log.debug("createZip({}, {}, {})", new Object[] { path, root, os });

    if (path.exists() && path.canRead()) {
        ZipArchiveOutputStream zaos = new ZipArchiveOutputStream(os);
        zaos.setComment("Generated by openkm");
        zaos.setCreateUnicodeExtraFields(UnicodeExtraFieldPolicy.ALWAYS);
        zaos.setUseLanguageEncodingFlag(true);
        zaos.setFallbackToUTF8(true);
        zaos.setEncoding("UTF-8");

        // Prevents java.util.zip.ZipException: ZIP file must have at least one entry
        ZipArchiveEntry zae = new ZipArchiveEntry(root + "/");
        zaos.putArchiveEntry(zae);
        zaos.closeArchiveEntry();

        createZipHelper(path, zaos, root);

        zaos.flush();
        zaos.finish();
        zaos.close();
    } else {
        throw new IOException("Can't access " + path);
    }

    log.debug("createZip: void");
}