Returns stream of fixes from the given file. If the file name ends in
'.gz' then the file is unzipped before being read.

@param file
@return fixes stream
340325
public static Observable<Fix> from(final File file, BinaryFixesFormat format) {

        Func0<InputStream> resourceFactory = new Func0<InputStream>() {

            @Override
            public InputStream call() {
                try {
                    if (file.getName().endsWith(".gz"))
                        return new GZIPInputStream(new FileInputStream(file));
                    else
                        return new FileInputStream(file);
                } catch (FileNotFoundException e) {
                    throw new RuntimeException(e);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        };

        Func1<InputStream, Observable<Fix>> obsFactory = new Func1<InputStream, Observable<Fix>>() {

            @Override
            public Observable<Fix> call(InputStream is) {
                Optional<Integer> mmsi;
                if (format == BinaryFixesFormat.WITH_MMSI)
                    mmsi = Optional.absent();
                else
                    mmsi = Optional.of(BinaryFixesUtil.getMmsi(file));

                return Observable.create(new BinaryFixesOnSubscribeWithBackp(is, mmsi, format));
            }
        };
        Action1<InputStream> disposeAction = new Action1<InputStream>() {

            @Override
            public void call(InputStream is) {
                try {
                    is.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        };
        return Observable.using(resourceFactory, obsFactory, disposeAction, true);

    }
1255183
protected InputStream initInput(final File file)
        throws MojoExecutionException {
        InputStream stream = null;
        try {
            if (file.isDirectory()) {
                throw new MojoExecutionException("File "
                    + file.getAbsolutePath()
                    + " is directory!");
            }
            if (!file.exists()) {
                throw new MojoExecutionException("File "
                    + file.getAbsolutePath()
                    + " does not exist!");
            }
            stream = new FileInputStream(file);
            //append to outfile here
        } catch (FileNotFoundException e) {
            throw new MojoExecutionException("Could not find file: "
                + file.getAbsolutePath(), e);
        }
        return stream;
    }
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);
  }
1032590
private static String decompress(File file) throws IOException {
        if (file == null || !file.exists()) {
            return Constants.EMPTY_STRING;
        }

        byte[] bytes = Base64.getDecoder().decode(IOUtils.toByteArray(new FileInputStream(file)));
        GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(bytes));
        BufferedReader bf = new BufferedReader(new InputStreamReader(gzipInputStream, UTF_8));
        StringBuilder outStr = new StringBuilder(Constants.EMPTY_STRING);
        String line;
        while ((line = bf.readLine()) != null) {
            outStr.append(line);
        }
        return outStr.toString();
    }
815907
public static Dependencies load(final File file) {
        Utils4J.checkNotNull("file", file);
        Utils4J.checkValidFile(file);
        try {
            final InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
            try {
                return load(inputStream);
            } finally {
                inputStream.close();
            }
        } catch (final IOException ex) {
            throw new RuntimeException(ex);
        }
    }
271073
public static String getExtension(String file)
    {
        Check.notNull(file);

        String ext = Constant.EMPTY_STRING;
        final int i = file.lastIndexOf(Constant.DOT);
        if (i >= 0 && i < file.length() - 1)
        {
            ext = file.substring(i + 1).toLowerCase(Locale.ENGLISH);
        }
        return ext;
    }
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;
	}
860091
public static OutputStream getFileOutputStream(String filename) throws IOException {
    OutputStream out = new FileOutputStream(filename);
    if (filename.endsWith(".gz")) {
      out = new GZIPOutputStream(out);
    } else if (filename.endsWith(".bz2")) {
      //out = new CBZip2OutputStream(out);
      out = getBZip2PipedOutputStream(filename);
    }
    return out;
  }
540774
public static OutputStream toFile(File file) throws FileNotFoundException {
		if(file != null) {
			return new FileOutputStream(file);
		}
		return null;
	}
584411
public InputStreamReader getFileStream(File file)
			throws NoSuchPathException{
		try {
			return new InputStreamReader(new FileInputStream(file));
		} catch (FileNotFoundException e) {
			throw new NoSuchPathException(e);
		}
	}
330131
public static List<File> unzipSkipHidden(File file) {
    return unzip(file, name -> name.startsWith(".") || name.startsWith("_") ? null : name);
  }
970724
static String getVersionForFile(final File file)  {
        try {
            final PluginMeta pluginMeta = loadMeta(file);
            return pluginMeta.getVersion();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
154091
public static InputStream fileAsStream(File file) {
    try {
      return new BufferedInputStream(new FileInputStream(file));
    } catch(FileNotFoundException e) {
      throw LOG.fileNotFoundException(file.getAbsolutePath(), e);
    }
  }
14902
static String readFile(String file) {

        try {
            FileReader     reader = new FileReader(file);
            BufferedReader read   = new BufferedReader(reader);
            StringBuffer   b      = new StringBuffer();
            String         s      = null;
            int            count  = 0;

            while ((s = read.readLine()) != null) {
                count++;

                b.append(s);
                b.append('\n');
            }

            read.close();
            reader.close();

            return b.toString();
        } catch (IOException e) {
            return e.getMessage();
        }
    }
461051
public FileDigestOutputStream openFile(File file) throws IOException
   {
      MessageDigest md;
      try
      {
         md = MessageDigest.getInstance(digestAlgo);
      }
      catch (NoSuchAlgorithmException e)
      {
         LOG.error("Can't wriet using " + digestAlgo + " algorithm, " + e, e);
         throw new IOException(e.getMessage(), e);
      }

      return new FileDigestOutputStream(file, md);
   }
888668
public String readFileContent(File file) {
        StringBuilder fileContentBuilder = new StringBuilder();
        if (file.exists()) {
            String stringLine;
            try {
                FileReader fileReader = new FileReader(file);
                BufferedReader bufferedReader = new BufferedReader(fileReader);
                while ((stringLine = bufferedReader.readLine()) != null) {
                    fileContentBuilder.append(stringLine + "\n");
                }
                bufferedReader.close();
                fileReader.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return fileContentBuilder.toString();
    }
220143
public static String slurpGZippedFile(File file) throws IOException {
    Reader r = new InputStreamReader(new GZIPInputStream(new FileInputStream(
        file)));
    return IOUtils.slurpReader(r);
  }