-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDownloadDefinitions.java
More file actions
80 lines (75 loc) · 3.46 KB
/
DownloadDefinitions.java
File metadata and controls
80 lines (75 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import java.net.URL;
import java.util.Scanner;
import java.io.IOException;
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
public class DownloadDefinitions {
private static void download(String urlname, String filename) {
try {
URL url = new URL(urlname);
try(BufferedInputStream bis = new BufferedInputStream(url.openStream())) {
try(FileOutputStream fos = new FileOutputStream(filename)) {
byte[] buffer = new byte[1024];
int count=0;
while((count = bis.read(buffer,0,buffer.length)) != -1) {
fos.write(buffer, 0, count);
}
}
}
} catch (IOException ex) {
System.err.println("Unable to download\n from: "+urlname+ "\n to: "+filename+"\n "+ex);
}
}
private static void downloadIANALanguageSubtagRegistery(String filename) {
try {
URL url = new URL("https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry");
Scanner from = new Scanner(url.openStream());
try(FileOutputStream fos = new FileOutputStream(filename)) {
boolean isLang = false;
String tag = null;
while(from.hasNextLine()) {
String line = from.nextLine();
if (line.startsWith("Type: ")) isLang = line.equals("Type: language");
else if (line.startsWith("Subtag: ")) tag = line.substring(8);
else if (isLang && line.startsWith("Description: ")) {
String key = line.substring(13);
// key = key.replaceAll(" \\(.*", ""); // change "Modern Greek (1453-)" to "Modern Greek" but also conflates arr "Karo (Brazil)" and kxh "Karo (Ethiopia)" so disabled for now
key = key.replaceAll(" language.*", ""); // change "Bihari languages" to "Bihari"
fos.write((key+"\t"+tag+"\n").getBytes("UTF-8"));
}
}
}
} catch (IOException ex) {
System.err.println("Unable to download\n from: https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry\n to: "+filename+"\n "+ex);
}
}
public static void main(String[] args) {
download(
"https://github.com/FamilySearch/GEDCOM/raw/main/extracted-files/enumerations.tsv",
"ged5to7/config/enumerations.tsv"
);
download(
"https://github.com/FamilySearch/GEDCOM/raw/main/extracted-files/enumerationsets.tsv",
"ged5to7/config/enumerationsets.tsv"
);
download(
"https://github.com/FamilySearch/GEDCOM/raw/main/extracted-files/payloads.tsv",
"ged5to7/config/payloads.tsv"
);
download(
"https://github.com/FamilySearch/GEDCOM/raw/main/extracted-files/substructures.tsv",
"ged5to7/config/substructures.tsv"
);
download(
"https://github.com/FamilySearch/GEDCOM/raw/main/extracted-files/cardinalities.tsv",
"ged5to7/config/cardinalities.tsv"
);
download(
"https://github.com/fhiso/legacy-format/raw/master/languages.tsv",
"ged5to7/config/languages.tsv"
);
downloadIANALanguageSubtagRegistery(
"ged5to7/config/all-languages.tsv"
);
}
}