private boolean writeFile(byte[] data) {
    String directoryName = Environment.getExternalStorageDirectory().getPath() + DOWNLOAD_DIRECTORY;
    File f = new File(directoryName);

    if (!f.isDirectory()) {
      if (!f.mkdir()) {
        return false;
      }
    }

    String filename = directoryName + "/" + objects.getCName();
    File object = new File(filename);
    BufferedOutputStream bos = null;

    try {
      FileOutputStream fos = new FileOutputStream(object);
      bos = new BufferedOutputStream(fos);
      bos.write(data);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      if (bos != null) {
        try {
          bos.flush();
          bos.close();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }
    return true;
  }
 private boolean fileIsDownloaded() {
   if (storageIsReady()) {
     String fileName =
         Environment.getExternalStorageDirectory().getPath()
             + "/RackspaceCloud/"
             + objects.getCName();
     File f = new File(fileName);
     return f.isFile();
   }
   return false;
 }
  private void loadObjectData() {
    // Object Name
    TextView name = (TextView) findViewById(R.id.view_container_name);
    name.setText(objects.getCName().toString());

    // File size
    if (objects.getBytes() >= bConver) {
      megaBytes = Math.abs(objects.getBytes() / bConver + 0.2);
      TextView sublabel = (TextView) findViewById(R.id.view_file_bytes);
      sublabel.setText(megaBytes + " MB");
    } else if (objects.getBytes() >= kbConver) {
      kiloBytes = Math.abs(objects.getBytes() / kbConver + 0.2);
      TextView sublabel = (TextView) findViewById(R.id.view_file_bytes);
      sublabel.setText(kiloBytes + " KB");
    } else {
      TextView sublabel = (TextView) findViewById(R.id.view_file_bytes);
      sublabel.setText(objects.getBytes() + " B");
    }

    // Content Type
    TextView cType = (TextView) findViewById(R.id.view_content_type);
    cType.setText(objects.getContentType().toString());

    // Last Modification date
    String strDate = objects.getLastMod();
    strDate = strDate.substring(0, strDate.indexOf('T'));
    /*
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.ssssss");
    Date dateStr = null;
    try {
    	dateStr = formatter.parse(strDate);
    } catch (ParseException e1) {
    	e1.printStackTrace();
    }
    String formattedDate = formatter.format(dateStr);

    Date date1 = null;
    try {
    	date1 = formatter.parse(formattedDate);
    } catch (ParseException e) {
    	e.printStackTrace();
    }
    formatter = new SimpleDateFormat("MMM-dd-yyyy");
    formattedDate = formatter.format(date1);
    */
    TextView lastmod = (TextView) findViewById(R.id.view_file_modification);
    lastmod.setText(strDate);
  }
 private void openFile() {
   File object =
       new File(
           Environment.getExternalStorageDirectory().getPath()
               + "/RackspaceCloud/"
               + objects.getCName());
   Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW);
   File file = new File(object.getAbsolutePath());
   String extension =
       android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(file).toString());
   String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
   myIntent.setDataAndType(Uri.fromFile(file), mimetype);
   // myIntent.setData(Uri.fromFile(file));
   try {
     startActivity(myIntent);
   } catch (Exception e) {
     Toast.makeText(this, "Could not open file.", Toast.LENGTH_SHORT).show();
   }
 }