Changeset 33969 in osm for applications/editors/josm


Ignore:
Timestamp:
2017-12-31T14:04:30+01:00 (7 years ago)
Author:
donvip
Message:

remove unused code calling deprecated (now removed) API

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsApi.java

    r33870 r33969  
    1313import java.net.ConnectException;
    1414import java.net.HttpURLConnection;
    15 import java.net.MalformedURLException;
    1615import java.net.SocketTimeoutException;
    1716import java.net.URL;
     
    2019import java.util.HashMap;
    2120import java.util.List;
    22 import java.util.zip.GZIPInputStream;
    23 import java.util.zip.Inflater;
    24 import java.util.zip.InflaterInputStream;
    2521
    2622import org.openstreetmap.josm.Main;
    2723import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    28 import org.openstreetmap.josm.io.OsmApiException;
    29 import org.openstreetmap.josm.io.OsmTransferCanceledException;
    30 import org.openstreetmap.josm.io.ProgressInputStream;
    3124import org.openstreetmap.josm.tools.CheckParameterUtil;
    3225import org.openstreetmap.josm.tools.Logging;
     
    447440        }
    448441    }
    449 
    450     protected InputStream getInputStream(String urlStr, ProgressMonitor progressMonitor) throws SdsTransferException {
    451         urlStr = getBaseUrl() + urlStr;
    452         try {
    453             URL url = null;
    454             try {
    455                 url = new URL(urlStr.replace(" ", "%20"));
    456             } catch (MalformedURLException e) {
    457                 throw new SdsTransferException(e);
    458             }
    459             try {
    460                 activeConnection = (HttpURLConnection) url.openConnection();
    461             } catch (Exception e) {
    462                 throw new SdsTransferException(tr("Failed to open connection to API {0}.", url.toExternalForm()), e);
    463             }
    464             if (cancel) {
    465                 activeConnection.disconnect();
    466                 return null;
    467             }
    468 
    469             addAuth(activeConnection);
    470 
    471             if (cancel)
    472                 throw new SdsTransferException();
    473             if (Main.pref.getBoolean("osm-server.use-compression", true)) {
    474                 activeConnection.setRequestProperty("Accept-Encoding", "gzip, deflate");
    475             }
    476 
    477             activeConnection.setConnectTimeout(Main.pref.getInt("socket.timeout.connect", 15)*1000);
    478 
    479             try {
    480                 System.out.println("GET " + url);
    481                 activeConnection.connect();
    482             } catch (Exception e) {
    483                 e.printStackTrace();
    484                 throw new SdsTransferException(tr("Could not connect to the OSM server. Please check your internet connection."), e);
    485             }
    486             try {
    487                 if (activeConnection.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED)
    488                     throw new OsmApiException(HttpURLConnection.HTTP_UNAUTHORIZED, null, null);
    489 
    490                 if (activeConnection.getResponseCode() == HttpURLConnection.HTTP_PROXY_AUTH)
    491                     throw new OsmTransferCanceledException(tr("Proxy Authentication Required"));
    492 
    493                 String encoding = activeConnection.getContentEncoding();
    494                 if (activeConnection.getResponseCode() != HttpURLConnection.HTTP_OK) {
    495                     String errorHeader = activeConnection.getHeaderField("Error");
    496                     StringBuilder errorBody = new StringBuilder();
    497                     try {
    498                         InputStream i = FixEncoding(activeConnection.getErrorStream(), encoding);
    499                         if (i != null) {
    500                             BufferedReader in = new BufferedReader(new InputStreamReader(i, StandardCharsets.UTF_8));
    501                             String s;
    502                             while ((s = in.readLine()) != null) {
    503                                 errorBody.append(s);
    504                                 errorBody.append("\n");
    505                             }
    506                         }
    507                     } catch (Exception e) {
    508                         errorBody.append(tr("Reading error text failed."));
    509                     }
    510 
    511                     throw new OsmApiException(activeConnection.getResponseCode(), errorHeader, errorBody.toString());
    512                 }
    513 
    514                 return FixEncoding(new ProgressInputStream(activeConnection, progressMonitor), encoding);
    515             } catch (Exception e) {
    516                 if (e instanceof SdsTransferException)
    517                     throw (SdsTransferException) e;
    518                 else
    519                     throw new SdsTransferException(e);
    520 
    521             }
    522         } finally {
    523             progressMonitor.invalidate();
    524         }
    525     }
    526 
    527     private InputStream FixEncoding(InputStream stream, String encoding) throws IOException {
    528         if (encoding != null && encoding.equalsIgnoreCase("gzip")) {
    529             stream = new GZIPInputStream(stream);
    530         } else if (encoding != null && encoding.equalsIgnoreCase("deflate")) {
    531             stream = new InflaterInputStream(stream, new Inflater(true));
    532         }
    533         return stream;
    534     }
    535442}
Note: See TracChangeset for help on using the changeset viewer.