Changeset 30738 in osm for applications/editors/josm/plugins/trustosm/src/org
- Timestamp:
- 2014-10-19T01:27:04+02:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/data/TrustSignatures.java
r30724 r30738 13 13 import org.bouncycastle.bcpg.BCPGOutputStream; 14 14 import org.bouncycastle.openpgp.PGPSignature; 15 import org.openstreetmap.josm.Main; 15 16 16 17 public class TrustSignatures { … … 126 127 if (textsigs.containsKey(plain)){ 127 128 List<PGPSignature> l = textsigs.get(plain); 128 try { 129 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 130 ArmoredOutputStream aOut = new ArmoredOutputStream(baos); 129 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 130 try (ArmoredOutputStream aOut = new ArmoredOutputStream(baos)) { 131 131 aOut.beginClearText(l.get(0).getHashAlgorithm()); 132 132 aOut.write(plain.getBytes(Charset.forName("UTF-8"))); … … 134 134 aOut.endClearText(); 135 135 136 BCPGOutputStream bOut = new BCPGOutputStream(aOut); 137 for (PGPSignature sig : l) { 138 sig.encode(bOut); 136 try (BCPGOutputStream bOut = new BCPGOutputStream(aOut)) { 137 for (PGPSignature sig : l) { 138 sig.encode(bOut); 139 } 139 140 } 140 141 bOut.close();142 aOut.close();143 141 144 142 return baos.toString("UTF-8"); 145 143 146 144 } catch (Exception e) { 147 e.printStackTrace();145 Main.error(e); 148 146 return "Error - read console Output"; 149 147 } … … 153 151 154 152 public String getArmoredFulltextSignature(PGPSignature sig) { 155 try { 156 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 157 ArmoredOutputStream aOut = new ArmoredOutputStream(baos); 153 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 154 try (ArmoredOutputStream aOut = new ArmoredOutputStream(baos)) { 158 155 aOut.beginClearText(sig.getHashAlgorithm()); 159 156 aOut.write(getSigtext(sig).getBytes(Charset.forName("UTF-8"))); … … 161 158 aOut.endClearText(); 162 159 163 BCPGOutputStream bOut = new BCPGOutputStream(aOut); 164 sig.encode(bOut); 165 bOut.close(); 166 aOut.close(); 167 160 try (BCPGOutputStream bOut = new BCPGOutputStream(aOut)) { 161 sig.encode(bOut); 162 } 168 163 169 164 return baos.toString("UTF-8"); 170 165 } catch (Exception e) { 171 e.printStackTrace();166 Main.error(e); 172 167 return "Error - read console Output"; 173 168 } 174 169 } 175 176 170 } -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/util/NameGenerator.java
r30724 r30738 8 8 /** 9 9 * This class is released under GNU general public license 10 * 10 * 11 11 * Description: This class generates random names from syllables, and provides programmer a 12 12 * simple way to set a group of rules for generator to avoid unpronounceable and bizarre names. 13 * 13 * 14 14 * SYLLABLE FILE REQUIREMENTS/FORMAT: 15 15 * 1) all syllables are separated by line break. … … 17 17 * 3) + and - characters are used to set rules, and using them in other way, may result in unpredictable results. 18 18 * 4) Empty lines are ignored. 19 * 19 * 20 20 * SYLLABLE CLASSIFICATION: 21 21 * Name is usually composed from 3 different class of syllables, which include prefix, middle part and suffix. … … 23 23 * To declare syllable as a suffix in the file, insert "+" as a first character of the line. 24 24 * everything else is read as a middle part. 25 * 25 * 26 26 * NUMBER OF SYLLABLES: 27 27 * Names may have any positive number of syllables. In case of 2 syllables, name will be composed from prefix and suffix. 28 28 * In case of 1 syllable, name will be chosen from amongst the prefixes. 29 29 * In case of 3 and more syllables, name will begin with prefix, is filled with middle parts and ended with suffix. 30 * 30 * 31 31 * ASSIGNING RULES: 32 32 * I included a way to set 4 kind of rules for every syllable. To add rules to the syllables, write them right after the 33 33 * syllable and SEPARATE WITH WHITESPACE. (example: "aad +v -c"). The order of rules is not important. 34 * 34 * 35 35 * RULES: 36 36 * 1) +v means that next syllable must definitely start with a vocal. … … 41 41 * Beware of creating logical mistakes, like providing only syllables ending with consonants, but expecting only vocals, which will be detected 42 42 * and RuntimeException will be thrown. 43 * 43 * 44 44 * TO START: 45 45 * Create a new NameGenerator object, provide the syllable file, and create names using compose() method. 46 * 46 * 47 47 * @author Joonas Vali, August 2009. 48 48 * … … 85 85 */ 86 86 public void refresh() throws IOException{ 87 88 FileReader input = null; 89 BufferedReader bufRead; 90 String line; 91 92 input = new FileReader(fileName); 93 94 bufRead = new BufferedReader(input); 95 line=""; 96 97 while(line != null){ 98 line = bufRead.readLine(); 99 if(line != null && !line.equals("")){ 100 if(line.charAt(0) == '-'){ 101 pre.add(line.substring(1).toLowerCase()); 102 } 103 else if(line.charAt(0) == '+'){ 104 sur.add(line.substring(1).toLowerCase()); 105 } 106 else{ 107 mid.add(line.toLowerCase()); 108 } 109 } 110 } 111 bufRead.close(); 112 } 113 114 private String upper(String s){ 87 try ( 88 FileReader input = new FileReader(fileName); 89 BufferedReader bufRead = new BufferedReader(input); 90 ) { 91 String line=""; 92 while (line != null){ 93 line = bufRead.readLine(); 94 if (line != null && !line.equals("")) { 95 if(line.charAt(0) == '-') { 96 pre.add(line.substring(1).toLowerCase()); 97 } else if (line.charAt(0) == '+') { 98 sur.add(line.substring(1).toLowerCase()); 99 } else { 100 mid.add(line.toLowerCase()); 101 } 102 } 103 } 104 } 105 } 106 107 private String upper(String s) { 115 108 return s.substring(0,1).toUpperCase().concat(s.substring(1)); 116 109 } 117 110 118 private boolean containsConsFirst(ArrayList<String> array) {111 private boolean containsConsFirst(ArrayList<String> array) { 119 112 for(String s: array){ 120 113 if(consonantFirst(s)) return true;
Note:
See TracChangeset
for help on using the changeset viewer.