forked from I2P_Developers/i2p.i2p
format (shendaras)
This commit is contained in:
@@ -28,66 +28,67 @@ public class FetchSeeds {
|
||||
* @return whether new seed nodes could be fetched
|
||||
*/
|
||||
public static boolean fetchSeeds(File destination, String sourceURL) {
|
||||
InputStream in = null;
|
||||
try {
|
||||
URL source = new URL(sourceURL);
|
||||
URLConnection con = source.openConnection();
|
||||
in = con.getInputStream();
|
||||
BufferedReader br = new BufferedReader
|
||||
(new InputStreamReader(in));
|
||||
String line;
|
||||
while ((line = br.readLine())!= null) {
|
||||
int pos = line.indexOf(" <a href=\"routerInfo-");
|
||||
if (pos == -1) continue;
|
||||
line=line.substring(pos+10);
|
||||
pos=line.indexOf("\"");
|
||||
if (pos == -1) continue;
|
||||
line=line.substring(0,pos);
|
||||
fetchFile(new File(destination, line), sourceURL+line);
|
||||
System.out.println(line);
|
||||
}
|
||||
br.close();
|
||||
return true;
|
||||
} catch (IOException ex) {
|
||||
System.err.println("Unable to fetch seeds from " + sourceURL + ": " + ex.getMessage());
|
||||
//ex.printStackTrace();
|
||||
return false;
|
||||
} finally {
|
||||
if (in != null) try { in.close(); } catch (IOException ioe) {}
|
||||
}
|
||||
InputStream in = null;
|
||||
try {
|
||||
URL source = new URL(sourceURL);
|
||||
URLConnection con = source.openConnection();
|
||||
in = con.getInputStream();
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
int pos = line.indexOf(" <a href=\"routerInfo-");
|
||||
if (pos == -1) continue;
|
||||
line = line.substring(pos + 10);
|
||||
pos = line.indexOf("\"");
|
||||
if (pos == -1) continue;
|
||||
line = line.substring(0, pos);
|
||||
fetchFile(new File(destination, line), sourceURL + line);
|
||||
System.out.println(line);
|
||||
}
|
||||
br.close();
|
||||
return true;
|
||||
} catch (IOException ex) {
|
||||
System.err.println("Unable to fetch seeds from " + sourceURL + ": " + ex.getMessage());
|
||||
//ex.printStackTrace();
|
||||
return false;
|
||||
} finally {
|
||||
if (in != null) try {
|
||||
in.close();
|
||||
} catch (IOException ioe) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void fetchFile(File destFile, String fileURL)
|
||||
throws IOException {
|
||||
URL url = new URL(fileURL);
|
||||
InputStream in = url.openStream();
|
||||
OutputStream out = new FileOutputStream(destFile);
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len=in.read(buf)) != -1) {
|
||||
out.write(buf,0,len);
|
||||
}
|
||||
in.close();
|
||||
out.flush();
|
||||
out.close();
|
||||
public static void fetchFile(File destFile, String fileURL) throws IOException {
|
||||
URL url = new URL(fileURL);
|
||||
InputStream in = url.openStream();
|
||||
OutputStream out = new FileOutputStream(destFile);
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) != -1) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
in.close();
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* test main method.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
switch (args.length) {
|
||||
case 1:
|
||||
fetchSeeds(new File(args[0]), "http://i2p.dnsalias.net/i2pdb/");
|
||||
return;
|
||||
case 2:
|
||||
fetchSeeds(new File(args[0]), args[1]);
|
||||
return;
|
||||
default:
|
||||
System.out.println("Usage: FetchSeeds <outDir>");
|
||||
System.out.println(" or FetchSeeds <outDir> <seedURL>");
|
||||
System.out.println("The default seedURL is http://i2p.dnsalias.net/i2pdb/");
|
||||
return;
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
switch (args.length) {
|
||||
case 1:
|
||||
fetchSeeds(new File(args[0]), "http://i2p.dnsalias.net/i2pdb/");
|
||||
return;
|
||||
case 2:
|
||||
fetchSeeds(new File(args[0]), args[1]);
|
||||
return;
|
||||
default:
|
||||
System.out.println("Usage: FetchSeeds <outDir>");
|
||||
System.out.println(" or FetchSeeds <outDir> <seedURL>");
|
||||
System.out.println("The default seedURL is http://i2p.dnsalias.net/i2pdb/");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user