Waits for a file to be created.

@param file the file
@return {@literal true} if the file was created, {@literal false} otherwise
482117
public static boolean waitForFile(File file) {
        if (file.isFile()) {
            return true;
        } else {
            // Start waiting 10 seconds maximum
            long timeout = System.currentTimeMillis() + FILE_WAIT_TIMEOUT;
            while (System.currentTimeMillis() <= timeout) {
                sleepQuietly(10);
                if (file.isFile()) {
                    return true;
                }
            }
        }
        // Timeout reached
        return false;
    }
1079126
public static boolean isImage( File file ){
		try {
			String mimeType = Files.probeContentType(file.toPath());
			if( mimeType == null ) {
				// In some OS there is a bug where it always returns null/
				String extension = FilenameUtils.getExtension(file.getName()).toLowerCase();
				String[] suffixes = ImageIO.getReaderFileSuffixes();
				for( String s : suffixes ) {
					if( s.equals(extension)) {
						return true;
					}
				}
			} else {
				return mimeType.startsWith("image");
			}
		} catch (IOException ignore) {}
		return false;
	}
865201
public static void watchFile(String file, SimpleHutoolWatcher watcher, boolean shouldFirstExecute) {
        if (shouldFirstExecute) {
            watcher.doSomething();
        }
        SimpleWatcher simpleWatcher = new SimpleWatcher() {
            @Override
            public void onModify(WatchEvent<?> event, Path currentPath) {
                watcher.onModify(event, currentPath);
                watcher.doSomething();
            }
        };
        try (WatchMonitor monitor = WatchMonitor.createAll(file, simpleWatcher)) {
            monitor.start();
        }
    }
1199778
public static boolean createEmptyFile(File file) {
        try {
            file.getParentFile().mkdirs();
            return file.createNewFile();
        } catch (Exception e) {
            return JMExceptionManager.handleExceptionAndReturnFalse(log, e,
                    "createEmptyFile", file);
        }

    }
319398
function(file) {
      var deferred = $q.defer();

      var reader = angular.extend(new FileReader(), {
        onload: function(e) {
          deferred.resolve(e.target.result);
          if (!$rootScope.$$phase) $rootScope.$apply();
        },
        onerror: function(e) {
          deferred.reject(e);
          if (!$rootScope.$$phase) $rootScope.$apply();
        },
        onabort: function(e) {
          deferred.reject(e);
          if (!$rootScope.$$phase) $rootScope.$apply();
        }
        // onprogress: Gee, it'd be great to get some progress support from $q...
      });
      reader.readAsDataURL(file);

      return angular.extend(deferred.promise, {
        abort: function() { reader.abort(); }
      });
    }
1041037
public static Object pollFile(File file, int timeout, int interval)
            throws InterruptedException {
        // Convert time from s to ms for Thread
        int fullTimeout = Math.round(timeout * 1000);

        // Split up the timeout to poll every x amount of time
        int timeoutShard = Math.round(fullTimeout / interval);

        // Poll until file exists, return if it exists
        for (int i = 0; i < interval; i++) {
            Thread.sleep(timeoutShard);
            if (file.exists()) {
                return readObjectFromFile(file);
            }
        }

        // Return null if time is up and still no file
        return null;
    }
750267
@Override
    public boolean fileCreated(File file) throws WatchingException {
        try {
            createApplicationBundle();
        } catch (Exception e) {
            throw new WatchingException(e.getMessage(), file, e);
        }
        return true;
    }
412849
public void queueFile (File file, boolean loop)
    {
        try {
            queueURL(file.toURI().toURL(), loop);
        } catch (MalformedURLException e) {
            log.warning("Invalid file url.", "file", file, e);
        }
    }
374081
public static String file(File file) throws IOException {
        FileInputStream fi = null;
        try {
            fi = new FileInputStream(file);
            return stream(fi, file.length());
        } finally {
            if (fi != null) {
                try {
                    fi.close();
                } catch (Throwable t) {
                }
            }
        }

    }
269250
public static void checkValidFile(final File file) {
        checkNotNull("file", file);
        if (!file.exists()) {
            throw new IllegalArgumentException("The file '" + file + "' does not exist!");
        }
        if (!file.isFile()) {
            throw new IllegalArgumentException("The name '" + file + "' is not a file!");
        }
    }
239382
public boolean accept(File file) {
        // extract this file's extension
        String fileExt = FileUtil.parseFileExtension(file.getName());

        // a file extension might not have existed
        if (fileExt == null) {
            // if no file extension extracted, this definitely is not a match
            return false;
        }

        // does it match our list of acceptable file extensions?
        for (String extension : extensions) {
            if (caseSensitive) {
                if (fileExt.equals(extension)) {
                    return true;
                }
            } else {
                if (fileExt.equalsIgnoreCase(extension)) {
                    return true;
                }
            }
        }
        
        // if we got here, then no match was found
        return false;
    }
351922
function readFile(file) {

    if (file && fs.existsSync(file)) {
        return fs.readFileSync(file);
    }

    return null;
}
790974
function fileExists(file) {
    try {
        var targetStat = fs.statSync(file);
        if (targetStat.isDirectory() ) {
            throw new Error("File exists but it's a driectory: " + file);
        }
    }
    catch(err) {
        if (err.code == 'ENOENT') {         // No such file or directory
            return false;
        }
        else {
            throw err;
        }
    }
    return true;
}
128350
private boolean waitForAdd(long waitStart, long maxWait) throws InterruptedException {
        while (this.size == 0) {
            if (!waitOnCondition(this.notEmpty, maxWait, waitStart)) {
                return false;
            }
        }

        return true;
    }
540892
def _wait_for_file(cls, filename, timeout=FAIL_WAIT_SEC, want_content=True):
    """"""
    def file_waiter():
      return os.path.exists(filename) and (not want_content or os.path.getsize(filename))

    action_msg = 'file {} to appear'.format(filename)
    return cls._deadline_until(file_waiter, action_msg, timeout=timeout)
315847
public File waitForNextFile(File pre) throws InterruptedException {
        try {
            lock.lockInterruptibly();
            if (binlogs.size() == 0) {
                nextCondition.await();// 等待新文件
            }

            if (exception != null) {
                throw exception;
            }
            if (pre == null) {// 第一次
                return binlogs.get(0);
            } else {
                int index = seek(pre);
                if (index < binlogs.size() - 1) {
                    return binlogs.get(index + 1);
                } else {
                    nextCondition.await();// 等待新文件
                    return waitForNextFile(pre);// 唤醒之后递归调用一下
                }
            }
        } finally {
            lock.unlock();
        }
    }
764761
function(file) {
      var type = file.type.toLowerCase(),
        sources = file.sources;

      $.each(sources, function(tmpSource) {
        if (_support[type][tmpSource]) {
          file = file.sources[tmpSource];
          file.type = type.toUpperCase();
          return false;
        }
      });
      if (file.source) {
        return file;
      } else {
        return false;
      }
    }