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.gu.conf.FileAndResourceLoader.java

private InputStream getFile(String resource) throws IOException {
    File file = new File(stripProtocol(resource));
    if (!file.canRead()) {
        LOG.info("Ignoring missing configuration file " + resource);
        return null;
    }/*  w ww. j a  v a 2 s.  c om*/
    return new BufferedInputStream(new FileInputStream(file));
}

From source file:net.urlgrey.mythpodcaster.transcode.ClipLocatorImpl.java

/**
 * @param filename//from w  ww.  j  a v a  2  s .  c o  m
 * @return
 */
public File locateOriginalClip(String filename) {

    final List<String> recordingDirectories = recordingsDao.findRecordingDirectories();
    if (recordingDirectories == null || recordingDirectories.size() == 0) {
        return null;
    }

    for (String directory : recordingDirectories) {
        File clipLocation = new File(directory, filename);
        if (clipLocation.canRead()) {
            return clipLocation;
        }
    }
    return null;
}

From source file:com.filesprocessing.listener.FilesListener.java

private void iterateFiles(final File dir) {
    File[] files = dir.listFiles();
    for (File file : files) {
        if (file.isDirectory() && file.canRead()) {
            iterateFiles(file);/*from  w w  w .j a  v  a 2s  . co  m*/
        } else if (pattern.matcher(file.getName()).matches()) {
            log.info("Find a file for processing: " + file.getPath());
            ++numFiles;
            pool.submit(new FileRunnable(file));
        }
    }
}

From source file:com.seanbright.osgi.launcher.Daemon.java

private Map<String, String> loadFrameworkProperties(String filename) {
    Map<String, String> properties = new HashMap<String, String>();

    File f = new File(filename);

    if (!f.exists() || !f.isFile() || !f.canRead()) {
        return properties;
    }/*from w w w  . j a  v a  2s . c o m*/

    Properties workingCopy = new Properties();

    FileInputStream stream = null;

    try {
        stream = new FileInputStream(f);

        workingCopy.load(stream);
    } catch (IOException e) {
        e.printStackTrace(System.err);
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
                /* Ignore */
            }
        }
    }

    for (String key : workingCopy.stringPropertyNames()) {
        properties.put(key, workingCopy.getProperty(key));
    }

    PropertiesParser.performSubstitutions(properties);

    return properties;
}

From source file:marytts.util.io.FileUtils.java

public static void copy(String sourceFile, String destinationFile) throws IOException {
    File fromFile = new File(sourceFile);
    File toFile = new File(destinationFile);

    if (!fromFile.exists()) {
        throw new IOException("FileCopy: " + "no such source file: " + sourceFile);
    }/*  ww  w.ja  va 2  s .  c om*/
    if (!fromFile.isFile()) {
        throw new IOException("FileCopy: " + "can't copy directory: " + sourceFile);
    }
    if (!fromFile.canRead()) {
        throw new IOException("FileCopy: " + "source file is unreadable: " + sourceFile);
    }

    if (toFile.isDirectory()) {
        toFile = new File(toFile, fromFile.getName());
    }

    if (toFile.exists()) {
        if (!toFile.canWrite()) {
            throw new IOException("FileCopy: " + "destination file cannot be written: " + destinationFile);
        }
    }

    String parent = toFile.getParent();
    if (parent == null) {
        parent = System.getProperty("user.dir");
    }
    File dir = new File(parent);
    if (!dir.exists()) {
        throw new IOException("FileCopy: " + "destination directory doesn't exist: " + parent);
    }
    if (dir.isFile()) {
        throw new IOException("FileCopy: " + "destination is not a directory: " + parent);
    }
    if (!dir.canWrite()) {
        throw new IOException("FileCopy: " + "destination directory is unwriteable: " + parent);
    }

    FileInputStream from = null;
    FileOutputStream to = null;
    try {
        from = new FileInputStream(fromFile);
        to = new FileOutputStream(toFile);
        byte[] buffer = new byte[4096];
        int bytesRead;

        while ((bytesRead = from.read(buffer)) != -1) {
            to.write(buffer, 0, bytesRead); // write
        }
    } finally {
        close(from, to);
    }
}

From source file:cn.vlabs.clb.server.ui.frameservice.pdf.PdfConvertAdapter.java

public void parseConfig(String cfp, Properties props) {
    File cff = new File(cfp);
    if (!cff.exists() || !cff.isFile() || !cff.canRead()) {
        throw (new InvalidParameterException("Configuration file unreadable."));
    }//from w w w.j a  v  a  2s  .c  o m
    BufferedReader cfr = null;
    try {
        cfr = new BufferedReader(new FileReader(cff));
        String line;
        while ((line = cfr.readLine()) != null) {
            processLine(line, props);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(cfr);
    }
}

From source file:net.lightbody.bmp.proxy.jetty.html.Image.java

/** Set the image size from the header of a GIF file.
 *///from w w  w . j  a  va2  s .c o  m
public Image setSizeFromGif(File gif) {
    if (gif.canRead()) {
        FileInputStream in = null;
        try {
            byte[] buf = new byte[10];
            in = new FileInputStream(gif);
            if (in.read(buf, 0, 10) == 10) {
                if (log.isDebugEnabled())
                    log.debug("Image " + gif.getName() + " is " + ((0x00ff & buf[7]) * 256 + (0x00ff & buf[6]))
                            + " x " + (((0x00ff & buf[9]) * 256 + (0x00ff & buf[8]))));
                width((0x00ff & buf[7]) * 256 + (0x00ff & buf[6]));
                height(((0x00ff & buf[9]) * 256 + (0x00ff & buf[8])));
            }
        } catch (IOException e) {
            LogSupport.ignore(log, e);
        } finally {
            IO.close(in);
        }
    }

    return this;
}

From source file:com.frostwire.platform.DefaultFileSystem.java

@Override
public boolean canRead(File file) {
    return file.canRead();
}

From source file:com.zotoh.netio.MemFileServer.java

public StreamData getFile(String file) throws IOException {
    File fp = new File(_vdir, file);
    StreamData out = null;/*from   www.  ja v  a 2  s.com*/

    if (fp.exists() && fp.canRead()) {
        out = new StreamData();
        out.resetMsgContent(fp, false);
    }

    return out;
}

From source file:org.eclipse.vorto.remoterepository.VortoTestApplication.java

@Bean(name = "fsDirectory")
@DependsOn("analyzer")
public FSDirectory getFSDirectory() {
    FSDirectory fsd = null;/*from  w  w w. j a va  2  s .  c  om*/

    Path indexLocation = Paths.get("src/test/resources/temp/lucent");

    File location = indexLocation.toFile();

    if (!location.exists() || !location.canRead()) {
        log.info("Creating index directory: '" + location.getAbsolutePath() + "'");
        location.mkdirs();
    }

    try {
        fsd = FSDirectory.open(location, new NativeFSLockFactory());
    } catch (IOException e) {
        log.log(Level.SEVERE, " IOException for creating Indexing folder", e);
    }

    return fsd;
}