Get a media from an existing file descriptor. {@link #setResourcesDirectory(String)} must be activated.

@param file The file descriptor (must not be <code>null</code>).
@return The media instance.
@throws LionEngineException If invalid parameter.
437802
public static synchronized Media get(File file)
    {
        Check.notNull(file);

        final String filename = file.getPath();
        final String localFile = filename.substring(resourcesDir.length() + filename.lastIndexOf(resourcesDir));

        return create(localFile);
    }
531806
@Nonnull
    public static String readFile(@Nonnull File file, @Nonnull Charset charset) throws IOException {
        if (file == null)
            throw new NullPointerException("Given 'file' can not be null");
        if (!file.exists())
            throw new IllegalArgumentException("File " + file.getAbsolutePath() + " does not exist");
        if (file.isDirectory())
            throw new IllegalArgumentException("File " + file.getAbsolutePath() + " can NOT be a directory");

        InputStream in = new BufferedInputStream(new FileInputStream(file));
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        copy(in, bos);
        return new String(bos.toByteArray(), charset);

    }
916897
public static <T> T readObjectFromFile(String file, Class<T> clazz) {
        return readObjectFromFile(file, clazz, false);
    }
1137701
public static String getContentMimeType(final java.io.File file, final String name) throws IOException {

		String mimeType;

		// try name first, if not null
		if (name != null) {
			mimeType = mimeTypeMap.getContentType(name);
			if (mimeType != null && !UNKNOWN_MIME_TYPE.equals(mimeType)) {
				return mimeType;
			}
		}

		try (final InputStream is = new BufferedInputStream(new FileInputStream(file))) {

			final MediaType mediaType = new DefaultDetector().detect(is, new Metadata());
			if (mediaType != null) {

				mimeType = mediaType.toString();
				if (mimeType != null) {

					return mimeType;
				}
			}

		} catch (NoClassDefFoundError t) {
			logger.warn("Unable to instantiate MIME type detector: {}", t.getMessage());
		}

		// no success :(
		return UNKNOWN_MIME_TYPE;
	}
736007
private static InputStream getFileAsInputStream(String file) throws InitializationException {
		if (file == null) {
			throw new NullPointerException("File is null");
		}
		try {
			return new FileInputStream(new File(file));
		} catch (FileNotFoundException e) {
			throw new InitializationException("File not found: " + file);
		}
	}
540040
public static String readFile(File file) {
		FileInputStream inputStream;
		try {
			inputStream = new FileInputStream(file);
			return new String(readStream(inputStream));
		} catch (FileNotFoundException e) {
			JK.throww(e);
			return null;
		}
	}
682859
public static File noDirectory(File file) {
		Validate.exists(file);
		if(file.isDirectory())
			throw new ParameterException("\""+file+"\" is a directory!");
		return file;
	}
124048
public static File createDirectoryTree( File file ) throws IOException
    {
        if (file.isDirectory() && file.canWrite()) return file;
        if (file.isDirectory())
            throw new IOException( "Directory not writable " + file.getAbsolutePath() );
        if (file.exists())
            throw new IOException( file.getAbsolutePath() + " is not a directory" );
        boolean created = file.mkdirs();
        if (!created) throw new IOException( "Could not create directory " + file.getAbsolutePath() );

        return file;
    }
1181977
public Configurator fromFile(File file) {
        if (!file.exists()) throw new FileNotFoundException(file.getAbsolutePath() + "does not exist.");
        return new Configurator(Uri.fromFile(file));
    }
464551
@SuppressWarnings("unchecked")
    public static <T> T load(File file) {
        try {
            FileInputStream fis = new FileInputStream(file);
            ObjectInputStream inStream = 
                new ObjectInputStream(new BufferedInputStream(fis));
            T object = (T) inStream.readObject();
            inStream.close();
            return object;
        } catch (IOException ioe) {
            throw new IOError(ioe);
        } catch (ClassNotFoundException cnfe) {
            throw new IOError(cnfe);
        }
    }
944309
public static Attachment fromBinaryFile( File file, MediaType mediaType ) throws IOException {
        FileInputStream stream = new FileInputStream( file );
        try {
            return fromBinaryInputStream( stream, mediaType );
        } finally {
            ResourceUtil.close( stream );
        }
    }
813672
public SendAudio setAudio(File file) {
        Objects.requireNonNull(file, "file cannot be null!");
        this.audio = new InputFile(file, file.getName());
        return this;
    }
71405
public SourceFile getSourceFile(File file) throws IOException
	{
		SourceFile source = sourceFiles.get(file);

		if (source == null)
		{
			source = new SourceFile(file);
			sourceFiles.put(file, source);
		}

		return source;
	}
519048
public static Properties fromFile(
    final File file)
    throws IOException
  {
    Objects.requireNonNull(file, "File");

    try (InputStream stream = Files.newInputStream(file.toPath())) {
      final Properties p = new Properties();
      p.load(stream);
      return p;
    }
  }
972178
public static Uri getUriForInternalMedia(Context context, File file) {
        String authority = context.getPackageName() + ".fileprovider";
        return FileProvider.getUriForFile(context, authority, file);
    }
28477
public static synchronized File getJarResources()
    {
        if (!loader.isPresent())
        {
            throw new LionEngineException(JAR_LOADER_ERROR);
        }

        final Media media = Medias.create(Constant.EMPTY_STRING);
        final String path = media.getFile().getPath().replace(File.separator, Constant.SLASH);
        final String prefix = loader.get().getPackage().getName().replace(Constant.DOT, Constant.SLASH);
        final int jarSeparatorIndex = path.indexOf(prefix);
        final String jar = path.substring(0, jarSeparatorIndex);

        return new File(jar);
    }
817458
public void fromXML(String file) throws DocumentException
    {
        SAXReader reader = new SAXReader();
        fromXML(reader.read(new StringReader(file)));
    }