/**
   * This method only uses the default Commons HttpClient implementation when the URL object
   * represents a HTTP resource. The URL object could also represent a file or some JNDI resource.
   * In that case, the default Java implementation is used.
   *
   * @return A string representation of the resource referenced by the URL object
   */
  public String URLtoString(URL url) throws IOException {
    String xml = null;

    if (url != null) {
      String protocol = url.getProtocol().toLowerCase();

      if (protocol.startsWith(Http.HTTP) || protocol.startsWith(Http.HTTPS)) {

        return URLtoString(url.toString());
      }

      URLConnection urlConnection = url.openConnection();

      InputStream inputStream = urlConnection.getInputStream();

      UnsyncByteArrayOutputStream unsyncByteArrayOutputStream = new UnsyncByteArrayOutputStream();

      byte[] bytes = new byte[512];

      for (int i = inputStream.read(bytes, 0, 512); i != -1; i = inputStream.read(bytes, 0, 512)) {

        unsyncByteArrayOutputStream.write(bytes, 0, i);
      }

      xml =
          new String(
              unsyncByteArrayOutputStream.unsafeGetByteArray(),
              0,
              unsyncByteArrayOutputStream.size());

      inputStream.close();

      unsyncByteArrayOutputStream.close();
    }

    return xml;
  }