Example #1
0
  /**
   * decodes an entire file's contents into plain text that was encoded with quoted-printable.
   *
   * @param filepath The path to the quoted-printable encoded file to decode.
   * @return The decoded string.
   * @throws ObjectDisposedException A problem occurred while attempting to decode the encoded
   *     string.
   * @throws OutOfMemoryException There is insufficient memory to allocate a buffer for the returned
   *     string.
   * @throws ArgumentNullException A string is passed in as a null reference.
   * @throws IOException An I/O error occurs, such as the stream being closed.
   * @throws FileNotFoundException The file was not found.
   * @throws SecurityException The caller does not have the required permission to open the file
   *     specified in filepath.
   * @throws UnauthorizedAccessException filepath is read-only or a directory.
   *     <p>Decodes a quoted-printable encoded file into a string of unencoded text of any size.
   */
  public static String decodeFile(String filepath) throws Exception {
    if (filepath == null) throw new ArgumentNullException();

    String decodedHtml = "", line;
    File f = new File(filepath);
    if (!f.Exists) throw new FileNotFoundException();

    BufferedReader sr = f.OpenText();
    try {
      while ((line = sr.readLine()) != null) decodedHtml += decode(line);
      return decodedHtml;
    } finally {
      sr.close();
      sr = null;
      f = null;
    }
  }