Ignore:
Timestamp:
2015-05-06T00:23:51+02:00 (9 years ago)
Author:
Don-vip
Message:

fix various issues:

  • performance - inefficient use of keySet iterator instead of entrySet iterator
  • squid:S2674: The value returned from a stream read should be checked
  • remove unused imports
  • improve javadoc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/projection/datum/NTV2SubGrid.java

    r8308 r8332  
    7575        byte[] b4 = new byte[4];
    7676        byte[] b1 = new byte[1];
    77         in.read(b8);
    78         in.read(b8);
     77        readBytes(in, b8);
     78        readBytes(in, b8);
    7979        subGridName = new String(b8, StandardCharsets.UTF_8).trim();
    80         in.read(b8);
    81         in.read(b8);
     80        readBytes(in, b8);
     81        readBytes(in, b8);
    8282        parentSubGridName = new String(b8, StandardCharsets.UTF_8).trim();
    83         in.read(b8);
    84         in.read(b8);
     83        readBytes(in, b8);
     84        readBytes(in, b8);
    8585        created = new String(b8, StandardCharsets.UTF_8);
    86         in.read(b8);
    87         in.read(b8);
     86        readBytes(in, b8);
     87        readBytes(in, b8);
    8888        updated = new String(b8, StandardCharsets.UTF_8);
    89         in.read(b8);
    90         in.read(b8);
     89        readBytes(in, b8);
     90        readBytes(in, b8);
    9191        minLat = NTV2Util.getDouble(b8, bigEndian);
    92         in.read(b8);
    93         in.read(b8);
     92        readBytes(in, b8);
     93        readBytes(in, b8);
    9494        maxLat = NTV2Util.getDouble(b8, bigEndian);
    95         in.read(b8);
    96         in.read(b8);
     95        readBytes(in, b8);
     96        readBytes(in, b8);
    9797        minLon = NTV2Util.getDouble(b8, bigEndian);
    98         in.read(b8);
    99         in.read(b8);
     98        readBytes(in, b8);
     99        readBytes(in, b8);
    100100        maxLon = NTV2Util.getDouble(b8, bigEndian);
    101         in.read(b8);
    102         in.read(b8);
     101        readBytes(in, b8);
     102        readBytes(in, b8);
    103103        latInterval = NTV2Util.getDouble(b8, bigEndian);
    104         in.read(b8);
    105         in.read(b8);
     104        readBytes(in, b8);
     105        readBytes(in, b8);
    106106        lonInterval = NTV2Util.getDouble(b8, bigEndian);
    107107        lonColumnCount = 1 + (int)((maxLon - minLon) / lonInterval);
    108108        latRowCount = 1 + (int)((maxLat - minLat) / latInterval);
    109         in.read(b8);
    110         in.read(b8);
     109        readBytes(in, b8);
     110        readBytes(in, b8);
    111111        nodeCount = NTV2Util.getInt(b8, bigEndian);
    112112        if (nodeCount != lonColumnCount * latRowCount)
     
    123123            // certain VM which are not able to read byte blocks when the resource file is
    124124            // in a .jar file (Pieren)
    125             in.read(b1); b4[0] = b1[0];
    126             in.read(b1); b4[1] = b1[0];
    127             in.read(b1); b4[2] = b1[0];
    128             in.read(b1); b4[3] = b1[0];
     125            readBytes(in, b1); b4[0] = b1[0];
     126            readBytes(in, b1); b4[1] = b1[0];
     127            readBytes(in, b1); b4[2] = b1[0];
     128            readBytes(in, b1); b4[3] = b1[0];
    129129            latShift[i] = NTV2Util.getFloat(b4, bigEndian);
    130             in.read(b1); b4[0] = b1[0];
    131             in.read(b1); b4[1] = b1[0];
    132             in.read(b1); b4[2] = b1[0];
    133             in.read(b1); b4[3] = b1[0];
     130            readBytes(in, b1); b4[0] = b1[0];
     131            readBytes(in, b1); b4[1] = b1[0];
     132            readBytes(in, b1); b4[2] = b1[0];
     133            readBytes(in, b1); b4[3] = b1[0];
    134134            lonShift[i] = NTV2Util.getFloat(b4, bigEndian);
    135             in.read(b1); b4[0] = b1[0];
    136             in.read(b1); b4[1] = b1[0];
    137             in.read(b1); b4[2] = b1[0];
    138             in.read(b1); b4[3] = b1[0];
     135            readBytes(in, b1); b4[0] = b1[0];
     136            readBytes(in, b1); b4[1] = b1[0];
     137            readBytes(in, b1); b4[2] = b1[0];
     138            readBytes(in, b1); b4[3] = b1[0];
    139139            if (loadAccuracy) {
    140140                latAccuracy[i] = NTV2Util.getFloat(b4, bigEndian);
    141141            }
    142             in.read(b1); b4[0] = b1[0];
    143             in.read(b1); b4[1] = b1[0];
    144             in.read(b1); b4[2] = b1[0];
    145             in.read(b1); b4[3] = b1[0];
     142            readBytes(in, b1); b4[0] = b1[0];
     143            readBytes(in, b1); b4[1] = b1[0];
     144            readBytes(in, b1); b4[2] = b1[0];
     145            readBytes(in, b1); b4[3] = b1[0];
    146146            if (loadAccuracy) {
    147147                lonAccuracy[i] = NTV2Util.getFloat(b4, bigEndian);
    148148            }
     149        }
     150    }
     151
     152    private void readBytes(InputStream in, byte[] b) throws IOException {
     153        if (in.read(b) < b.length) {
     154            Main.error("Failed to read expected amount of bytes ("+ b.length +") from stream");
    149155        }
    150156    }
     
    194200     * Bi-Linear interpolation of four nearest node values as described in
    195201     * 'GDAit Software Architecture Manual' produced by the <a
    196      * href='http://www.sli.unimelb.edu.au/gda94'>Geomatics
    197      * Department of the University of Melbourne</a>
     202     * href='http://www.dtpli.vic.gov.au/property-and-land-titles/geodesy/geocentric-datum-of-australia-1994-gda94/gda94-useful-tools'>
     203     * Geomatics Department of the University of Melbourne</a>
    198204     * @param a value at the A node
    199205     * @param b value at the B node
    200206     * @param c value at the C node
    201207     * @param d value at the D node
    202      * @param X Longitude factor
    203      * @param Y Latitude factor
     208     * @param x Longitude factor
     209     * @param y Latitude factor
    204210     * @return interpolated value
    205211     */
    206     private final double interpolate(float a, float b, float c, float d, double X, double Y) {
    207         return a + (((double)b - (double)a) * X) + (((double)c - (double)a) * Y) +
    208         (((double)a + (double)d - b - c) * X * Y);
     212    private final double interpolate(float a, float b, float c, float d, double x, double y) {
     213        return a + (((double)b - (double)a) * x) + (((double)c - (double)a) * y) +
     214        (((double)a + (double)d - b - c) * x * y);
    209215    }
    210216
     
    213219     * of the GridShiftFile. The algorithm is described in
    214220     * 'GDAit Software Architecture Manual' produced by the <a
    215      * href='http://www.sli.unimelb.edu.au/gda94'>Geomatics
    216      * Department of the University of Melbourne</a>
     221     * href='http://www.dtpli.vic.gov.au/property-and-land-titles/geodesy/geocentric-datum-of-australia-1994-gda94/gda94-useful-tools'>
     222     * Geomatics Department of the University of Melbourne</a>
    217223     * <p>This method is thread safe for both memory based and file based node data.
    218224     * @param gs GridShift object containing the coordinate to shift and the shift values
Note: See TracChangeset for help on using the changeset viewer.