Get a byte array from the given file.

@param tmpFile
The file.
@return Returns a byte array or null.
@throws IOException
Signals that an I/O exception has occurred.
332493
public static byte[] toByteArray(final File tmpFile) throws IOException
	{
		byte[] data = null;
		if (tmpFile.exists() && !tmpFile.isDirectory())
		{
			try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(tmpFile));
				ByteArrayOutputStream bos = new ByteArrayOutputStream(FileConst.KILOBYTE);)
			{
				StreamExtensions.writeInputStreamToOutputStream(bis, bos);
				data = bos.toByteArray();
			}
		}
		return data;
	}
129813
public static IArchiveFile getArchiveFile(final File pFile) {

		String extension = pFile.getName();
		if (extension.contains(".")){
			try {
				extension = extension.substring(extension.lastIndexOf(".") + 1);
			}catch (Exception ex){
				//just to catch any potential out of index errors
			}
		}
		Class<? extends IArchiveFile> aClass = extensionMap.get(extension.toLowerCase());
		if (aClass!=null){
			try {
				IArchiveFile provider = aClass.newInstance();
				provider.init(pFile);
				return provider;
			} catch (InstantiationException e) {
				Log.e(IMapView.LOGTAG, "Error initializing archive file provider " + pFile.getAbsolutePath(), e);
			} catch (IllegalAccessException e) {
				Log.e(IMapView.LOGTAG, "Error initializing archive file provider " + pFile.getAbsolutePath(), e);
			} catch (final Exception e) {
				Log.e(IMapView.LOGTAG,"Error opening archive file " + pFile.getAbsolutePath(), e);
			}
		}


		return null;
	}
1043968
public static byte[] getBytes(Object o)
    {
        if (o != null)
        {
            return getBytes(o, o.getClass());
        }

        return null;
    }
113341
public File getFile()
        throws IOException
    {
        // Try the permission hack
        if (checkConnection())
        {
            Permission perm = _connection.getPermission();
            if (perm instanceof java.io.FilePermission)
                return new File(perm.getName());
        }

        // Try the URL file arg
        try {return new File(_url.getFile());}
        catch(Exception e) {LogSupport.ignore(log,e);}

        // Don't know the file
        return null;    
    }
151102
@Nullable
  public static byte [] getAllFileBytes (@Nullable final File aFile)
  {
    return aFile == null ? null : StreamHelper.getAllBytes (FileHelper.getInputStream (aFile));
  }
1043880
public ByteBuffer getByteBuffer() throws IOException
    {
        return rwChannel.map( FileChannel.MapMode.READ_ONLY, 0, file.length() );
    }
435182
public static byte[] getBytes(File file) throws IOException {
		InputStream in = new FileInputStream(file);
		int fileSize = (int) file.length();

		if (fileSize > Integer.MAX_VALUE) {
			in.close();
			throw new IOException("File size to large: " + fileSize + " > " + Integer.MAX_VALUE);
		}

		byte[] bytes = new byte[fileSize];

		// Read in the bytes
		int offset = 0;
		int numRead = 0;
		while (offset < bytes.length && (numRead = in.read(bytes, offset, bytes.length-offset)) >= 0) {
			offset += numRead;
		}

		// Ensure all the bytes have been read in
		if (offset < bytes.length) {
			in.close();
			throw new IOException("Could not completely read file " + file.getName());
		}

		in.close();

		return bytes;
	}
119353
public byte[] getBytes() throws IOException {
        InputStream input = getInputStream();
        ByteArrayOutputStream output = new ByteArrayOutputStream();

        final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
        int len;

        try {
            while ((len = input.read(buffer)) != -1) {
                output.write(buffer, 0, len);
            }
        } finally {
            try {
                output.close();
            } catch (IOException e) {
                // ignore
            }
            try {
                input.close();
            } catch (IOException e) {
                // ignore
            }
        }

        return output.toByteArray();
    }
631146
private String getPemFileData() throws IOException {
        final String methodName = "getPemFileData";
        logger.entry(this, methodName);
        
        if (pemFileData != null) {
            logger.exit(this, methodName, pemFileData);
            return pemFileData;
        }
        
        final StringBuilder sb = new StringBuilder();
        final InputStreamReader isr = new InputStreamReader(new FileInputStream(pemFile), "US-ASCII");
        try {
            int ch;
            while ((ch = isr.read()) != -1) {
                sb.append((char)ch);
            }
        } finally {
            try {
                isr.close();
            } catch (IOException e) {
                logger.data(this, methodName, "Failed to close input stream reader. Reason: ", e);
            }
        }
        
        pemFileData = sb.toString();

        logger.exit(this, methodName, pemFileData);

        return pemFileData;
    }
136484
public static byte[] getLocalByteArray(File res) {
		try {
			return toByteArray(new FileInputStream(res));
		} catch (FileNotFoundException e) {
			logger.error("FileNotFound", e);
		} 
		return null;
	}
1053682
public static byte[] read(File file) throws IOException {
        FileInputStream is = new FileInputStream(file);
        try {
            return bytes(is);
        } finally {
            closeQuietly(is);
        }
    }
860373
public InputStream getInputStream(String pathToFile)
	throws IOException
	{
		File f = new File(pathToFile);
		return getInputStream(f);
	}
469592
private byte[] getFileContents(File file) {
    if (file.exists()) {
      try {
        return FileUtil.getFileContents(file);
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return null;
  }
662148
@Override
    public byte[] retrieveBytes(File impFi) {
        if ( resourceLocator != null ) {
            // does only return a result if a transpiler is registered
            byte[] bytes = resourceLocator.retrieveBytes(impFi);
            if ( bytes != null )
                return bytes;
        }
        return HtmlImportShim.ResourceLocator.super.retrieveBytes(impFi);
    }
637470
private String getMimeTypeFromFileExtension(String srcFile)
  {
    String srcFileLowCase = srcFile.toLowerCase();

    for (FileCompressionType compressionType : FileCompressionType.values())
    {
      if (srcFileLowCase.endsWith(compressionType.fileExtension))
      {
        return compressionType.mimeType + "/" +
               compressionType.mimeSubTypes.get(0);
      }
    }

    return null;
  }
839368
public static ByteBuffer readFile(File inFile) throws IOException {
        ByteBuffer mBuf;
        try (FileInputStream fIn = new FileInputStream(inFile);
             FileChannel fChan = fIn.getChannel()) {
            long fSize = fChan.size();
            mBuf = ByteBuffer.allocate((int) fSize);
            fChan.read(mBuf);
            mBuf.rewind();
        }
        return mBuf;
    }
21532
def with_tmpfile
      path = [@file, $$.to_s(36), Thread.current.object_id.to_s(36)].join
      file = File.open(path, 'wb')
      yield(path, file)
    ensure
      file.close unless file.closed?
      File.unlink(path) if File.exists?(path)
    end