Ignore:
Timestamp:
2019-01-17T07:55:16+01:00 (6 years ago)
Author:
gerdp
Message:

improve code base on findbugs + sonar results

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/o5m/src/org/openstreetmap/josm/plugins/o5m/io/O5mReader.java

    r34827 r34835  
    88import java.io.IOException;
    99import java.io.InputStream;
     10import java.nio.charset.StandardCharsets;
    1011import java.util.ArrayList;
    1112import java.util.Collection;
     
    3940 */
    4041public class O5mReader extends AbstractReader {
    41     public IllegalDataException exception = null;
     42    private IllegalDataException exception = null;
    4243    private boolean discourageUpload;
    4344   
     
    8081    private BufferedInputStream fis;
    8182    private InputStream is;
    82     private ByteArrayInputStream bis;
    8383
    8484    // buffer for byte -> String conversions
     
    9494    private int bytesToRead;
    9595    // total number of bytes read from stream
    96     long countBytes;
     96    private long countBytes;
    9797
    9898    // for delta calculations
     
    103103    private long lastTs;
    104104    private long lastChangeSet;
    105     private int lastLon, lastLat;
     105    private int lastLon;
     106    private int lastLat;
    106107    private int version;
    107108    private User osmUser;
     
    175176                    }
    176177                    ioPos = 0;
    177                     bis = new ByteArrayInputStream(ioBuf, 0, bytesToRead);
    178                     is = bis;
     178                    is = new ByteArrayInputStream(ioBuf, 0, bytesToRead);
    179179                    break;                   
    180                 default:    
     180                default: break;    
    181181                }
    182182            }
     
    229229            ds.addDataSource(new DataSource(b, header));
    230230        } else {
    231             Logging.error("Invalid Bounds: "+b);
     231            Logging.error("Invalid Bounds: " + b);
    232232        }
    233233    }
     
    235235    /**
    236236     * read a node data set
    237      * @throws IOException in case of I/O error
    238      */
    239     private void readNode() throws IOException {
     237     */
     238    private void readNode() {
    240239        if (exception != null)
    241240            return;
     
    285284    /**
    286285     * read a way data set
    287      * @throws IOException in case of I/O error
    288      */
    289     private void readWay() throws IOException {
     286     */
     287    private void readWay() {
    290288        if (exception != null)
    291289            return;
     
    333331    /**
    334332     * read a relation data set
    335      * @throws IOException in case of I/O error
    336      */
    337     private void readRel() throws IOException {
     333     */
     334    private void readRel() {
    338335        if (exception != null)
    339336            return;
     
    387384    }
    388385
    389     private Map<String, String> readTags() throws IOException {
     386    private Map<String, String> readTags() {
    390387        Map<String, String> keys = new HashMap<>();
    391388        while (bytesToRead > 0) {
     
    424421     * Read version, time stamp and change set and author. 
    425422     * We are not interested in the values, but we have to maintain the string table.
    426      * @throws IOException in case of I/O error
    427      */
    428     private void readVersionTsAuthor() throws IOException {
     423     */
     424    private void readVersionTsAuthor() {
    429425        stringPair[0] = null;
    430426        stringPair[1] = null;
     
    442438    /**
    443439     * Read author .
    444      * @throws IOException in case of I/O error
    445      */
    446     private void readAuthor() throws IOException {
     440     */
     441    private void readAuthor() {
    447442        int stringRef = readUnsignedNum32();
    448443        if (stringRef == 0) {
     
    465460
    466461                if (b == 0)
    467                     stringPair[1] = new String(cnvBuffer, start, buffPos-1, "UTF-8");
     462                    stringPair[1] = new String(cnvBuffer, start, buffPos-1, StandardCharsets.UTF_8);
    468463            }
    469464            long bytes = toReadStart - bytesToRead;
     
    472467        } else
    473468            setStringRefPair(stringRef);
    474         if (stringPair[0] != null && stringPair[0].isEmpty() == false) {
     469        if (stringPair[0] != null && !stringPair[0].isEmpty()) {
    475470            long uid = Long.parseLong(stringPair[0]);
    476471            osmUser = User.createOsmUser(uid, stringPair[1]);
     
    482477     * read object type ("0".."2") concatenated with role (single string)
    483478     * @return 0..3 for type (3 means unknown)
    484      * @throws IOException in case of I/O error
    485      */
    486     private int readRelRef() throws IOException {
     479     */
     480    private int readRelRef() {
    487481        int refType = -1;
    488482        long toReadStart = bytesToRead;
     
    505499
    506500                if (b == 0)
    507                     stringPair[1] = new String(cnvBuffer, start, buffPos-1, "UTF-8");
     501                    stringPair[1] = new String(cnvBuffer, start, buffPos-1, StandardCharsets.UTF_8);
    508502            }
    509503            long bytes = toReadStart - bytesToRead;
     
    525519    /**
    526520     * read a string pair (see o5m definition)
    527      * @throws IOException in case of I/O error
    528      */
    529     private void readStringPair() throws IOException {
     521     */
     522    private void readStringPair() {
    530523        int stringRef = readUnsignedNum32();
    531524        if (stringRef == 0) {
     
    540533
    541534                if (b == 0) {
    542                     stringPair[cnt] = new String(cnvBuffer, start, buffPos-start-1, "UTF-8");
     535                    stringPair[cnt] = new String(cnvBuffer, start, buffPos-start-1, StandardCharsets.UTF_8);
    543536                    ++cnt;
    544537                    start = buffPos;
     
    570563            throw new IOException(tr("unsupported header"));
    571564        }
    572         header = new String(ioBuf, 0, 3, "UTF-8");
     565        header = new String(ioBuf, 0, 3, StandardCharsets.UTF_8);
    573566    }
    574567
     
    707700     * Exception thrown after user cancellation.
    708701     */
     702    @SuppressWarnings("serial")
    709703    private static final class O5mParsingCancelException extends Exception implements ImportCancelException {
    710704        O5mParsingCancelException(String msg) {
Note: See TracChangeset for help on using the changeset viewer.