Package java.net

Examples of java.net.URLConnection


    filesLastModified = new HashMap<String, Long>();

    // store file sizes and mark which files not to download
    fileSizes = new int[urlList.length];

    URLConnection urlconnection;

    File cacheFile = new File(dir, "cache");

    // if cache file exists, load it
    if (cacheFile.exists()) {
      filesLastModified = readCacheFile(cacheFile);
    }

    // calculate total size of jars to download
    for (int i = 0; i < urlList.length; i++) {
      urlconnection = urlList[i].openConnection();
      urlconnection.setDefaultUseCaches(false);
      if (urlconnection instanceof HttpURLConnection) {
        ((HttpURLConnection) urlconnection).setRequestMethod("HEAD");
      }

      fileSizes[i] = urlconnection.getContentLength();

      long lastModified = urlconnection.getLastModified();
      String fileName = getFileName(urlList[i]);


      if (cacheEnabled && lastModified != 0 &&
          filesLastModified.containsKey(fileName)) {
View Full Code Here


   */
  protected void downloadJars(String path) throws Exception {

    setState(STATE_DOWNLOADING);

    URLConnection urlconnection;

    int initialPercentage = percentage = 15;

    // download each jar
    byte buffer[] = new byte[65536];
    for (int i = 0; i < urlList.length; i++) {

      // skip file if marked as -2 (already downloaded and not changed)
      if (fileSizes[i] == -2) continue;

      int unsuccessfulAttempts = 0;
      int maxUnsuccessfulAttempts = 3;
      boolean downloadFile = true;

      // download the jar a max of 3 times
      while(downloadFile) {
        downloadFile = false;

        debug_sleep(2000);

        urlconnection = urlList[i].openConnection();

        if (urlconnection instanceof HttpURLConnection) {
          urlconnection.setRequestProperty("Cache-Control", "no-cache");
          urlconnection.connect();
            }

        String currentFile = getFileName(urlList[i]);
        InputStream inputstream = getJarInputStream(currentFile, urlconnection);
        FileOutputStream fos = new FileOutputStream(path + currentFile);
View Full Code Here

        // fallback to something else
     
      try{
        URL  url = new URL( "http://www.google.com/" );
       
        URLConnection connection = url.openConnection();
       
        connection.setConnectTimeout( 10000 );
       
        connection.connect();
       
        return( null );
       
      }catch( Throwable f ){
     
View Full Code Here

              }
            }else{
             
              URL source_url = new URL( url_str );
           
              URLConnection connection = source_url.openConnection();
             
              is = source_url.openConnection().getInputStream();
             
              String s = connection.getHeaderField( "content-length" );
             
              if ( s != null ){
               
                length = Long.parseLong( s );
               
View Full Code Here

            xqdoc = _sharedCache.get(docurl);
        } else {
            final InputStream is;
            boolean parseAsHtml = false;
            try {
                final URLConnection conn = docurl.openConnection();
                // TODO REVIEWME workaround code               
                final String contentType = conn.getContentType();
                if(unescaped.endsWith(".html")
                        || (contentType != null && contentType.contains("html"))) {
                    parseAsHtml = true;
                    try {
                        conn.setRequestProperty("User-agent", "Mozilla/5.0");
                    } catch (IllegalStateException ace) {// already connected                       
                        ;
                    }
                }
                is = conn.getInputStream();
            } catch (IOException e) {
                throw new DynamicError("Openning a document failed: " + unescaped, e);
            }
            final boolean resolveEntity = unescaped.startsWith("http");
            final DocumentTableModel dtm = new DocumentTableModel(parseAsHtml, resolveEntity);
View Full Code Here

     */
    public org.omg.CORBA.Object readIOR(URL iorURL) throws IOException {
        org.omg.CORBA.Object object = null;

        if (iorURL != null) {
            URLConnection urlConnection = iorURL.openConnection();
            InputStream is = urlConnection.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader reader = new BufferedReader(isr);
            String ior = reader.readLine();

            if (Debug.debugging("corba")) {
View Full Code Here

            {
                lastModified = file.lastModified();
            }
            else
            {
                URLConnection uriConnection = resource.openConnection();
                lastModified = uriConnection.getLastModified();

                // - we need to set the urlConnection to null and explicity
                //   call garbage collection, otherwise the JVM won't let go
                //   of the URL resource
                uriConnection = null;
View Full Code Here

    }

    public void shutdown() {
        if (url != null) {
            try {
                URLConnection connect = url.openConnection();
                if (connect instanceof HttpURLConnection) {
                    ((HttpURLConnection)connect).disconnect();
                }
            } catch (IOException ex) {
                //ignore
View Full Code Here

                        }
                    }

                } else {

                    URLConnection uc = repositoryURL.openConnection();
                    if (uc instanceof JarURLConnection){
                        JarFile  jarFile = ((JarURLConnection)uc).getJarFile();

                        // get all jar entries that belongs to the help repository
                        Set jarEntries = getJarDirectoryEntries(jarFile, ((JarURLConnection) uc).getEntryName());
View Full Code Here

                e.printStackTrace();
            }
           
        } else if (responseObj instanceof URLConnection) {
            try {
                URLConnection connection = (URLConnection)responseObj;
                connection.getOutputStream().close();
                connection.getInputStream().close();
            } catch (IOException ioe) {
                LOG.log(Level.WARNING, "DECOUPLED_RESPONSE_FAILED_MSG", ioe);
            }
        }
       
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.