Gets the contents of the given file, as a byte array.

@param pFile the file to get content from
@return the content of the file as a byte array.
@throws IOException if the read operation fails
509233
public static byte[] read(File pFile) throws IOException {
        // Custom implementation, as we know the size of a file
        if (!pFile.exists()) {
            throw new FileNotFoundException(pFile.toString());
        }

        byte[] bytes = new byte[(int) pFile.length()];
        InputStream in = null;

        try {
            // Use buffer size two times byte array, to avoid i/o bottleneck
            in = new BufferedInputStream(new FileInputStream(pFile), BUF_SIZE * 2);

            int off = 0;
            int len;
            while ((len = in.read(bytes, off, in.available())) != -1 && (off < bytes.length)) {
                off += len;
                //              System.out.println("read:" + len);
            }
        }
        // Just pass any IOException on up the stack
        finally {
            close(in);
        }

        return bytes;
    }
20705
public static byte[] getBytes(URL url) throws IOException {
        final String path = url.getPath();
        final File file = new File(path);
        if (file.exists()) {
            return getFileBytes(file);
        }

        return null;
    }
1012824
static byte[] getBytesHttpOld(String pURL) throws IOException {
        // Get the input stream from the url
        InputStream in = new BufferedInputStream(getInputStreamHttp(pURL), BUF_SIZE * 2);

        // Get all the bytes in loop
        byte[] bytes = new byte[0];
        int count;
        byte[] buffer = new byte[BUF_SIZE];

        try {
            while ((count = in.read(buffer)) != -1) {

                // NOTE: According to the J2SE API doc, read(byte[]) will read
                // at least 1 byte, or return -1, if end-of-file is reached.
                bytes = (byte[]) CollectionUtil.mergeArrays(bytes, 0, bytes.length, buffer, 0, count);
            }
        }
        finally {

            // Close the buffer
            in.close();
        }
        return bytes;
    }
919516
private static byte[] readBytes(final File aFile) throws IOException {
        final FileInputStream fileStream = new FileInputStream(aFile);
        final ByteBuffer buf = ByteBuffer.allocate((int) aFile.length());
        final int read = fileStream.getChannel().read(buf);

        if (read != aFile.length()) {
            fileStream.close();
            throw new IOException(LOGGER.getI18n(MessageCodes.UTIL_044, aFile));
        }

        fileStream.close();
        return buf.array();
    }
267324
public static File unzipUniqueFile(File inFile) throws IOException {
        File outFile = File.createTempFile(inFile.getName(), "tmp");
        try {
            BufferedOutputStream out = null;
            ZipInputStream in = new ZipInputStream(new BufferedInputStream(
                    new FileInputStream(inFile)));
            in.getNextEntry();
            int count;
            byte data[] = new byte[1024];
            out = new BufferedOutputStream(new FileOutputStream(outFile), 1024);
            while ((count = in.read(data, 0, 1024)) != -1) {
                out.write(data, 0, count);
            }
            out.flush();
            out.close();
            in.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return outFile;
    }
265375
private function getImageMimeType($pFile = '')
    {
        if (PHPExcel_Shared_File::file_exists($pFile)) {
            $image = getimagesize($pFile);
            return image_type_to_mime_type($image[2]);
        } else {
            throw new PHPExcel_Writer_Exception("File $pFile does not exist");
        }
    }
1162282
public static byte[] readBytes(File file) throws IOException {
        byte[] bytes = new byte[(int) file.length()];
        FileInputStream fileInputStream = new FileInputStream(file);
        DataInputStream dis = new DataInputStream(fileInputStream);
        try {
            dis.readFully(bytes);
            InputStream temp = dis;
            dis = null;
            temp.close();
        } finally {
            closeWithWarning(dis);
        }
        return bytes;
    }
475143
public static byte[] readFileToBytes( String filePath ) throws IOException {
        Path path = Paths.get(filePath);
        byte[] bytes = Files.readAllBytes(path);
        return bytes;
    }
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;
	}
441486
function loadJsonAsArray($pFile)
    {
        $contents = \file_get_contents($pFile);
        $returnValue = \json_decode($contents, true);

        if (!$this->isArray($returnValue)) {
            $returnValue = [];
        }

        return $returnValue;
    }
1053682
public static byte[] read(File file) throws IOException {
        FileInputStream is = new FileInputStream(file);
        try {
            return bytes(is);
        } finally {
            closeQuietly(is);
        }
    }
151102
@Nullable
  public static byte [] getAllFileBytes (@Nullable final File aFile)
  {
    return aFile == null ? null : StreamHelper.getAllBytes (FileHelper.getInputStream (aFile));
  }
1086370
private static String readPRJFile(File prjFile) throws FileNotFoundException, IOException {
        try (FileInputStream fis = new FileInputStream(prjFile)) {
            BufferedReader r = new BufferedReader(new InputStreamReader(fis, Charset.defaultCharset()));
            StringBuilder b = new StringBuilder();
            while (r.ready()) {
                b.append(r.readLine());
            }
            return b.toString();
        }
    }
866970
public static byte[] readBytes(File file) throws IOException {
        FileInputStream fis = null;
        ByteArrayOutputStream bos = null;
        if (file == null) {
            throw new FileNotFoundException("No file specified");
        }
        try {
            fis = new FileInputStream(file);
            bos = new ByteArrayOutputStream();
            byte[] buffer = new byte[BUFFER_SIZE];
            int remaining;
            while ((remaining = fis.read(buffer)) > 0) {
                bos.write(buffer, 0, remaining);
            }
            return bos.toByteArray();
        } finally {
            Closeables.closeQuietly(fis);
            Closeables.closeQuietly(bos);
        }
    }
1184704
public static String readFileContents(File file) throws IOException {

        try (Scanner in = new Scanner(file)) {
            in.useDelimiter("\\Z");
            return (in.next());
        }       
    }
274214
private static byte[] decodePem(File pemFile) throws IOException {
        BufferedReader reader = new BufferedReader(new FileReader(pemFile));
        try {
            String line;
            while ((line = reader.readLine()) != null) {
                if (line.contains("-----BEGIN ")) {
                    return readBytes(pemFile, reader, line.trim().replace("BEGIN", "END"));
                }
            }
            throw new IOException("PEM " + pemFile + " is invalid: no begin marker");
        } finally {
            reader.close();
        }
    }
222437
public static byte[] getBytesFromHttp(String httpFileURL) throws IOException {

        InputStream bufferedInputStream = null;
        try {
            bufferedInputStream = getInputStreamFromHttp(httpFileURL);
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            byte[] buffer = new byte[BUFFER_SIZE];
            for (int len = 0; (len = bufferedInputStream.read(buffer)) != -1;) {
                byteArrayOutputStream.write(buffer, 0, len);
            }
            byte[] arrayOfByte1 = byteArrayOutputStream.toByteArray();
            return arrayOfByte1;
        } finally {
            if (bufferedInputStream != null)
                bufferedInputStream.close();
        }
    }