Changeset 30738 in osm for applications/editors/josm/plugins/cadastre-fr/src
- Timestamp:
- 2014-10-19T01:27:04+02:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CacheControl.java
r30737 r30738 1 1 // License: GPL. v2 and later. Copyright 2008-2009 by Pieren <pieren3@gmail.com> and others 2 2 package cadastre_fr; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.io.BufferedOutputStream; 7 import java.io.File; 8 import java.io.FileInputStream; 9 import java.io.FileOutputStream; 10 import java.io.IOException; 11 import java.io.ObjectInputStream; 12 import java.io.ObjectOutputStream; 13 import java.io.OutputStream; 14 import java.util.ArrayList; 15 import java.util.concurrent.locks.Lock; 16 import java.util.concurrent.locks.ReentrantLock; 17 18 import javax.swing.JDialog; 19 import javax.swing.JOptionPane; 20 21 import org.openstreetmap.josm.Main; 22 3 23 /** 4 24 * This class handles the WMS layer cache mechanism. The design is oriented for a good performance (no … … 10 30 * is inserted before each append and an exception is raised at objects read). 11 31 */ 12 13 import static org.openstreetmap.josm.tools.I18n.tr;14 15 import java.io.*;16 import java.util.ArrayList;17 import java.util.concurrent.locks.Lock;18 import java.util.concurrent.locks.ReentrantLock;19 20 import javax.swing.JDialog;21 import javax.swing.JOptionPane;22 import org.openstreetmap.josm.Main;23 24 32 public class CacheControl implements Runnable { 25 33 … … 32 40 super(out); 33 41 } 42 @Override 34 43 protected void writeStreamHeader() throws IOException { 35 44 reset(); … … 40 49 41 50 public static int cacheSize = 500; 42 43 51 44 52 public WMSLayer wmsLayer = null; … … 141 149 public boolean loadCache(File file, int currentLambertZone) { 142 150 boolean successfulRead = false; 143 FileInputStream fis = null; 144 ObjectInputStream ois = null; 145 try { 146 fis = new FileInputStream(file); 147 ois = new ObjectInputStream(fis); 151 try ( 152 FileInputStream fis = new FileInputStream(file); 153 ObjectInputStream ois = new ObjectInputStream(fis); 154 ) { 148 155 successfulRead = wmsLayer.read(file, ois, currentLambertZone); 149 156 } catch (Exception ex) { … … 151 158 JOptionPane.showMessageDialog(Main.parent, tr("Error loading file.\nProbably an old version of the cache file."), tr("Error"), JOptionPane.ERROR_MESSAGE); 152 159 return false; 153 } finally {154 try {155 ois.close();156 fis.close();157 } catch (Exception e) {158 e.printStackTrace();159 }160 160 } 161 161 if (successfulRead && wmsLayer.isRaster()) { … … 165 165 return successfulRead; 166 166 } 167 168 167 169 168 public synchronized void saveCache(GeorefImage image) { … … 177 176 * Thread saving the grabbed images in background. 178 177 */ 178 @Override 179 179 public synchronized void run() { 180 180 for (;;) { … … 186 186 try { 187 187 if (file.exists()) { 188 ObjectOutputStreamAppend oos = new ObjectOutputStreamAppend( 189 new BufferedOutputStream(new FileOutputStream(file, true))); 190 for (int i=0; i < size; i++) { 191 oos.writeObject(imagesToSave.get(i)); 188 try (ObjectOutputStreamAppend oos = new ObjectOutputStreamAppend( 189 new BufferedOutputStream(new FileOutputStream(file, true)))) { 190 for (int i=0; i < size; i++) { 191 oos.writeObject(imagesToSave.get(i)); 192 } 192 193 } 193 oos.close();194 194 } else { 195 ObjectOutputStream oos = new ObjectOutputStream( 196 new BufferedOutputStream(new FileOutputStream(file))); 197 wmsLayer.write(file, oos); 198 for (int i=0; i < size; i++) { 199 oos.writeObject(imagesToSave.get(i)); 195 try (ObjectOutputStream oos = new ObjectOutputStream( 196 new BufferedOutputStream(new FileOutputStream(file)))) { 197 wmsLayer.write(file, oos); 198 for (int i=0; i < size; i++) { 199 oos.writeObject(imagesToSave.get(i)); 200 } 200 201 } 201 oos.close();202 202 } 203 203 } catch (IOException e) { 204 e.printStackTrace(System.out);204 Main.error(e); 205 205 } 206 206 imagesLock.lock(); -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreGrabber.java
r28961 r30738 22 22 private CadastreInterface wmsInterface = new CadastreInterface(); 23 23 24 public GeorefImage grab(WMSLayer wmsLayer, EastNorth lambertMin, EastNorth lambertMax) throws IOException, OsmTransferException {25 24 public GeorefImage grab(WMSLayer wmsLayer, EastNorth lambertMin, EastNorth lambertMax) 25 throws IOException, OsmTransferException { 26 26 try { 27 27 URL url = null; … … 88 88 wmsInterface.urlConn.setRequestMethod("GET"); 89 89 wmsInterface.setCookie(); 90 InputStream is = new ProgressInputStream(wmsInterface.urlConn, NullProgressMonitor.INSTANCE); 91 BufferedImage img = ImageIO.read(is); 92 is.close(); 93 return img; 90 try (InputStream is = new ProgressInputStream(wmsInterface.urlConn, NullProgressMonitor.INSTANCE)) { 91 return ImageIO.read(is); 92 } 94 93 } 95 94 … … 97 96 return wmsInterface; 98 97 } 99 100 98 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreInterface.java
r30737 r30738 229 229 } 230 230 if (Main.isDebugEnabled()) { 231 231 Main.debug(lines); 232 232 } 233 233 } catch (MalformedURLException e) { … … 284 284 urlConn.setDoInput(true); 285 285 setCookie(); 286 OutputStream wr = urlConn.getOutputStream() ;287 wr.write(content.getBytes()); 288 System.out.println("POST "+content);289 wr.flush(); 290 wr.close();291 BufferedReader rd = new BufferedReader(new InputStreamReader(urlConn.getInputStream())) ;292 while ((ln = rd.readLine()) != null) { 293 lines += ln; 294 } 295 rd.close();286 try (OutputStream wr = urlConn.getOutputStream()) { 287 wr.write(content.getBytes()); 288 Main.info("POST "+content); 289 wr.flush(); 290 } 291 try (BufferedReader rd = new BufferedReader(new InputStreamReader(urlConn.getInputStream()))) { 292 while ((ln = rd.readLine()) != null) { 293 lines += ln; 294 } 295 } 296 296 urlConn.disconnect(); 297 297 if (lines != null) { … … 371 371 setCookie(urlConn2); 372 372 urlConn2.connect(); 373 System.out.println("GET "+getAllImagesURL);374 BufferedReader rd = new BufferedReader(new InputStreamReader(urlConn2.getInputStream())) ;375 while ((ln = rd.readLine()) != null) { 376 lines += ln; 377 } 378 rd.close();373 Main.info("GET "+getAllImagesURL); 374 try (BufferedReader rd = new BufferedReader(new InputStreamReader(urlConn2.getInputStream()))) { 375 while ((ln = rd.readLine()) != null) { 376 lines += ln; 377 } 378 } 379 379 urlConn2.disconnect(); 380 //System.out.println("GET="+lines);381 380 } catch (IOException e) { 382 381 listOfFeuilles.clear(); 383 e.printStackTrace();382 Main.error(e); 384 383 } 385 384 return lines; … … 483 482 } 484 483 System.out.println("GET "+searchFormURL); 485 BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream())) ;486 while ((ln = in.readLine()) != null) { 487 line += ln; 488 } 489 in.close();484 try (BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()))) { 485 while ((ln = in.readLine()) != null) { 486 line += ln; 487 } 488 } 490 489 urlConn.disconnect(); 491 490 parseBBoxCommune(wmsLayer, line); … … 511 510 512 511 private void parseGeoreferences(WMSLayer wmsLayer, String input) { 513 /* commented since cadastre WMS changes mid july 2013 512 /* commented since cadastre WMS changes mid july 2013 514 513 * until new GeoBox coordinates parsing is solved */ 515 514 // if (input.lastIndexOf(cBBoxCommunStart) != -1) { -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreSessionExporter.java
r29922 r30738 30 30 } 31 31 32 33 32 @Override 33 public Collection<Layer> getDependencies() { 34 34 return Collections.emptySet(); 35 35 } 36 36 37 38 37 @Override 38 public Component getExportPanel() { 39 39 final JPanel p = new JPanel(new GridBagLayout()); 40 40 export = new JCheckBox(); … … 46 46 p.add(GBC.glue(1,0), GBC.std().fill(GBC.HORIZONTAL)); 47 47 return p; 48 48 } 49 49 50 51 50 @Override 51 public boolean shallExport() { 52 52 return export.isSelected(); 53 53 } 54 54 55 56 57 58 55 @Override 56 public boolean requiresZip() { 57 return false; 58 } 59 59 60 61 60 @Override 61 public Element export(ExportSupport support) throws IOException { 62 62 Element layerEl = support.createElement("layer"); 63 63 layerEl.setAttribute("type", "cadastre-fr"); … … 76 76 file.appendChild(support.createTextNode(url.toString())); 77 77 return layerEl; 78 78 } 79 79 80 80 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreSessionImporter.java
r30701 r30738 22 22 public class CadastreSessionImporter implements SessionLayerImporter{ 23 23 24 25 26 27 24 @Override 25 public Layer load(Element elem, ImportSupport support, 26 ProgressMonitor progressMonitor) throws IOException, 27 IllegalDataException { 28 28 String version = elem.getAttribute("version"); 29 29 if (!"0.1".equals(version)) { … … 41 41 fileStr = URLDecoder.decode(fileStr, "UTF-8"); 42 42 fileStr = fileStr.substring(fileStr.indexOf(":/")+2); 43 43 String filename = fileStr.substring(fileStr.lastIndexOf("/")+1,fileStr.length()); 44 44 String ext = (filename.lastIndexOf(".")==-1)?"":filename.substring(filename.lastIndexOf(".")+1,filename.length()); 45 45 // create layer and load cache … … 60 60 throw new RuntimeException(e); 61 61 } 62 62 } 63 63 64 64 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadSVGBuilding.java
r30737 r30738 43 43 private static String errorMessage; 44 44 45 45 /** 46 * Constructs a new {@code DownloadSVGBuilding}. 47 */ 46 48 public DownloadSVGBuilding(WMSLayer wmsLayer) { 47 49 super(tr("Downloading {0}", wmsLayer.getName())); … … 240 242 wmsInterface.urlConn.setRequestMethod("GET"); 241 243 wmsInterface.setCookie(); 242 InputStream is = new ProgressInputStream(wmsInterface.urlConn, NullProgressMonitor.INSTANCE);243 244 File file = new File(CadastrePlugin.cacheDir + "building.svg"); 244 245 String svg = new String(); 245 try { 246 try (InputStream is = new ProgressInputStream(wmsInterface.urlConn, NullProgressMonitor.INSTANCE)) { 246 247 if (file.exists()) 247 248 file.delete(); 248 BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file, true)); 249 InputStreamReader isr =new InputStreamReader(is); 250 BufferedReader br = new BufferedReader(isr); 251 String line=""; 252 while ( null!=(line=br.readLine())){ 253 line += "\n"; 254 bos.write(line.getBytes()); 255 svg += line; 256 } 257 br.close(); 258 bos.close(); 249 try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file, true)); 250 InputStreamReader isr = new InputStreamReader(is); 251 BufferedReader br = new BufferedReader(isr)) { 252 String line=""; 253 while ( null!=(line=br.readLine())){ 254 line += "\n"; 255 bos.write(line.getBytes()); 256 svg += line; 257 } 258 } 259 259 } catch (IOException e) { 260 e.printStackTrace(System.out); 261 } 262 is.close(); 260 Main.error(e); 261 } 263 262 return svg; 264 263 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadSVGTask.java
r30737 r30738 47 47 private static String errorMessage; 48 48 49 /** 50 * Constructs a new {@code DownloadSVGTask}. 51 */ 49 52 public DownloadSVGTask(WMSLayer wmsLayer) { 50 53 super(tr("Downloading {0}", wmsLayer.getName())); … … 194 197 wmsInterface.urlConn.setRequestMethod("GET"); 195 198 wmsInterface.setCookie(); 196 InputStream is = new ProgressInputStream(wmsInterface.urlConn, NullProgressMonitor.INSTANCE);197 199 File file = new File(CadastrePlugin.cacheDir + "boundary.svg"); 198 200 String svg = new String(); 199 try { 201 try (InputStream is = new ProgressInputStream(wmsInterface.urlConn, NullProgressMonitor.INSTANCE)) { 200 202 if (file.exists()) 201 203 file.delete(); 202 BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file, true)); 203 InputStreamReader isr =new InputStreamReader(is); 204 BufferedReader br = new BufferedReader(isr); 205 String line=""; 206 while ( null!=(line=br.readLine())){ 207 line += "\n"; 208 bos.write(line.getBytes()); 209 svg += line; 204 try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file, true)); 205 InputStreamReader isr =new InputStreamReader(is); 206 BufferedReader br = new BufferedReader(isr)) { 207 String line=""; 208 while ( null!=(line=br.readLine())){ 209 line += "\n"; 210 bos.write(line.getBytes()); 211 svg += line; 212 } 210 213 } 211 br.close();212 bos.close();213 214 } catch (IOException e) { 214 e.printStackTrace(System.out); 215 } 216 is.close(); 215 Main.error(e); 216 } 217 217 return svg; 218 218 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java
r30737 r30738 133 133 // if the layer is currently saving the images in the cache, wait until it's finished 134 134 if(grabThread != null) 135 135 grabThread.cancel(); 136 136 grabThread = null; 137 137 super.destroy();
Note:
See TracChangeset
for help on using the changeset viewer.