Shortcut for calling {@code Variables.fileValue(name).file(file).mimeType(type).create()}.
The name is set to the file name and the mime type is detected via {@link MimetypesFileTypeMap}.
6937
public static FileValue fileValue(File file){
    String contentType = MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType(file);
    return new FileValueBuilderImpl(file.getName()).file(file).mimeType(contentType).create();
  }
1233983
public File createFile(File file) throws DataUtilException {
        if(file == null) {
            throw new DataUtilException("File parameter can not be a null value");
        }

        try {
            if(! file.createNewFile()) {
                throw new DataUtilException("Failed to create file. Result of File.createNewFile() was false.");
            }
            trackedFiles.add(file);
        } catch (IOException e) {
            throw new DataUtilException("Failed to create file: " + file.getAbsolutePath(), e);
        }
        return file;
    }
726355
public static String getMimeType(String url)
	{
	    String type = null;
	    String extension = MimeTypeMap.getFileExtensionFromUrl(url);
	    if (extension != null) {
	        MimeTypeMap mime = MimeTypeMap.getSingleton();
	        type = mime.getMimeTypeFromExtension(extension);
	    }
	    return type;
	}
130301
public static Map<String, IDLProxyObject> create(File file) throws IOException {
        return create(file, false);
    }
1347847
function(name, type, filename, code) {
    this.name = name;
    this.type = type;
    this.filename = filename;
    this.code = code;
}
403809
public static boolean create(File file) {

		boolean created = false;

		// Validate or add the file extension
		if (GeoPackageIOUtils.hasFileExtension(file)) {
			GeoPackageValidate.validateGeoPackageExtension(file);
		} else {
			file = GeoPackageIOUtils.addFileExtension(file,
					GeoPackageConstants.GEOPACKAGE_EXTENSION);
		}

		if (file.exists()) {
			throw new GeoPackageException("GeoPackage already exists: "
					+ file.getAbsolutePath());
		} else {
			// Create the GeoPackage Connection
			GeoPackageConnection connection = connect(file);

			// Set the GeoPackage application id and user version
			connection.setApplicationId();
			connection.setUserVersion();

			// Create the minimum required tables
			GeoPackageTableCreator tableCreator = new GeoPackageTableCreator(
					connection);
			tableCreator.createRequired();

			connection.close();
			created = true;
		}

		return created;
	}
1255364
@Override
	public FSDataOutputStream create(Path f, WriteMode overwriteMode) throws IOException {
		return createOutputStream(() -> originalFs.create(f, overwriteMode));
	}
90281
public static ContentFileTypeMap ensureContentTypeManager() {
		FileTypeMap defaultMap = FileTypeMap.getDefaultFileTypeMap();
		if (!(defaultMap instanceof ContentFileTypeMap)) {
			defaultMap = new ContentFileTypeMap(defaultMap);
			FileTypeMap.setDefaultFileTypeMap(defaultMap);
		}
		return (ContentFileTypeMap) defaultMap;
	}
9685
@Override
    public FatLfnDirectoryEntry addFile(String name) throws IOException {
        checkWritable();
        checkUniqueName(name);
        
        name = name.trim();
        final ShortName sn = makeShortName(name);
        
        final FatLfnDirectoryEntry entry =
                new FatLfnDirectoryEntry(name, sn, this, false);

        dir.addEntries(entry.compactForm());
        
        shortNameIndex.put(sn, entry);
        longNameIndex.put(name.toLowerCase(Locale.ROOT), entry);

        getFile(entry.realEntry);
        
        dir.setDirty();
        return entry;
    }
262120
@Override
    protected FileType doGetType() throws Exception {
        // JDK BUG: 6192331
        // if (!file.exists())
        if (!file.exists() && file.length() < 1) {
            return FileType.IMAGINARY;
        }

        if (file.isDirectory()) {
            return FileType.FOLDER;
        }

        // In doubt, treat an existing file as file
        // if (file.isFile())
        // {
        return FileType.FILE;
        // }

        // throw new FileSystemException("vfs.provider.local/get-type.error", file);
    }
897520
public static <T extends File> T createFile(final SecurityContext securityContext, final InputStream fileStream, final Class<T> fileType, final PropertyMap props)
		throws FrameworkException, IOException {

		T newFile = (T) StructrApp.getInstance(securityContext).create(fileType, props);

		setFileData(newFile, fileStream, props.get(StructrApp.key(File.class, "contentType")));

		// schedule indexing
		newFile.notifyUploadCompletion();

		return newFile;
	}
1283074
public static MimeType parseMimeType(String mimeType) {
        if (Strings.isNullOrEmpty(mimeType)) {
            throw new InvalidMimeTypeException(mimeType, "'mimeType' must not be empty");
        }

        String[] parts = FluentIterable.from(Splitter.on(";").trimResults().split(mimeType)).toArray(String.class);

        String fullType = parts[0].trim();
        // java.net.HttpURLConnection returns a *; q=.2 Accept header
        if (MimeType.WILDCARD_TYPE.equals(fullType)) {
            fullType = "*/*";
        }
        int subIndex = fullType.indexOf('/');
        if (subIndex == -1) {
            throw new InvalidMimeTypeException(mimeType, "does not contain '/'");
        }
        if (subIndex == fullType.length() - 1) {
            throw new InvalidMimeTypeException(mimeType, "does not contain subtype after '/'");
        }
        String type = fullType.substring(0, subIndex);
        String subtype = fullType.substring(subIndex + 1, fullType.length());
        if (MimeType.WILDCARD_TYPE.equals(type) && !MimeType.WILDCARD_TYPE.equals(subtype)) {
            throw new InvalidMimeTypeException(mimeType, "wildcard type is legal only in '*/*' (all mime types)");
        }

        Map<String, String> parameters = null;
        if (parts.length > 1) {
            parameters = new LinkedHashMap<String, String>(parts.length - 1);
            for (int i = 1; i < parts.length; i++) {
                String parameter = parts[i];
                int eqIndex = parameter.indexOf('=');
                if (eqIndex != -1) {
                    String attribute = parameter.substring(0, eqIndex);
                    String value = parameter.substring(eqIndex + 1, parameter.length());
                    parameters.put(attribute, value);
                }
            }
        }

        try {
            return new MimeType(type, subtype, parameters);
        }
        catch (UnsupportedCharsetException ex) {
            throw new InvalidMimeTypeException(mimeType, "unsupported charset '" + ex.getCharsetName() + "'");
        }
        catch (IllegalArgumentException ex) {
            throw new InvalidMimeTypeException(mimeType, ex.getMessage());
        }
    }
1106938
@Transactional
  @PostMapping(value = "/{entityTypeId}", headers = "Content-Type=multipart/form-data")
  public void createFromFormPostMultiPart(
      @PathVariable("entityTypeId") String entityTypeId,
      MultipartHttpServletRequest request,
      HttpServletResponse response) {
    Map<String, Object> paramMap = new HashMap<>();
    for (String param : request.getParameterMap().keySet()) {
      String[] values = request.getParameterValues(param);
      String value = values != null ? StringUtils.join(values, ',') : null;
      if (StringUtils.isNotBlank(value)) {
        paramMap.put(param, value);
      }
    }

    // add files to param map
    for (Entry<String, List<MultipartFile>> entry : request.getMultiFileMap().entrySet()) {
      String param = entry.getKey();
      List<MultipartFile> files = entry.getValue();
      if (files != null && files.size() > 1) {
        throw new IllegalArgumentException("Multiple file input not supported");
      }
      paramMap.put(param, files != null && !files.isEmpty() ? files.get(0) : null);
    }
    createInternal(entityTypeId, paramMap, response);
  }
422187
def create_email(filepaths, collection_name):
    
    outer = MIMEMultipart()
    outer.preamble = 'Here are some files for you'

    def add_file_to_outer(path):
        if not os.path.isfile(path):
            return

        # Guess the content type based on the file's extension.  Encoding
        # will be ignored, although we should check for simple things like
        # gzip'd or compressed files.
        ctype, encoding = mimetypes.guess_type(path)
        if ctype is None or encoding is not None:
            # No guess could be made, or the file is encoded (compressed), so
            # use a generic bag-of-bits type.
            ctype = 'application/octet-stream'
        maintype, subtype = ctype.split('/', 1)

        if maintype == 'image':
            fp = open(path, 'rb')
            msg = MIMEImage(fp.read(), _subtype=subtype)
            fp.close()
        elif maintype == 'audio':
            fp = open(path, 'rb')
            msg = MIMEAudio(fp.read(), _subtype=subtype)
            fp.close()
        elif maintype == 'text':
            # We do this to catch cases where text files have
            # an encoding we can't guess correctly.
            try:
                fp = open(path, 'r')
                msg = MIMEText(fp.read(), _subtype=subtype)
                fp.close()
            except UnicodeDecodeError:
                fp = open(path, 'rb')
                msg = MIMEBase(maintype, subtype)
                msg.set_payload(fp.read())
                encoders.encode_base64(msg)
                fp.close()
        else:
            fp = open(path, 'rb')
            msg = MIMEBase(maintype, subtype)
            msg.set_payload(fp.read())
            fp.close()
            # Encode the payload using Base64
            encoders.encode_base64(msg)

        # Set the filename parameter
        msg.add_header('Content-Disposition', 'attachment',
                filename=os.path.basename(path))
        outer.attach(msg)

    outer.attach(MIMEText("Here are some files I've thrown at you."))
    
    for path in filepaths:
        add_file_to_outer(path)

    return outer
916893
static void createFileFromResource(String resource, Resource file) throws IOException {
	createFileFromResource(resource, file, null);
    }
710792
protected void generateFileTypeDetectionScript(String basename) {
		final CharSequence scriptContent = getFileTypeDetectionScript();
		if (scriptContent != null) {
			final String textualContent = scriptContent.toString();
			if (!Strings.isEmpty(textualContent)) {
				final byte[] bytes = textualContent.getBytes();
				for (final String output : getOutputs()) {
					final File directory = new File(output, FTDETECT_FOLDER).getAbsoluteFile();
					try {
						final File outputFile = new File(directory, basename);
						outputFile.getParentFile().mkdirs();
						Files.write(Paths.get(outputFile.getAbsolutePath()), bytes);
					} catch (IOException e) {
						throw new RuntimeException(e);
					}
				}
			}
		}
	}
328113
public void setMimeTypes(com.google.api.ads.admanager.axis.v201902.AssetCreativeTemplateVariableMimeType[] mimeTypes) {
        this.mimeTypes = mimeTypes;
    }