Ignore:
Timestamp:
2014-10-19T01:27:04+02:00 (10 years ago)
Author:
donvip
Message:

[josm_plugins] fix java 7 warnings / global usage of try-with-resource

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  
    1313import org.bouncycastle.bcpg.BCPGOutputStream;
    1414import org.bouncycastle.openpgp.PGPSignature;
     15import org.openstreetmap.josm.Main;
    1516
    1617public class TrustSignatures {
     
    126127        if (textsigs.containsKey(plain)){
    127128            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)) {
    131131                aOut.beginClearText(l.get(0).getHashAlgorithm());
    132132                aOut.write(plain.getBytes(Charset.forName("UTF-8")));
     
    134134                aOut.endClearText();
    135135
    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                            }
    139140                }
    140 
    141                 bOut.close();
    142                 aOut.close();
    143141
    144142                return baos.toString("UTF-8");
    145143
    146144            } catch (Exception e) {
    147                 e.printStackTrace();
     145                Main.error(e);
    148146                return "Error - read console Output";
    149147            }
     
    153151
    154152    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)) {
    158155            aOut.beginClearText(sig.getHashAlgorithm());
    159156            aOut.write(getSigtext(sig).getBytes(Charset.forName("UTF-8")));
     
    161158            aOut.endClearText();
    162159
    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            }
    168163
    169164            return baos.toString("UTF-8");
    170165        } catch (Exception e) {
    171             e.printStackTrace();
     166            Main.error(e);
    172167            return "Error - read console Output";
    173168        }
    174169    }
    175 
    176170}
  • applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/util/NameGenerator.java

    r30724 r30738  
    88/**
    99 * This class is released under GNU general public license
    10  * 
     10 *
    1111 * Description: This class generates random names from syllables, and provides programmer a
    1212 * simple way to set a group of rules for generator to avoid unpronounceable and bizarre names.
    13  * 
     13 *
    1414 * SYLLABLE FILE REQUIREMENTS/FORMAT:
    1515 * 1) all syllables are separated by line break.
     
    1717 * 3) + and - characters are used to set rules, and using them in other way, may result in unpredictable results.
    1818 * 4) Empty lines are ignored.
    19  * 
     19 *
    2020 * SYLLABLE CLASSIFICATION:
    2121 * Name is usually composed from 3 different class of syllables, which include prefix, middle part and suffix.
     
    2323 * To declare syllable as a suffix in the file, insert "+" as a first character of the line.
    2424 * everything else is read as a middle part.
    25  * 
     25 *
    2626 * NUMBER OF SYLLABLES:
    2727 * Names may have any positive number of syllables. In case of 2 syllables, name will be composed from prefix and suffix.
    2828 * In case of 1 syllable, name will be chosen from amongst the prefixes.
    2929 * In case of 3 and more syllables, name will begin with prefix, is filled with middle parts and ended with suffix.
    30  * 
     30 *
    3131 * ASSIGNING RULES:
    3232 * I included a way to set 4 kind of rules for every syllable. To add rules to the syllables, write them right after the
    3333 * syllable and SEPARATE WITH WHITESPACE. (example: "aad +v -c"). The order of rules is not important.
    34  * 
     34 *
    3535 * RULES:
    3636 * 1) +v means that next syllable must definitely start with a vocal.
     
    4141 * Beware of creating logical mistakes, like providing only syllables ending with consonants, but expecting only vocals, which will be detected
    4242 * and RuntimeException will be thrown.
    43  * 
     43 *
    4444 * TO START:
    4545 * Create a new NameGenerator object, provide the syllable file, and create names using compose() method.
    46  * 
     46 *
    4747 * @author Joonas Vali, August 2009.
    4848 *
     
    8585     */
    8686    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) {
    115108        return s.substring(0,1).toUpperCase().concat(s.substring(1));
    116109    }
    117110
    118     private boolean containsConsFirst(ArrayList<String> array){
     111    private boolean containsConsFirst(ArrayList<String> array) {
    119112        for(String s: array){
    120113            if(consonantFirst(s)) return true;
Note: See TracChangeset for help on using the changeset viewer.