Returns the corresponding input file in the 'sourceDirPath' for the specified lock file.
If no such file is found then returns null
344831
private Path getFileForLockFile(Path lockFile, Path sourceDirPath)
          throws IOException {
    String lockFileName = lockFile.getName();
    Path dataFile = new Path(sourceDirPath + Path.SEPARATOR + lockFileName + inprogress_suffix);
    if( hdfs.exists(dataFile) ) {
      return dataFile;
    }
    dataFile = new Path(sourceDirPath + Path.SEPARATOR +  lockFileName);
    if(hdfs.exists(dataFile)) {
      return dataFile;
    }
    return null;
  }
1347372
synchronized String findPath(INodeFileUnderConstruction pendingFile) 
         throws IOException {
     Lease lease = getLease(pendingFile.getClientName());
     if (lease != null) {
       String src = lease.findPath(pendingFile);
       if (src != null) {
         return src;
       }
     }
     throw new IOException("pendingFile (=" + pendingFile + ") not found."
           + "(lease=" + lease + ")");
   }
710846
public int lock()
  {
      if (tc.isEntryEnabled()) Tr.entry(tc, "lock");

      int result = LOCK_FAILURE;

      // Ensure that the target lock files exist.
      if (!_lockFilesExist)
      {
          if (tc.isDebugEnabled()) Tr.debug(tc,"Confirming/Creating the lock files");

          _handle1 = ensureFileExists(RECOVERY_FILE_1_NAME);
          if (_handle1 != null)
          {
              _handle2 = ensureFileExists(RECOVERY_FILE_2_NAME);

              if (_handle2 != null)
              {
                _lockFilesExist = true;
              }
              else
              {
                Tr.error(tc,"CWRLS0004_RECOVERY_LOG_CREATE_FAILED", _lockDirectory + File.separator + RECOVERY_FILE_2_NAME);
                _handle1 = null;
              }
          }
          else
          {
            Tr.error(tc,"CWRLS0004_RECOVERY_LOG_CREATE_FAILED",  _lockDirectory + File.separator + RECOVERY_FILE_1_NAME);
          }
      }
      else
      {
          if (tc.isDebugEnabled()) Tr.debug(tc,"Already Confirmed/Created the lock files");
      }

      if (_lockFilesExist)
      {
        result = obtainLock(_handle1);

        if (result == LOCK_SUCCESS)
        {
          result = obtainLock(_handle2);

          if (result != LOCK_SUCCESS)
          {
            if (result == LOCK_FAILURE)
            {
               Tr.error(tc,"CWRLS0005_RECOVERY_LOG_LOCK_FAILED", _lockDirectory + File.separator + RECOVERY_FILE_2_NAME);
            }

            releaseLock(_handle1);
          }
        }
        else if (result == LOCK_FAILURE)
        {
          Tr.error(tc,"CWRLS0005_RECOVERY_LOG_LOCK_FAILED", _lockDirectory + File.separator + RECOVERY_FILE_1_NAME);
        }
      }

      if (tc.isEntryEnabled()) Tr.exit(tc, "lock",new Integer(result));
      return result;
  }
468344
public static FileLock getFileLock(java.io.RandomAccessFile file, String fileName) throws java.io.IOException
    {
        return (FileLock) Utils.getImpl("com.ibm.ws.objectManager.utils.FileLockImpl",
                                        new Class[] { java.io.RandomAccessFile.class, String.class },
                                        new Object[] { file, fileName });
    }
886096
def with_index_lock
      lock_path = "#{@index_file}.lock"
      File.open(lock_path, "w+") do |f|
        f.flock(File::LOCK_EX)
        yield
      end
    end
407673
private static InputStream inputStreamFromFile(String relativePathPrefix, String src) throws IOException {
        File file = getFile(relativePathPrefix, src);
        if (!file.exists()) {
            if (src.length() > 0 && src.charAt(0) == File.separatorChar) {
                file = getFile(relativePathPrefix, src.substring(1));
            }
            if (!file.exists()) {
                file = null;
            }
        } else if (!file.isFile() || !file.canRead()) {
            file = null;
        }
        if (file != null) {
            return new FileInputStream(file);
        }
        return null;
    }
833629
@Nullable
  public static File findFile(@Nullable final Class<?> clazz) {
    if (null == clazz) return null;
    String name = clazz.getName();
    if (null == name) return null;
    final String path = name.replaceAll("\\.", "/").replaceAll("\\$.*", "");
    return com.simiacryptus.util.lang.CodeUtil.findFile(path + ".java");
  }
659985
public static Path copyFile(Path src, Path dest, StandardCopyOption... options) throws IORuntimeException {
		Assert.notNull(src, "Source File is null !");
		Assert.notNull(dest, "Destination File or directiory is null !");

		Path destPath = dest.toFile().isDirectory() ? dest.resolve(src.getFileName()) : dest;
		try {
			return Files.copy(src, destPath, options);
		} catch (IOException e) {
			throw new IORuntimeException(e);
		}
	}
121734
protected ResourceEntry findResourceInternal(String name, String path) {

        if (!started) {
            log.info(sm.getString("webappClassLoader.stopped", name));
            return null;
        }

        if ((name == null) || (path == null))
            return null;

        ResourceEntry entry = (ResourceEntry) resourceEntries.get(name);
        if (entry != null)
            return entry;

        int contentLength = -1;
        InputStream binaryStream = null;

        int jarFilesLength = jarFiles.length;
        int repositoriesLength = repositories.length;

        int i;

        Resource resource = null;

        boolean fileNeedConvert = false;

        for (i = 0; (entry == null) && (i < repositoriesLength); i++) {
            try {

                String fullPath = repositories[i] + path;

                Object lookupResult = resources.lookup(fullPath);
                if (lookupResult instanceof Resource) {
                    resource = (Resource) lookupResult;
                }

                // Note : Not getting an exception here means the resource was
                // found
                 if (securityManager != null) {
                    PrivilegedAction dp =
                        new PrivilegedFindResource(files[i], path);
                    entry = (ResourceEntry)AccessController.doPrivileged(dp);
                 } else {
                    entry = findResourceInternal(files[i], path);
                 }

                ResourceAttributes attributes =
                    (ResourceAttributes) resources.getAttributes(fullPath);
                contentLength = (int) attributes.getContentLength();
                entry.lastModified = attributes.getLastModified();

                if (resource != null) {


                    try {
                        binaryStream = resource.streamContent();
                    } catch (IOException e) {
                        return null;
                    }

                    if (needConvert) {
                        if (path.endsWith(".properties")) {
                            fileNeedConvert = true;
                        }
                    }

                    // Register the full path for modification checking
                    // Note: Only syncing on a 'constant' object is needed
                    synchronized (allPermission) {

                        int j;

                        long[] result2 = 
                            new long[lastModifiedDates.length + 1];
                        for (j = 0; j < lastModifiedDates.length; j++) {
                            result2[j] = lastModifiedDates[j];
                        }
                        result2[lastModifiedDates.length] = entry.lastModified;
                        lastModifiedDates = result2;

                        String[] result = new String[paths.length + 1];
                        for (j = 0; j < paths.length; j++) {
                            result[j] = paths[j];
                        }
                        result[paths.length] = fullPath;
                        paths = result;

                    }

                }

            } catch (NamingException e) {
            }
        }

        if ((entry == null) && (notFoundResources.containsKey(name)))
            return null;

        JarEntry jarEntry = null;

        synchronized (jarFiles) {

            if (!openJARs()) {
                return null;
            }
            for (i = 0; (entry == null) && (i < jarFilesLength); i++) {

                jarEntry = jarFiles[i].getJarEntry(path);

                if (jarEntry != null) {

                    entry = new ResourceEntry();
                    try {
                        entry.codeBase = getURL(jarRealFiles[i], false);
                        String jarFakeUrl = getURI(jarRealFiles[i]).toString();
                        jarFakeUrl = "jar:" + jarFakeUrl + "!/" + path;
                        entry.source = new URL(jarFakeUrl);
                        entry.lastModified = jarRealFiles[i].lastModified();
                    } catch (MalformedURLException e) {
                        return null;
                    }
                    contentLength = (int) jarEntry.getSize();
                    try {
                        entry.manifest = jarFiles[i].getManifest();
                        binaryStream = jarFiles[i].getInputStream(jarEntry);
                    } catch (IOException e) {
                        return null;
                    }

                    // Extract resources contained in JAR to the workdir
                    if (antiJARLocking && !(path.endsWith(".class"))) {
                        byte[] buf = new byte[1024];
                        File resourceFile = new File
                            (loaderDir, jarEntry.getName());
                        if (!resourceFile.exists()) {
                            Enumeration entries = jarFiles[i].entries();
                            while (entries.hasMoreElements()) {
                                JarEntry jarEntry2 = 
                                    (JarEntry) entries.nextElement();
                                if (!(jarEntry2.isDirectory()) 
                                    && (!jarEntry2.getName().endsWith
                                        (".class"))) {
                                    resourceFile = new File
                                        (loaderDir, jarEntry2.getName());
                                    resourceFile.getParentFile().mkdirs();
                                    FileOutputStream os = null;
                                    InputStream is = null;
                                    try {
                                        is = jarFiles[i].getInputStream
                                            (jarEntry2);
                                        os = new FileOutputStream
                                            (resourceFile);
                                        while (true) {
                                            int n = is.read(buf);
                                            if (n <= 0) {
                                                break;
                                            }
                                            os.write(buf, 0, n);
                                        }
                                    } catch (IOException e) {
                                        // Ignore
                                    } finally {
                                        try {
                                            if (is != null) {
                                                is.close();
                                            }
                                        } catch (IOException e) {
                                        }
                                        try {
                                            if (os != null) {
                                                os.close();
                                            }
                                        } catch (IOException e) {
                                        }
                                    }
                                }
                            }
                        }
                    }

                }

            }

            if (entry == null) {
                synchronized (notFoundResources) {
                    notFoundResources.put(name, name);
                }
                return null;
            }

            if (binaryStream != null) {

                byte[] binaryContent = new byte[contentLength];

                int pos = 0;
                try {

                    while (true) {
                        int n = binaryStream.read(binaryContent, pos,
                                                  binaryContent.length - pos);
                        if (n <= 0)
                            break;
                        pos += n;
                    }
                    binaryStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                    return null;
                } catch (Exception e) {
                    e.printStackTrace();
                    return null;
                }

                if (fileNeedConvert) {
                    String str = new String(binaryContent,0,pos);
                    try {
                        binaryContent = str.getBytes("UTF-8");
                    } catch (Exception e) {
                        return null;
                    }
                }
                entry.binaryContent = binaryContent;

                // The certificates are only available after the JarEntry 
                // associated input stream has been fully read
                if (jarEntry != null) {
                    entry.certificates = jarEntry.getCertificates();
                }

            }

        }

        // Add the entry in the local resource repository
        synchronized (resourceEntries) {
            // Ensures that all the threads which may be in a race to load
            // a particular class all end up with the same ResourceEntry
            // instance
            ResourceEntry entry2 = (ResourceEntry) resourceEntries.get(name);
            if (entry2 == null) {
                resourceEntries.put(name, entry);
            } else {
                entry = entry2;
            }
        }

        return entry;

    }
1138660
private InputStream getResourceInputStream(String path) {
		InputStream is = config.getContext().getResourceAsStream(path);
		if (is == null) {
			try {
				is = ClassLoaderResourceUtils.getResourceAsStream(path, this);
			} catch (FileNotFoundException e) {
				throw new BundlingProcessException(e);
			}
		}

		return is;
	}
1334995
def lock_file(filename, interval=.5, timeout=15):
    '''
    
    '''
    log.trace('Attempting to obtain lock for %s', filename)
    lock = filename + '.lock'
    start = time.time()
    while True:
        if os.path.exists(lock):
            if time.time() - start >= timeout:
                log.warning('Unable to obtain lock for %s', filename)
                return False
            time.sleep(interval)
        else:
            break

    with salt.utils.files.fopen(lock, 'a'):
        pass
687669
def _obtain_lock(self):
        """"""
        starttime = time.time()
        maxtime = starttime + float(self._max_block_time)
        while True:
            try:
                super(BlockingLockFile, self)._obtain_lock()
            except IOError:
                # synity check: if the directory leading to the lockfile is not
                # readable anymore, raise an exception
                curtime = time.time()
                if not osp.isdir(osp.dirname(self._lock_file_path())):
                    msg = "Directory containing the lockfile %r was not readable anymore after waiting %g seconds" % (
                        self._lock_file_path(), curtime - starttime)
                    raise IOError(msg)
                # END handle missing directory

                if curtime >= maxtime:
                    msg = "Waited %g seconds for lock at %r" % (maxtime - starttime, self._lock_file_path())
                    raise IOError(msg)
                # END abort if we wait too long
                time.sleep(self._check_interval)
            else:
                break
939000
public static File getFile(String resourceOrFile, Class<?> cls,
            boolean deleteTmpOnExit) throws FileNotFoundException {
        try {

            // jar:file:/home/.../blue.jar!/path/to/file.xml
            URI uri = getURL(resourceOrFile, cls).toURI();
            String uriStr = uri.toString();
            if (uriStr.startsWith("jar")) {

                if (uriStr.endsWith("/")) {
                    throw new UnsupportedOperationException(
                            "cannot unjar directories, only files");
                }

                String jarPath = uriStr.substring(4, uriStr.indexOf("!"))
                        .replace("file:", "");
                String filePath = uriStr.substring(uriStr.indexOf("!") + 2);

                JarFile jarFile = new JarFile(jarPath);
                assert (jarFile.size() > 0) : "no jarFile at " + jarPath;

                Enumeration<JarEntry> entries = jarFile.entries();

                while (entries.hasMoreElements()) {

                    JarEntry jarEntry = entries.nextElement();
                    if (jarEntry.toString().equals(filePath)) {
                        InputStream input = jarFile.getInputStream(jarEntry);
                        assert (input != null) : "empty is for " + jarEntry;
                        return tmpFileFromStream(input, filePath,
                                deleteTmpOnExit);
                    }
                }
                assert (false) : "file" + filePath + " not found in " + jarPath;
                return null;
            } else {
                return new File(uri);
            }

        } catch (URISyntaxException e) {
            throw new FileNotFoundException(resourceOrFile);
        } catch (IOException e) {
            throw new FileNotFoundException(resourceOrFile);
        }
    }
748212
def lock_pid(self):
        
        
        if os.path.exists(self.lock_filename):
            return int(open(self.lock_filename).read())
        else:
            return None
1004591
@Override
    public File findFile(RepositoryPointerImpl location) {
        // Assume that instanceIds are good and check fileId only.
        File result = getChild(location.getFileId());
        return isFile(result) ? result : null;
    }
418754
public function get($path, $lock = false)
    {
        if ($this->isFile($path)) {
            return $lock ? $this->sharedGet($path) : file_get_contents($path);
        }

        throw new FileNotFoundException("File does not exist at path {$path}");
    }
1020844
public static InputStream fromFile(String filepath) throws FileNotFoundException {
		if(Strings.isValid(filepath)) {
			return fromFile(new File(filepath));
		}
		return null;
	}