如何只解析域名

Soo*_*Nam -1 java

我想在JAVA中只解析域名.例如,

http://facebook.com/bartsf
http://www.facebook.com/pages/Shine-Communications/169790283042195
http://graph.facebook.com/100002306245454/picture?width=150&height=150
http://maps.google.com/maps?hl=en&q=37.78353+-122.39579
http://www.google.com/url?sa=X&q=http://www.onlinehaendler-news.de/interviews/1303-abba24-im-spagat-zwischen-haendler-und-kaeuferinteressen.html&ct=ga&cad=CAEQARgAIAAoATABOAFAnqSQjwVIAVAAWABiAmRl&cd=xa_cHWHNG70&usg=AFQjCNFMgnkzqN0fNKMFKz1NTKK1n9Gg9A
Run Code Online (Sandbox Code Playgroud)

这是我的代码我正在编写map reduce代码.

 String[] whiteList={"www.facebook.com","www.google.com"};
 UrlValidator urlValidator=new UrlValidator(schemes);
 Readfile line by line

for line in file
{
            String sCurrentLine=line;
            if(sCurrentLine.length()>=3)
            {
                String tempString=sCurrentLine.substring(0,3);

                if(!tempString.equals("192") && !tempString.equals("172") && !tempString.equals("10."))
                {

                    sCurrentLine="http://"+sCurrentLine;
                    if(urlValidator.isValid(sCurrentLine))//domain filter should be here
                    {
                           System.out.println(sCurrentLine);
                    }
                }
                tempString="";
            }
 }
Run Code Online (Sandbox Code Playgroud)

我想过滤域名是facebook.com还是google.com,以上所有网址都被过滤掉了.

Mat*_*all 8

用于java.net.URI将字符串解析为URI.这里没有必要重新发明轮子.

URI foo = new URI("http://facebook.com/bartsf");
String host = foo.getHost(); // "facebook.com"
Run Code Online (Sandbox Code Playgroud)