Restore and check hashinator config data from a file.
@param file hashinator config file
@param return the buffer with the raw data
@throws IOException
325231
public void restoreFromFile(File file) throws IOException
    {
        byte[] rawData = new byte[(int) file.length()];
        ByteBuffer bufData = null;
        FileInputStream fis = null;
        DataInputStream dis = null;
        try {
            fis = new FileInputStream(file);
            dis = new DataInputStream(fis);
            dis.readFully(rawData);
            bufData = ByteBuffer.wrap(rawData);
            restoreFromBuffer(bufData);
        }
        finally {
            if (dis != null) {
                dis.close();
            }
            if (fis != null) {
                fis.close();
            }
        }
    }
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);
        }
    }
796021
public static byte[] fileHash(File file, MessageDigest messageDigest)
            throws IOException {
        return computeHash(file, messageDigest, 0L, file.length());
    }
699073
static BlockMetadataHeader readHeader(File file) throws IOException {
    DataInputStream in = null;
    try {
      in = new DataInputStream(new BufferedInputStream(
                               new FileInputStream(file)));
      return readHeader(in);
    } finally {
      IOUtils.closeStream(in);
    }
  }
663333
protected void loadConfig(final String file) throws FileNotFoundException,
      IOException {
    final FileInputStream file_stream = new FileInputStream(file);
    try {
      final Properties props = new Properties();
      props.load(file_stream);

      // load the hash map
      loadHashMap(props);

      // no exceptions thrown, so save the valid path and exit
      LOG.info("Successfully loaded configuration file: " + file);
      config_location = file;
    } finally {
      file_stream.close();
    }
  }
277115
public static <T> T readObjectFromFile(File file) throws IOException,
  ClassNotFoundException {
    ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(
        new GZIPInputStream(new FileInputStream(file))));
    Object o = ois.readObject();
    ois.close();
    return ErasureUtils.<T> uncheckedCast(o);
  }
374081
public static String file(File file) throws IOException {
        FileInputStream fi = null;
        try {
            fi = new FileInputStream(file);
            return stream(fi, file.length());
        } finally {
            if (fi != null) {
                try {
                    fi.close();
                } catch (Throwable t) {
                }
            }
        }

    }
113594
public static void toFile(InputStream input, File file) throws IOException {
		OutputStream os = new FileOutputStream(file);
		int bytesRead = 0;
		byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
		while ((bytesRead = input.read(buffer, 0, DEFAULT_BUFFER_SIZE)) != -1) {
			os.write(buffer, 0, bytesRead);
		}
		IOUtils.closeQuietly(os);
		IOUtils.closeQuietly(input);
	}
269723
public void addPatternFromFile(String file) throws IOException {

		File f = new File(file);
		addPatternFromReader(new FileReader(f));
	}
838833
public static String readFileFromClasspath(String file) {
		logger.trace("Reading file [{}]...", file);
		String content = null;

		try (InputStream asStream = SettingsReader.class.getClassLoader().getResourceAsStream(file)) {
			if (asStream == null) {
				logger.trace("Can not find [{}] in class loader.", file);
				return null;
			}
			content = IOUtils.toString(asStream, "UTF-8");
		} catch (IOException e) {
			logger.warn("Can not read [{}].", file);
		}

		return content;
	}
1149021
public Configuration create(File file) {
        try {
            Configuration configuration;
            InputStream stream = new BufferedInputStream(new FileInputStream(file));
            try {
                configuration = create(stream);
            } finally {
                stream.close();
            }
            return configuration;
        } catch (IOException e) {
            throw new TextProcessorFactoryException(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());
    }
1049852
@Benchmark
	@BenchmarkMode(Mode.AverageTime)
	public void byteBufferRandomAccessFile(final Configuration configuration) throws IOException {
		ByteBuffer buffer = ByteBuffer.allocate(BUFFER_CAPACITY);

		try (RandomAccessFile file = new RandomAccessFile(configuration.file, "rw")) {
			for (long i = 0; i < LINES; ++i) {
				if (buffer.remaining() < DATA.length) {
					file.write(buffer.array(), 0, buffer.position());
					buffer.rewind();
				}

				if (buffer.remaining() < DATA.length) {
					file.write(DATA);
				} else {
					buffer.put(DATA);
				}
			}

			if (buffer.position() > 0) {
				file.write(buffer.array(), 0, buffer.position());
			}
		}
	}
1298545
public static String createHash(final File file, final String algorithm) {
        checkNotNull("file", file);
        checkNotNull("algorithm", algorithm);
        try {
            try (final FileInputStream in = new FileInputStream(file)) {
                return createHash(in, algorithm);
            }
        } catch (final IOException ex) {
            throw new RuntimeException(ex);
        }
    }
737964
public void storeSettingsToFile(File file) throws IOException {
    FileOutputStream fos = new FileOutputStream(file);
    this.conf.writeXml(fos);
    fos.close();
  }
177324
public static void setVerificationHeaders(HttpServletResponse response, File file)
  throws IOException {
    response.setHeader(TransferFsImage.CONTENT_LENGTH,
        String.valueOf(file.length()));
    MD5Hash hash = MD5FileUtils.readStoredMd5ForFile(file);
    if (hash != null) {
      response.setHeader(TransferFsImage.MD5_HEADER, hash.toString());
    }
  }
911541
public static byte[] md5(File file) throws IOException {
		try (InputStream in = new FileInputStream(file)) {
			return md5(in);
		}
	}