private byte[] encodeBase64 (File file, boolean isChunked)
            throws IOException {
        byte[] buf = null;

        if (!file.isFile())
            throw new IOException(file.getAbsolutePath() + ": is not a file.");

        buf = new byte[(int) file.length()];
        FileInputStream in = new FileInputStream(file);
        int bytesRead = 0;
        do {
            bytesRead = in.read(buf, bytesRead, buf.length - bytesRead);
        } while (bytesRead > 0);

        return Base64.encodeBase64(buf, isChunked);
    }