Meaning of get methods for java.net. url

Source: Internet
Author: User

In java.net. URL, the source code comment is as follows:

* @ Author James Gosling
* @ Version 1.130, 08/25/04
* @ Since jdk1.0

Haha, the old man Bai Hu wrote some get methods. The meaning is not very straightforward. The hermit writes a small program to dump all kinds of values. The input result is as follows:

Getauthority () = so.mdbchina.com
Getclass () = Class java.net. url
Getcontent () = sun.net. www. Protocol. http. httpurlconnection $ httpinputstream @ 61de33
Getdefaultport () = 80
GetFile () =/Video/% E7 % be % 8e % E5 % a5 % B3
Gethost () = so.mdbchina.com
Getpath () =/Video/% E7 % be % 8e % E5 % a5 % B3
Getport () =-1
Getprotocol () = http
Getquery () = NULL
Getref () = NULL
Getuserinfo () = NULL

The source code is as follows:

Import java. Lang. Reflect. invocationtargetexception;
Import java. Lang. Reflect. method;
Import java. util. arrays;
Import java. util. comparator;

Public class test
...{
Public static final string method_prefix_is = "is ";

Public static final string method_prefix_get = "get ";

Public static final comparator <method> method_name_comparator = new comparator <method> ()...{
Public int compare (method O1, method O2 )...{
Return o1.getname (). comparetoignorecase (o2.getname ());
}
};

Public static void dumpobject (Object O )...{
Method [] Methods = O. getclass (). getmethods ();
Arrays. Sort (methods, method_name_comparator );
For (INT I = 0; I <methods. length; ++ I )...{
Method method = methods [I];
String methodname = method. getname ();
If (method. getparametertypes (). Length = 0
& (Methodname. indexof (method_prefix_is) = 0 | methodname
. Indexof (method_prefix_get) = 0 ))...{
Try ...{
System. Out. println (methodname
+ "() =" + Method. Invoke (o ));
} Catch (illegalargumentexception e )...{
E. printstacktrace ();
} Catch (illegalaccessexception e )...{
E. printstacktrace ();
} Catch (invocationtargetexception e )...{
E. printstacktrace ();
}
}
}
}

Public static void main (string [] argv) throws exception
...{
Java.net. url u = new java.net. URL ("http://so.mdbchina.com/video/%E7%BE%8E%E5%A5%B3 ");
Dumpobject (U );
}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.