/**
* Given a string of words separated by spaces, returns the first word.
* @param string
* @return
*/
public static String first(String string) {
if (isNullOrEmptyString(string)) { return ""; }
string = string.trim();
int index = string.indexOf(" "); //TODO: shouldn't this be "\\s+" to handle double spaces and tabs? That means regexp version of indexOf
if (index<0) { return string; }
return string.substring(0, index);
}
/**
* Given a string of words separated by spaces, returns the rest of the string after the first word.
* @param string
* @return
*/
public static String rest(String string) {
if (isNullOrEmptyString(string)) { return ""; }
string = string.trim();
int index = string.indexOf(" "); //TODO: shouldn't this be "\\s+" to handle double spaces and tabs? That means regexp version of indexOf
if (index<0) { return ""; }
return string.substring(index+1);
}
public static String grep(String regexp, String multiLineStringToSearch) {
String result = "";
//System.out.println("grep for '"+ regexp + "'");
String[] lines = multiLineStringToSearch.split("\\n");
//System.out.println("grep input string contains "+ lines.length + " lines.");
Pattern pattern = Pattern.compile(regexp);
for (String line : lines) {
Matcher matcher = pattern.matcher(line);
if (matcher.find()) {
//System.out.println("grep found match="+ line);
result = result + "\n" + line;
}
}
return result.trim();
}
/**
* Given the path and name of a plain text (ascii) file,
* reads it and returns the contents as a string.
* @param filePath
* @return
*/
public static String readTextFile(String filePath) {
BufferedReader reader;
String result = "";
int counter = 0;
try {
reader = new BufferedReader(new FileReader(filePath));
String line = "";
StringBuilder stringBuilder = new StringBuilder();
String lineSeparator = System.getProperty("line.separator");
while ((line = reader.readLine()) != null) {
counter = counter + 1;
stringBuilder.append(line);
stringBuilder.append(lineSeparator);
}
reader.close();
result = stringBuilder.toString();
logger.info("readTextFile: Read "+filePath+" with "+ counter + " lines, "+result.length()+" characters.");
return result;
} catch (FileNotFoundException e) {
logger.fatal("readTextFile: Could not find file "+filePath+".");
e.printStackTrace();
} catch (IOException e) {
logger.fatal("readTextFile: Could not read file "+filePath+".");
e.printStackTrace();
}
return "";
}
public static boolean isNullOrEmptyString(String s) {
return (s==null || s.equals(""));
}
/**
* Given a string of words separated by one or more whitespaces, returns the Nth word.
* @param string
* @return
*/
public static String nth(String string, int n) {
string = string.trim();
String[] splitstring = string.split("\\s+");
String result = "";
if (splitstring.length<n) { return ""; }
else {
result = splitstring[n - 1];
}
return result.trim();
}
/**
* Given a string of words separated by spaces, returns the last word.
* @param string
* @return
*/
public static String last(String string) {
return string.substring(string.trim().lastIndexOf(" ")+1, string.trim().length());
}
# 1 楼答案
Here有官方的中央存储库镜像列表(作为xml文件)和here的另一个中央存储库镜像列表
# 2 楼答案
实际上,http://docs.codehaus.org/display/MAVENUSER/Mirrors+Repositories处的列表是有问题的。在旧金山,加利福尼亚还是密苏里的圣路易斯?(我想这是一个不经意的教训,说明了为什么不应该对代码甚至xml进行注释)。为了让事情更加混乱,域的所有者(根据http://whois.net/whois/maven.org)在马里兰州的富尔顿
也许问题不是“存储库在哪里?”(以赛亚回答)但事实上: “如何找到离我家最近的maven存储库?”
这个问题也困扰着我
另一方面,考虑到数据包在世界各地的传播速度,这真的很重要吗
但它仍然困扰着我
有两种方法可以找出最接近的主机:
打开浏览器,转到http://freegeoip.net,然后键入主机名。如果你知道自己在哪里,那么你可以去谷歌地图,了解方向,并查看距离
打开终端窗口,ping主机名以查找平均往返传输时间(毫秒)。这将为您提供电子距离,这对于文件传输时间来说更为重要
对每个主机名重复此操作(例如,如果您正在查看Maven本身的下载站点,则大约重复40次)
根据谷歌地图上的距离、方向或通过时间进行排序
对于40台主机,您可能可以在20分钟内手动完成这项工作,但真正的专业人士更愿意花几个小时编写Selenium和java代码,以便在5分钟内完成这项工作
在我丰富的业余时间里,我只做了一半的工作(即没有硒):
其中,MavenUrls中的数据。txt是:
我的Utils类包括以下内容:
享受吧