Java 8 URL - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 URL class.

This code example shows how to use the following methods:
        } 
    } 
 
    public HttpClient(String url) {
        try { 
            baseUrl = new URL(url);
        } catch (MalformedURLException e) {
            throw new ElasticSearchException("", e);
        } 
    } 
 
    public HttpClient(URL url) {
        baseUrl = url;
    } 
 
    public HttpClientResponse request(String path) {
        return request("GET", path);
    } 
 
    public HttpClientResponse request(String method, String path) {
9
CodeRank
This code example shows how to use the following methods:getHost
     
    private static final Logger log = Logger.getLogger(RolloutPlanTestServlet.class); 
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException { 
         
        URL requestURL = new URL(request.getRequestURL().toString());
        host = requestURL.getHost();
         
        String op = request.getParameter(OP_PARAM);
        if (OP_BIND.equals(op)) {
            bindPort = Integer.valueOf(request.getParameter(BIND_PORT_PARAM));
            bind(); 
        } else if (OP_UNBIND.equals(op))
            unbind(); 
         
        response.setContentType("text/plain");
        PrintWriter out = response.getWriter();
        out.print(String.valueOf(initDate.getTime()));
        out.close();
    } 
9
CodeRank
This code example shows how to use the following methods:getFile
        JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "sar-example.sar");
        archive.addPackage(ConfigService.class.getPackage());
        archive.addClasses(AbstractContainerTestCase.class);
        String path = "META-INF/jboss-service.xml";
        URL resourceURL = RemoteInContainerTestCase.class.getResource("/sar-example.sar/" + path);
        archive.addAsResource(new File(resourceURL.getFile()), path);
        return archive;
    } 
 
    @Override 
    MBeanServerConnection getMBeanServer() throws Exception { 
        return ManagementFactory.getPlatformMBeanServer(); 
    } 
} 
9
CodeRank
This code example shows how to use the following methods:getPath
        return war;
    } 
 
    @Test 
    public void testContextRoot() { 
        Assert.assertEquals("Wrong context root!", TEST_PATH, baseUrl.getPath());
    } 
 
} 
9
CodeRank
This code example shows how to use the following methods:
    private static final String SERVICE_NAME = "TransactionalServiceImplService"; 
 
    public static TransactionalService newInstance(final String deploymentUrl) throws MalformedURLException { 
        LOG.debug("TransactionalClient.newInstance(deploymentUrl = " + deploymentUrl + ")"); 
 
        final URL wsdlLocation = new URL(deploymentUrl + "/" + NAME + "?wsdl"); 
 
        LOG.debug("wsdlLocation for service: " + wsdlLocation); 
 
        final QName serviceName = new QName(TARGET_NAMESPACE, SERVICE_NAME); 
        final QName portName = new QName(TARGET_NAMESPACE, PORT_NAME); 
 
        final Service service = Service.create(wsdlLocation, serviceName); 
        final TransactionalService transactionalService = service.getPort(portName, TransactionalService.class); 
 
        return transactionalService; 
    } 
 
} 
8
CodeRank
This code example shows how to use the following methods:getProtocol
        // intentionally empty 
    } 
 
    @Override 
    public boolean isFactoryFor(URL url) {
        return "jar".equals(url.getProtocol());
    } 
 
    @Override 
    public Iterator<Resource> createIterator(URL url, String path, String suffix) {
        try { 
            String jarPath = filePath(url);
            return new ZipResourceIterator(jarPath, path, suffix);
        } catch (IOException e) {
            throw new CucumberException(e);
        } 
    } 
} 
8
CodeRank
This code example shows how to use the following methods:openConnection
    return downloadViaHttp(uri, contentTypes, maxChars);
  } 
 
  private static CharSequence downloadViaHttp(String uri, String contentTypes, int maxChars) throws IOException {
    Log.i(TAG, "Downloading " + uri);
    URL url = new URL(uri);
    URLConnection conn = url.openConnection();
    if (!(conn instanceof HttpURLConnection)) {
      throw new IOException();
    } 
    HttpURLConnection connection = (HttpURLConnection) conn;
    connection.setRequestProperty("Accept", contentTypes);
    connection.setRequestProperty("Accept-Charset", "utf-8,*");
    connection.setRequestProperty("User-Agent", "ZXing (Android)");
    try { 
      try { 
        connection.connect();
      } catch (NullPointerException npe) {
        // this is an Android bug: http://code.google.com/p/android/issues/detail?id=16895 
        Log.w(TAG, "Bad URI? " + uri);
10
CodeRank
This code example shows how to use the following methods:getHost, getPort, getProtocol
        return !failed;
 
    } 
 
    public static String getBaseURL(URL url) throws MalformedURLException {
        return new URL(url.getProtocol(), url.getHost(), url.getPort(), "/").toString();
    } 
} 
8
CodeRank
This code example shows how to use the following methods:getFile
 
  private File downloadFile(String name) {
    URL url = getUrl(name);
 
    File dir = TemporaryFilesystem.getDefaultTmpFS().createTempDir("attachFile", "dir");
    File outputTo = new File(dir, url.getFile());
    if (!outputTo.getParentFile().mkdirs()) {
      throw new SeleniumException("Cannot create file for upload: " + outputTo);
    } 
 
    FileOutputStream fos = null;
    try { 
      fos = new FileOutputStream(outputTo);
      Resources.copy(url, fos);
    } catch (IOException e) {
 
    } 
 
    return outputTo;
  } 

8
CodeRank
This code example shows how to use the following methods:getFile, getHost, getPort, getProtocol
    } 
  } 
 
  static URL qualifyHost(URL url) {
    try { 
      InetAddress a = InetAddress.getByName(url.getHost());
      String qualHost = a.getCanonicalHostName();
      URL q = new URL(url.getProtocol(), qualHost, url.getPort(), url.getFile());
      return q;
    } catch (IOException io) {
      return url;
    } 
  } 
 
  static final String regexpSpecials = "[]()?*+|.!^-\\~@";
 
  public static String regexpEscape(String plain) {
    StringBuffer buf = new StringBuffer();
    char[] ch = plain.toCharArray();
    int csup = ch.length;
8
CodeRank

Related Java 8 URL Questions & Answers:

Other Java 8 URL Examples

20:		        try {
21:		            URL url = new URL(f_url[0]);
22:		            URLConnection conection = url.openConnection();
23:		            conection.connect();
24:		            // getting file length
-
20:		        try {
21:		            URL url = new URL(f_url[0]);
22:		            URLConnection conection = url.openConnection();
23:		            conection.connect();
24:		            // getting file length

Read More

50:				Bitmap mIcon11 = null;
51:				try {
52:					InputStream in = new java.net.URL(urldisplay).openStream();
53:					mIcon11 = BitmapFactory.decodeStream(in);
54:				} catch (Exception e) {

Read More

97:		        try {
98:		            URL url = new URL(f_url[0]);
99:		            URLConnection conection = url.openConnection();
100:		            conection.connect();
101:		            // this will be useful so that you can show a tipical 0-100% progress bar
-
97:		        try {
98:		            URL url = new URL(f_url[0]);
99:		            URLConnection conection = url.openConnection();
100:		            conection.connect();
101:		            // this will be useful so that you can show a tipical 0-100% progress bar

Read More

See Code Examples for Java 8 URL Methods: