GetHtml: a 40-line public method that takes a string url and returns the content of whatever is found at that url as a string (null if status code != 200 or an exception is thrown)



  • } catch (IOException e) {
      result = null;
    } finally {
      try {
        if (stream != null) {
          stream.close();
        }
      } catch (IOException e) {
        System.out.println("Failed to close input stream when closing connection while downloading custom CSS");
      }
      httpClient.getConnectionManager().shutdown();
    }
    


  • Looks to me as if there's the actual method missing?



  • The ultimate in future proofing bullet proof code. Designed for the day when the Internet is fully evolved and perfect and achieves a true binary state. I.e. Either the Resource exists and is provided, or it doesn't exist. The onus then is on the internet to create the content before the request is repeated. This last was a compromise after much debate and flurries of RFC's. The final argument being, that there is no end to infinity, even if you provide all possible resources, and besides it is cheaper to go with a modified version of "just in time" warehousing.



  • I wish.



  • Looks like fairly common Java <7 stream handling. Is the issue here that crusty old java code is crusty and old?



  • Well, mostly its just really half-ass, and I'm really pissed about the name, and that it's logging to stdout, and that its called getHtml but it has an error message about downloading css and that it takes a string URL and that I'm only even in here because one of my coworkers had an outstanding issue open where they had had a bug reported, identified what the problem was, commented on the issue "yeah, there's a missing / in the url at xxx" and then JUST FUCKING LEFT IT LIKE THAT FOR SIX MONTHS.

    What exactly is the deal with posting other people's code? I figured the snippet above was fine because there's absolutely nothing unique in it, apart from the error message which I anonymized anyway, but I'm not comfortable just copy/pasting an entire method.



  • @Buddy said:

    I figured the snippet above was fine

    Worked for me. It didn't lay it out on a plate, but that wasn't needed. Every thing I needed was in the title (in this case). Of course I could not appreciate the full nuance of the :wtf: because you would be there forever typing it up. Which is an exercise of limited value, because at some (unknown) point you would trigger the ACTIVATE_PEDANT flag, and thereafter be wasting your effort.
    👍



  • Yeah its hard work anonymizing code, and I always seem to miss out some crucial detail.


Log in to reply