Package java.net

Examples of java.net.URLConnection


    String mimeType = null;
    for (URL resource : resources) {
      if ("file".equals(resource.getProtocol())) {
        isFile = true;
      }
      URLConnection resourceConn = resource.openConnection();
      if (resourceConn.getLastModified() > lastModified) {
        lastModified = resourceConn.getLastModified();
      }

      String currentMimeType = servletContext.getMimeType(resource.getPath());
      if (currentMimeType == null) {
        String extension = resource.getPath().substring(resource.getPath().lastIndexOf('.'));
        currentMimeType = DEFAULT_MIME_TYPES.get(extension);
      }
      if (mimeType == null) {
        mimeType = currentMimeType;
      } else if (!mimeType.equals(currentMimeType)) {
        throw new MalformedURLException("Combined resource path: " + rawResourcePath
            + " is invalid. All resources in a combined resource path must be of the same mime type.");
      }
      contentLength += resourceConn.getContentLength();
      try {
        resourceConn.getInputStream().close();
      } catch (Exception e) {
        /*ignore, just trying to free resources*/
      }
      try {
        resourceConn.getOutputStream().close();
      } catch (Exception e) {
        /*ignore, just trying to free resources*/
      }
    }

 
View Full Code Here


    }

    long lastModified = -1;

    for (URL resource : resources) {
      URLConnection resourceConn;
      try {
        resourceConn = resource.openConnection();
      } catch (IOException e) {
        return -1;
      }
      if (resourceConn.getLastModified() > lastModified) {
        lastModified = resourceConn.getLastModified();
      }
      try {
        resourceConn.getInputStream().close();
      } catch (Exception e) {
        /*ignore, just trying to free resources*/
      }
      try {
        resourceConn.getOutputStream().close();
      } catch (Exception e) {
        /*ignore, just trying to free resources*/
      }
    }
    return lastModified;
View Full Code Here

    OutputStream out = selectOutputStream(request, response);

    try {
      for (URL resource : resources) {
        URLConnection resourceConn = resource.openConnection();
        InputStream in = resourceConn.getInputStream();
        try {
          byte[] buffer = new byte[1024];
          while (in.available() > 0) {
            int len = in.read(buffer);
            out.write(buffer, 0, len);
          }
        } finally {
          in.close();
          try {
            resourceConn.getOutputStream().close();
          } catch (Exception e) {
            /*ignore, just trying to free resources*/
          }
        }
      }
 
View Full Code Here

    String mimeType = null;
    for (URL resource : resources) {
      if ("file".equals(resource.getProtocol())) {
        isFile = true;
      }
      URLConnection resourceConn = resource.openConnection();
      if (resourceConn.getLastModified() > lastModified) {
        lastModified = resourceConn.getLastModified();
      }

      String currentMimeType = getServletContext().getMimeType(resource.getPath());
      if (currentMimeType == null) {
        String extension = resource.getPath().substring(resource.getPath().lastIndexOf('.'));
        currentMimeType = DEFAULT_MIME_TYPES.get(extension);
      }
      if (mimeType == null) {
        mimeType = currentMimeType;
      } else if (!mimeType.equals(currentMimeType)) {
        throw new MalformedURLException("Combined resource path: " + rawResourcePath
            + " is invalid. All resources in a combined resource path must be of the same mime type.");
      }
      contentLength += resourceConn.getContentLength();
      try {
        resourceConn.getInputStream().close();
      } catch (Exception e) {
        /*ignore, just trying to free resources*/
      }
      try {
        resourceConn.getOutputStream().close();
      } catch (Exception e) {
        /*ignore, just trying to free resources*/
      }
    }

 
View Full Code Here

    }

    long lastModified = -1;

    for (URL resource : resources) {
      URLConnection resourceConn;
      try {
        resourceConn = resource.openConnection();
      } catch (IOException e) {
        return -1;
      }
      if (resourceConn.getLastModified() > lastModified) {
        lastModified = resourceConn.getLastModified();
      }
      try {
        resourceConn.getInputStream().close();
      } catch (Exception e) {
        /*ignore, just trying to free resources*/
      }
      try {
        resourceConn.getOutputStream().close();
      } catch (Exception e) {
        /*ignore, just trying to free resources*/
      }
    }
    return lastModified;
View Full Code Here

     */
    protected Collection<BibtexEntry> getBibtexEntries(String ticket, String citations)
        throws IOException {
        try {
            URL url = new URL(URL_BIBTEX);
            URLConnection conn = url.openConnection();
            conn.setRequestProperty("Cookie", ticket + "; " + citations);
            conn.connect();

            BibtexParser parser = new BibtexParser(new BufferedReader(new InputStreamReader(conn
                .getInputStream())));
            return parser.parse().getDatabase().getEntries();
        } catch (MalformedURLException e) {
            // Propagate...
            throw new RuntimeException(e);
View Full Code Here

     * @return a Jstor ticket ID
     * @throws IOException
     */
    protected String openTicket() throws IOException {
        URL url = new URL(URL_TICKET);
        URLConnection conn = url.openConnection();
        return getCookie(COOKIE_TICKET, conn);
    }
View Full Code Here

        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }

        URL url = new URL(urlQuery);
        URLConnection conn = url.openConnection();
        conn.setRequestProperty("Cookie", ticket);
        return getCookie(COOKIE_CITATIONS, conn);
    }
View Full Code Here

    ArrayList extensionJars = new ArrayList();
    for (int i = 0; i < extensionJarsAndDlls.size(); i++) {
      URL extensionJarOrDllUrl = (URL)extensionJarsAndDlls.get(i);
      try {
        String extensionJarOrDllUrlFile = extensionJarOrDllUrl.getFile();
        URLConnection connection = null;
        long extensionJarOrDllFileDate;
        String extensionJarOrDllFile;
        if (extensionJarOrDllUrl.getProtocol().equals("jar")) {
          // Don't instantiate connection to a file accessed by jar protocol otherwise it might download again its jar container
          URL jarEntryUrl = new URL(extensionJarOrDllUrlFile.substring(0, extensionJarOrDllUrlFile.indexOf('!')));
          URLConnection jarEntryUrlConnection = jarEntryUrl.openConnection();
          // As connection.getLastModified() on an entry returns get modification date of the jar file itself
          extensionJarOrDllFileDate = jarEntryUrlConnection.getLastModified();
          extensionJarOrDllFile = extensionJarOrDllUrlFile.substring(extensionJarOrDllUrlFile.indexOf('!') + 2);
        } else {
          connection = extensionJarOrDllUrl.openConnection();
          extensionJarOrDllFileDate = connection.getLastModified();
          extensionJarOrDllFile = extensionJarOrDllUrlFile;
View Full Code Here

    } catch ( MalformedURLException e ) {
      throw new FreedbException("The URL: "+url+" is invalid, remove any accents from the search terms and try again");
    }
    assert url != null;

    URLConnection connection = null;

    try {
      connection = url.openConnection();
      setupProxy(connection);
    } catch ( IOException e ) {
      //e.printStackTrace();
      throw new FreedbException( "Error while trying to connect to freedb server, "+e.getMessage()+". Check your internet connection settings." );
    }
    assert connection != null;

    String output = null;

    try {
      InputStreamReader isr = new InputStreamReader( connection.getInputStream() );
           
      BufferedReader in = new BufferedReader( isr );
      String inputLine;

      output = "";
View Full Code Here

TOP

Related Classes of java.net.URLConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.