/**
   * This method actually writes the xml to disk.
   *
   * @param payload
   * @param path
   * @return
   */
  private static boolean exportXmlFile(ByteArrayPayload payload, String path) {
    // create data stream
    InputStream is = payload.getPayloadStream();
    int len = (int) payload.getLength();

    // read from data stream
    byte[] data = new byte[len];
    try {
      int read = is.read(data, 0, len);
      if (read > 0) {
        // write xml file
        try {
          // String filename = path + File.separator +
          // path.substring(path.lastIndexOf(File.separator) + 1) + ".xml";
          FileWriter fw = new FileWriter(path);
          fw.write(new String(data, "UTF-8"));
          fw.flush();
          fw.close();
          return true;

        } catch (IOException e) {
          Log.e(t, "Error writing XML file");
          e.printStackTrace();
          return false;
        }
      }
    } catch (IOException e) {
      Log.e(t, "Error reading from payload data stream");
      e.printStackTrace();
      return false;
    }

    return false;
  }
  /**
   * This method actually writes the xml to disk.
   *
   * @param payload
   * @param path
   * @return
   */
  static void exportXmlFile(ByteArrayPayload payload, String path) throws IOException {
    File file = new File(path);
    if (file.exists() && !file.delete()) {
      throw new IOException("Cannot overwrite " + path + ". Perhaps the file is locked?");
    }

    // create data stream
    InputStream is = payload.getPayloadStream();
    int len = (int) payload.getLength();

    // read from data stream
    byte[] data = new byte[len];
    //        try {
    int read = is.read(data, 0, len);
    if (read > 0) {
      // write xml file
      RandomAccessFile randomAccessFile = null;
      try {
        // String filename = path + File.separator +
        // path.substring(path.lastIndexOf(File.separator) + 1) + ".xml";
        randomAccessFile = new RandomAccessFile(file, "rws");
        randomAccessFile.write(data);
      } finally {
        if (randomAccessFile != null) {
          try {
            randomAccessFile.close();
          } catch (IOException e) {
            Log.e(t, "Error closing RandomAccessFile: " + path, e);
          }
        }
      }
    }
    //        } catch (IOException e) {
    //            Log.e(t, "Error reading from payload data stream");
    //            e.printStackTrace();
    //            return false;
    //        }
    //
    //        return false;
  }