Package java.net

Examples of java.net.URLConnection.connect()


        try {
            InputStream in = null;
            try {
                final URLConnection conn = new URL("http://localhost:8181/").openConnection();
                conn.setDoInput(true);
                conn.connect();
                in = new BufferedInputStream(conn.getInputStream());
                int i = in.read();
                StringBuilder sb = new StringBuilder();
                while (i != -1) {
                    sb.append((char)i);
View Full Code Here


      if (img.attr("data-inline").equals("true")) {
        String src = img.attr(IMG_SRC_ATTR);
        try {
          URL url = new URL(src);
          URLConnection urlConnection = url.openConnection();
          urlConnection.connect();
          String contentType = urlConnection.getContentType();

          urlConnection.getContent();
          byte[] srcContent = IOUtils.toByteArray(url.openStream());
          String base64 = new Base64().encodeToString(srcContent);
View Full Code Here

            if (auth != null)
            {
                c.setRequestProperty("Authorization", "Basic " + auth);
            }

            c.connect();
            in = c.getInputStream();
            if (!file.getParentFile().exists() && !file.getParentFile().mkdirs())
            {
                throw new IOException("Failed to create obr cache dir "
                    + file.getParentFile());
View Full Code Here

        if (_url.getHost()==null || _url.getHost().length()==0) {
            throw new IOException("Invalid URL: "+url);
        }
        URLConnection head = _url.openConnection();
        try {
            head.connect();
        } catch (IOException e) {
            throw (IOException)new IOException("Failed to connect to "+url).initCause(e);
        }
        String p = head.getHeaderField("X-Jenkins-CLI-Port");
        if (p==null)    p = head.getHeaderField("X-Hudson-CLI-Port");   // backward compatibility
View Full Code Here

        assertEquals("jsfresource:org.richfaces.resource.MockResource", url.toExternalForm());

        URLConnection urlConnection = url.openConnection();

        assertNotNull(urlConnection);
        urlConnection.connect();
        assertEquals(130, urlConnection.getContentLength());
        assertEquals("image/gif", urlConnection.getContentType());
        assertEquals(lastModified.getTime(), urlConnection.getLastModified());
        assertSame(stream, urlConnection.getInputStream());
        assertSame(url, urlConnection.getURL());
View Full Code Here

        assertSame(url, urlConnection.getURL());

        MockResourceImpl mockResource2 = new MockResourceImpl();
        URLConnection urlConnection2 = mockResource2.getURL().openConnection();

        urlConnection2.connect();
        assertEquals(-1, urlConnection2.getContentLength());
        assertNull(urlConnection2.getContentType());
        assertEquals(0, urlConnection2.getLastModified());
    }
View Full Code Here

                setStatus("Downloading " + asset.name + "...");
                con = asset.url.openConnection();
                if (con instanceof HttpURLConnection) {
                    con.setRequestProperty("Cache-Control", "no-cache, no-transform");
                    ((HttpURLConnection) con).setRequestMethod("GET");
                    con.connect();
                }
                asset.local.getParentFile().mkdirs();
                int readLen;
                int currentSize = 0;
                InputStream input = con.getInputStream();
View Full Code Here

                attempt++;
                Logger.logDebug("Connecting.. Try " + attempt + " of " + attempts + " for: " + jarURLs.toURI());
                URLConnection dlConnection = jarURLs.openConnection();
                if (dlConnection instanceof HttpURLConnection) {
                    dlConnection.setRequestProperty("Cache-Control", "no-cache, no-transform");
                    dlConnection.connect();
                }
                String jarFileName = getFilename(jarURLs);
                if (new File(binDir, jarFileName).exists()) {
                    new File(binDir, jarFileName).delete();
                }
View Full Code Here

                //HTTPURLConnection con = (HttpURLConnection) asset.url.openConnection();
                URLConnection con = asset.url.openConnection();
                if (con instanceof HttpURLConnection) {
                    con.setRequestProperty("Cache-Control", "no-cache, no-transform");
                    ((HttpURLConnection) con).setRequestMethod("HEAD");
                    con.connect();
                }

                // gather data for basic checks
                long remoteSize = Long.parseLong(con.getHeaderField("Content-Length"));
                if (asset.hash == null && asset.getPrimaryDLType() == DLType.ETag) {
View Full Code Here

      String configFile = System.getProperty(
    CONFIG_FILE_PROPERTY, CONFIG_FILE_DEFAULT);
      URL url = new URL(configFileContext, configFile);
      URLConnection connection = url.openConnection();
      connection.setUseCaches(false);
      connection.connect();
      long lastModified = connection.getLastModified();
      if (lastModified > lastRead) {
    lastRead = lastModified;
    InputStream in = null;
    try {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.