Reads all the bytes of a given file into an array. If the file size exceeds Integer.MAX_VALUE, it will be truncated.

@param localSwfFile
swf file
@return file bytes
496294
public static byte[] readAsByteArray(File localSwfFile) {
        byte[] fileBytes = new byte[(int) localSwfFile.length()];
        byte[] b = new byte[1];
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(localSwfFile);
            for (int i = 0; i < Integer.MAX_VALUE; i++) {
                if (fis.read(b) != -1) {
                    fileBytes[i] = b[0];
                } else {
                    break;
                }
            }
        } catch (IOException e) {
            log.warn("Exception reading file bytes", e);
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                }
            }
        }
        return fileBytes;
    }
1352447
public static byte[] readFileAtOnce(final File file) throws IOException {
		final FileInputStream fIn = new FileInputStream(file);
		return readFileAtOnce(fIn);
	}
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);
        }
    }
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;
	}
461741
public Path upload(final File localFile) throws IOException {

    if (!localFile.exists()) {
      throw new FileNotFoundException(localFile.getAbsolutePath());
    }

    final Path source = new Path(localFile.getAbsolutePath());
    final Path destination = new Path(this.path, localFile.getName());

    try {
      this.fileSystem.copyFromLocalFile(source, destination);
    } catch (final IOException ex) {
      LOG.log(Level.SEVERE, "Unable to upload " + source + " to " + destination, ex);
      throw ex;
    }

    LOG.log(Level.FINE, "Uploaded {0} to {1}", new Object[] {source, destination});

    return destination;
  }
605007
public SftpFile[] getFiles(String remote, String local)
			throws FileNotFoundException, SftpStatusException, SshException,
			TransferCancelledException {
		return getFiles(remote, local, false);
	}
962399
public void get(String remoteFileName,
                    File localFile)
        throws IOException,
               ClientException,
               ServerException {
        if (gSession.transferMode == GridFTPSession.MODE_EBLOCK) {
            DataSink sink =
                new FileRandomIO(new RandomAccessFile(localFile, "rw"));
            get(remoteFileName, sink, null);
        } else {
            super.get(remoteFileName, localFile);
        }
    }
712438
public static byte[] fileBytes(File file) throws IOException {

		FileInputStream fis = new FileInputStream(file);

		return streamBytes(fis);
	}
118581
def readlocal(path, offset=None, size=-1):
    
    try:
        with open(path, 'rb') as f:
            if offset:
                f.seek(offset)
            buf = f.read(size)
    except IOError as e:
        if e.errno == errno.ENOENT:
            raise FileNotFoundError(e)
        else:
            raise
    return buf
236262
public byte[] readRawBytes(final int numberOfBytes) {
    final byte[] tmpArr = new byte[numberOfBytes];
    System.arraycopy(buf, position, tmpArr, 0, numberOfBytes);
    position += numberOfBytes;
    return tmpArr;
  }
886744
public static byte[] byteBufToArray(ByteBuf byteBuf) {
        int length = byteBuf.readableBytes();
        byte[] byteArray = new byte[length];
        byteBuf.getBytes(byteBuf.readerIndex(), byteArray);
        return byteArray;
    }
456236
public ByteBuffer readToByteBuffer(int max) throws IOException {
        Validate.isTrue(max >= 0, "maxSize must be 0 (unlimited) or larger");
        final boolean localCapped = max > 0; // still possibly capped in total stream
        final int bufferSize = localCapped && max < DefaultSize ? max : DefaultSize;
        final byte[] readBuffer = new byte[bufferSize];
        final ByteArrayOutputStream outStream = new ByteArrayOutputStream(bufferSize);

        int read;
        int remaining = max;

        while (true) {
            read = read(readBuffer);
            if (read == -1) break;
            if (localCapped) { // this local byteBuffer cap may be smaller than the overall maxSize (like when reading first bytes)
                if (read >= remaining) {
                    outStream.write(readBuffer, 0, remaining);
                    break;
                }
                remaining -= read;
            }
            outStream.write(readBuffer, 0, read);
        }
        return ByteBuffer.wrap(outStream.toByteArray());
    }
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;
	}
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;
    }
1164551
public static byte[] copyToByteArray(File in) throws IOException {
        assert in != null : "No input File specified";

        return copyToByteArray(new BufferedInputStream(Files.newInputStream(in.toPath())));
    }
475143
public static byte[] readFileToBytes( String filePath ) throws IOException {
        Path path = Paths.get(filePath);
        byte[] bytes = Files.readAllBytes(path);
        return bytes;
    }
258109
public void initSwfVerification(String swfFilePath) {
        log.info("Initializing swf verification for: {}", swfFilePath);
        byte[] bytes = null;
        if (swfFilePath != null) {
            File localSwfFile = new File(swfFilePath);
            if (localSwfFile.exists() && localSwfFile.canRead()) {
                log.info("Swf file path: {}", localSwfFile.getAbsolutePath());
                bytes = FileUtil.readAsByteArray(localSwfFile);
            } else {
                bytes = "Red5 is awesome for handling non-accessable swf file".getBytes();
            }
        } else {
            bytes = new byte[42];
        }
        calculateHMAC_SHA256(bytes, 0, bytes.length, GENUINE_FP_KEY, 30, swfHash, 0);
        swfSize = bytes.length;
        log.info("Verification - size: {}, hash: {}", swfSize, Hex.encodeHexString(swfHash));
    }