Return a new File object based on the baseDir and the segments.

This method does not perform any operation on the file system.
497945
public static File newFile(File baseDir, String... segments) {
        File f = baseDir;
        for (String segment : segments) {
            f = new File(f, segment);
        }
        return f;
    }
436535
def from_file(filename_or_file_object):
    
    if isinstance(filename_or_file_object, basestring):
        file_ = open(filename_or_file_object, 'r')
        we_opened = True
    else:
        we_opened = False
        file_ = filename_or_file_object

    try:
        data = load(file_.read())
    finally:
        if we_opened:
            file_.close()

    return data
691786
public static File locateFile(String name, String basedir) {
    // Try exact match first.
    File f = new File(name);
    if(f.exists()) {
      return f;
    }
    // Try with base directory
    if(basedir != null) {
      if((f = new File(basedir, name)).exists()) {
        return f;
      }
    }
    // try stripping whitespace
    String name2;
    if(!name.equals(name2 = name.trim())) {
      if((f = locateFile(name2, basedir)) != null) {
        return f;
      }
    }
    // try substituting path separators
    if(!name.equals(name2 = name.replace('/', File.separatorChar))) {
      if((f = locateFile(name2, basedir)) != null) {
        return f;
      }
    }
    if(!name.equals(name2 = name.replace('\\', File.separatorChar))) {
      if((f = locateFile(name2, basedir)) != null) {
        return f;
      }
    }
    // try stripping extra characters, such as quotes.
    if(name.length() > 2 && name.charAt(0) == '"' && name.charAt(name.length() - 1) == '"') {
      if((f = locateFile(name.substring(1, name.length() - 1), basedir)) != null) {
        return f;
      }
    }
    return null;
  }
1090228
def open(self, mode='r', buffering=-1, encoding=None,
             errors=None, newline=None):
        
        if self._closed:
            self._raise_closed()
        return FakeFileOpen(self.filesystem, use_io=True)(
            self._path(), mode, buffering, encoding, errors, newline)
530440
public static FilesIterator<String> getAbsoluteNamesIterator(String baseDir) {
		return new FilesIterator<String>(new File(baseDir), Strategy.NAMES);
	}
574968
def __getFileObj(self, f):
        """"""
        if not f:
            raise ShapefileException("Shapefile Reader requires a shapefile or file-like object.")
        if self.shp and self.shpLength is None:
            self.load()
        if self.dbf and len(self.fields) == 0:
            self.load()
        return f
406929
def fromFile(cls, filename):
		

		# Load the file
		oFile = open(filename)

		# Convert it to a dictionary
		dDetails = JSON.decodef(oFile)

		# Create and return the new instance
		return cls(dDetails)
229566
def _OpenFileObject(self, path_spec):
    
    if not path_spec.HasParent():
      raise errors.PathSpecError(
          'Unsupported path specification without parent.')

    parent_path_spec = path_spec.parent

    file_system = resolver.Resolver.OpenFileSystem(
        parent_path_spec, resolver_context=self._resolver_context)

    # Note that we cannot use pyewf's glob function since it does not
    # handle the file system abstraction dfvfs provides.
    segment_file_path_specs = ewf.EWFGlobPathSpec(file_system, path_spec)
    if not segment_file_path_specs:
      return None

    if parent_path_spec.IsSystemLevel():
      # Typically the file-like object cache should have room for 127 items.
      self._resolver_context.SetMaximumNumberOfFileObjects(
          len(segment_file_path_specs) + 127)

    for segment_file_path_spec in segment_file_path_specs:
      file_object = resolver.Resolver.OpenFileObject(
          segment_file_path_spec, resolver_context=self._resolver_context)
      self._file_objects.append(file_object)

    ewf_handle = pyewf.handle()
    ewf_handle.open_file_objects(self._file_objects)
    return ewf_handle
435844
public Segment createSegment(SegmentDescriptor descriptor) {
    switch (storage.level()) {
      case MEMORY:
        return createMemorySegment(descriptor);
      case MAPPED:
        if (descriptor.version() == 1) {
          return createMappedSegment(descriptor);
        } else {
          return createDiskSegment(descriptor);
        }
      case DISK:
        return createDiskSegment(descriptor);
      default:
        throw new AssertionError();
    }
  }
594058
def get_filelikeobject(filename: str = None,
                       blob: bytes = None) -> BinaryIO:
    
    if not filename and not blob:
        raise ValueError("no filename and no blob")
    if filename and blob:
        raise ValueError("specify either filename or blob")
    if filename:
        return open(filename, 'rb')
    else:
        return io.BytesIO(blob)
1256219
def new(cls, pic_id, filename, rId, cx, cy):
        
        pic = parse_xml(cls._pic_xml())
        pic.nvPicPr.cNvPr.id = pic_id
        pic.nvPicPr.cNvPr.name = filename
        pic.blipFill.blip.embed = rId
        pic.spPr.cx = cx
        pic.spPr.cy = cy
        return pic
564296
private void openNewPartFile() throws Exception {
		closeCurrentPartFile();

		Path newBucketDirectory = bucketer.getNextBucketPath(new Path(basePath));

		if (!newBucketDirectory.equals(currentBucketDirectory)) {
			currentBucketDirectory = newBucketDirectory;
			try {
				if (fs.mkdirs(currentBucketDirectory)) {
					LOG.debug("Created new bucket directory: {}", currentBucketDirectory);
				}
			} catch (IOException e) {
				throw new RuntimeException("Could not create base path for new rolling file.", e);
			}
		}

		int subtaskIndex = getRuntimeContext().getIndexOfThisSubtask();
		currentPartPath = new Path(currentBucketDirectory, partPrefix + "-" + subtaskIndex + "-" + partCounter);

		// This should work since there is only one parallel subtask that tries names with
		// our subtask id. Otherwise we would run into concurrency issues here.
		while (fs.exists(currentPartPath) ||
				fs.exists(getPendingPathFor(currentPartPath)) ||
				fs.exists(getInProgressPathFor(currentPartPath))) {
			partCounter++;
			currentPartPath = new Path(currentBucketDirectory, partPrefix + "-" + subtaskIndex + "-" + partCounter);
		}

		// increase, so we don't have to check for this name next time
		partCounter++;

		LOG.debug("Next part path is {}", currentPartPath.toString());

		Path inProgressPath = getInProgressPathFor(currentPartPath);
		writer.open(fs, inProgressPath);
		isWriterOpen = true;
	}
910468
public static FilesIterator<File> getRelativeIterator(String baseDir) {
		return new FilesIterator<File>(new File(baseDir), Strategy.RELATIVE_FILES);
	}
938956
def new_from_files(self, basepath, basename, repo, \
                    bohrs=False, \
                    software=_E_SW.ORCA, \
                    repo_clobber=False, **kwargs):
        

        # Imports
        import os
        from os import path as osp
        from ..xyz import OpanXYZ as OX
        from ..grad import OrcaEngrad as OE
        from ..hess import OrcaHess as OH
        from .repo import OpanAnharmRepo as OR
        from ..const import EnumDispDirection as E_DDir, EnumFileType as E_FT
        from ..const import EnumSoftware as E_SW
        from ..const import DEF
        from ..error import AnharmError as ANHErr

##        # Store working directory for restore?
##        prev_dir = os.getcwd()

        # Complain if anything is already bound
        if not self.w_xyz == None:
            raise ANHErr(ANHErr.STATUS,
                    "XYZ object is already bound",
                    "")
        ## end if
        if not self.w_grad == None:
            raise ANHErr(ANHErr.STATUS,
                    "GRAD object is already bound",
                    "")
        ## end if
        if not self.w_hess == None:
            raise ANHErr(ANHErr.STATUS,
                    "HESS object is already bound",
                    "")
        ## end if
        if not self.repo == None:
            raise ANHErr(ANHErr.STATUS,
                    "Repository object is already bound",
                    "")
        ## end if

        # RESUME: vpt2--factor for loading from different software pkgs

        # Load the three data files
        self.w_xyz = OX( osp.join(basepath, \
                basename + osp.extsep + xyz_ext) )
        self.w_grad = OE( osp.join(basepath, \
                basename + osp.extsep + engrad_ext), \
                0, E_DDir.NO_DISP, 0.0 )
        self.w_hess = OH( osp.join(basepath, \
                basename + osp.extsep + hess_ext), \
                0, E_DDir.NO_DISP, 0.0 )

        # Only accept new repos for now
        if not isinstance(repo, str):
            raise TypeError("Must create new repository when loading " +
                    "a new dataset.")
        ## end if

        # Repo is string, treat as filename and try to load
        # Check if it's a complete path
        # If it's a relative path, prepend the basepath
        if osp.split(repo[0]) > 0 and not osp.isabs(repo):
            repo = osp.join(basepath, repo)
        ## end if

        # Complain if it's a directory
        if osp.isdir(repo):
            raise IOError("Cannot bind repository -- specified " +
                    "location is a directory")
        ## end if

        # If file exists ...
        if osp.isfile(repo):
                # Depending on clobber, either delete existing or raise error
                if repo_clobber:
                    # Clobber old repo
                    os.remove(repo)
                else:
                    # Raise error
                    raise IOError("Target repository file exists and " +
                            "clobber is disabled.")
                ## end if
            ## end if

        # Should be good to create the repo
        self.repo = OR(repo)
723684
def create(self, object_name, size=0, hash=None, extra=None, meta_data=None):
        
        obj = BaseObject(container=self.container,
                         driver=self.driver,
                         name=object_name,
                         size=size,
                         hash=hash,
                         extra=extra,
                         meta_data=meta_data)
        return Object(obj=obj)
1087923
def create_from_file(cls, filename):
        """"""
        obj = cls()
        obj.object_file = filename
        obj.load()
        return obj
1115777
def get_file(id, query = {} )
      response = self.get('files', id, query).body
      return OmekaClient::OmekaFile.new(self, JSON.parse(response))
    end