Convert a File into a ByteBuffer
@param file File to be converted
@return ByteBuffer containing the file
965434
public static ByteBuffer toByteBuffer(File file) {
        ByteBuffer buffer = ByteBuffer.allocateDirect((int) file.length());
        try {
            buffer.put(toByteArray(new FileInputStream(file)));
        } catch (IOException e) {
            logger.error("Failed to write file to byte array: " + e.getMessage());
        }
        buffer.flip();
        return buffer;
    }
95919
public static FileInputStream toStream(File file) {
		try {
			return new FileInputStream(file);
		} catch (FileNotFoundException e) {
			throw new IORuntimeException(e);
		}
	}
499611
public ByteBuffer makeByteBuffer(InputStream in)
        throws IOException {
        int limit = in.available();
        if (limit < 1024) limit = 1024;
        ByteBuffer result = byteBufferCache.get(limit);
        int position = 0;
        while (in.available() != 0) {
            if (position >= limit)
                // expand buffer
                result = ByteBuffer.
                    allocate(limit <<= 1).
                    put((ByteBuffer)result.flip());
            int count = in.read(result.array(),
                position,
                limit - position);
            if (count < 0) break;
            result.position(position += count);
        }
        return (ByteBuffer)result.flip();
    }
121407
public BufferedImage createImage(File file) throws IOException {
		resetAvailabilityFlags();
		this.data = PELoader.loadPE(file);
		image = new BufferedImage(fileWidth, height, IMAGE_TYPE);

		drawSections();

		Overlay overlay = new Overlay(data);
		if (overlay.exists()) {
			long overlayOffset = overlay.getOffset();
			drawPixels(colorMap.get(OVERLAY), overlayOffset,
					withMinLength(overlay.getSize()));
			overlayAvailable = true;
		}

		drawPEHeaders();
		drawSpecials();
		drawResourceTypes();
		assert image != null;
		assert image.getWidth() == fileWidth;
		assert image.getHeight() == height;
		return image;
	}
234744
@NonNull
  public static String readFromFile(@NonNull File file) throws FileNotFoundException {
    InputStream inputStream = new FileInputStream(file);
    Reader inputStreamReader = new InputStreamReader(inputStream);
    StringWriter output = new StringWriter();
    try {
      final char[] buffer = new char[DEFAULT_BUFFER_SIZE_IN_BYTES];
      int count;
      while ((count = inputStreamReader.read(buffer)) != -1) {
        output.write(buffer, 0, count);
      }
    } catch (IOException ioe) {
      Log.w(LOG_TAG, ioe.toString());
    } finally {
      try {
        inputStreamReader.close();
      } catch (IOException ioe) {
        Log.e(LOG_TAG, ioe.toString());
      }
    }
    return output.toString();
  }
471504
@Override
	public UserProfile convert(File file)
	{
		if(file == null)
			return null;
		
		try
		{
			String text = IO.readFile(file);
			
			if(text == null ||  text.length() == 0)
				return null;
			
			return converter.convert(text);
		}
		catch (IOException e)
		{
			throw new SystemException("Unable to convert file:"+
						file.getAbsolutePath()+" to user profile ERROR:"+e.getMessage(),e);
		}
	}
1032000
public static String readFileBufferedAsString(final File file, final String charset) throws IOException {
		return readInputStreamBufferedAsString(new FileInputStream(file), charset);
	}
712438
public static byte[] fileBytes(File file) throws IOException {

		FileInputStream fis = new FileInputStream(file);

		return streamBytes(fis);
	}
1352447
public static byte[] readFileAtOnce(final File file) throws IOException {
		final FileInputStream fIn = new FileInputStream(file);
		return readFileAtOnce(fIn);
	}
1343831
public static InputStream inputStream(File file) {
        // workaround http://stackoverflow.com/questions/36880692/java-file-does-not-exists-but-file-getabsolutefile-exists
        if (!file.exists()) {
            file = file.getAbsoluteFile();
        }
        if (!file.exists()) {
            throw E.ioException("File does not exists: %s", file.getPath());
        }
        try {
            return new FileInputStream(file);
        } catch (FileNotFoundException e) {
            throw E.ioException(e);
        }
    }
1093434
public static byte[] readContent(File file) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {
            copy(new BufferedInputStream(new FileInputStream(file)), baos);
        } catch (FileNotFoundException e) {
            throw E.ioException(e);
        }
        return baos.toByteArray();
    }
1081745
public static BufferedOutputStream getOutputStream(File file) throws IORuntimeException {
		try {
			return new BufferedOutputStream(new FileOutputStream(touch(file)));
		} catch (Exception e) {
			throw new IORuntimeException(e);
		}
	}
459469
@SuppressWarnings("resource")
    public static byte[] readFile(File file) throws IOException {

        // create input and output stream
        FileInputStream in = new FileInputStream(file);

        // read the content
        return readFully(in, (int)file.length());
    }
154091
public static InputStream fileAsStream(File file) {
    try {
      return new BufferedInputStream(new FileInputStream(file));
    } catch(FileNotFoundException e) {
      throw LOG.fileNotFoundException(file.getAbsolutePath(), e);
    }
  }
426396
public static SameDiff fromFlatFile(@NonNull File file) throws IOException {
        byte[] bytes;
        try (InputStream is = new BufferedInputStream(new FileInputStream(file))) {
            bytes = IOUtils.toByteArray(is);
        }

        ByteBuffer bbIn = ByteBuffer.wrap(bytes);
        return fromFlatBuffers(bbIn);
    }
456265
public static BufferedImage loadImage(File file){
		try {
			BufferedImage bimg = ImageIO.read(file);
			if(bimg == null){
				throw new ImageLoaderException("Could not load Image! ImageIO.read() returned null.");
			}
			return bimg;
		} catch (IOException e) {
			throw new ImageLoaderException(e);
		}
	}
47375
public INDArray toBgr(File file) {
        try {
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
            INDArray ret = toBgr(bis);
            bis.close();
            return ret;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }