Changeset 5874 in josm for trunk/src/org/openstreetmap/josm/data
- Timestamp:
- 2013-04-16T19:57:43+02:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/AutosaveTask.java
r5566 r5874 38 38 import org.openstreetmap.josm.io.OsmExporter; 39 39 import org.openstreetmap.josm.io.OsmImporter; 40 import org.openstreetmap.josm.tools.Utils; 40 41 41 42 /** … … 156 157 PrintStream ps = new PrintStream(pidFile); 157 158 ps.println(ManagementFactory.getRuntimeMXBean().getName()); 158 ps.close();159 Utils.close(ps); 159 160 } catch (Throwable t) { 160 161 System.err.println(t.getMessage()); … … 299 300 System.err.println(t.getClass()+":"+t.getMessage()); 300 301 } finally { 301 reader.close();302 Utils.close(reader); 302 303 } 303 304 } catch (Throwable t) { -
trunk/src/org/openstreetmap/josm/data/CustomConfigurator.java
r5590 r5874 1 1 package org.openstreetmap.josm.data; 2 2 3 import javax.script.ScriptException;4 import org.openstreetmap.josm.Main;5 import org.openstreetmap.josm.data.Preferences.Setting;6 3 import static org.openstreetmap.josm.tools.I18n.tr; 7 4 … … 12 9 import java.io.File; 13 10 import java.io.FileInputStream; 14 import java.io.IOException;15 11 import java.io.InputStream; 16 17 12 import java.util.ArrayList; 18 import java.util.Arrays;19 13 import java.util.Collection; 20 14 import java.util.Collections; … … 30 24 import java.util.regex.Matcher; 31 25 import java.util.regex.Pattern; 26 32 27 import javax.script.ScriptEngine; 33 28 import javax.script.ScriptEngineManager; 29 import javax.script.ScriptException; 34 30 import javax.swing.JOptionPane; 35 31 import javax.swing.SwingUtilities; … … 42 38 import javax.xml.transform.stream.StreamResult; 43 39 40 import org.openstreetmap.josm.Main; 41 import org.openstreetmap.josm.data.Preferences.Setting; 44 42 import org.openstreetmap.josm.gui.io.DownloadFileTask; 45 43 import org.openstreetmap.josm.plugins.PluginDownloadTask; … … 47 45 import org.openstreetmap.josm.plugins.ReadLocalPluginInformationTask; 48 46 import org.openstreetmap.josm.tools.LanguageInfo; 47 import org.openstreetmap.josm.tools.Utils; 49 48 import org.w3c.dom.Document; 50 49 import org.w3c.dom.Element; … … 441 440 log("Error reading custom preferences: "+ex.getMessage()); 442 441 } finally { 443 try { 444 if (is != null) { 445 is.close(); 446 } 447 } catch (IOException ex) { } 442 Utils.close(is); 448 443 } 449 444 log("-- Reading complete --"); -
trunk/src/org/openstreetmap/josm/data/Preferences.java
r5871 r5874 18 18 import java.lang.annotation.RetentionPolicy; 19 19 import java.lang.reflect.Field; 20 import java.nio.channels.FileChannel;21 20 import java.util.ArrayList; 22 21 import java.util.Arrays; … … 137 136 } 138 137 138 /** 139 * Base abstract class of all settings, holding the setting value. 140 * 141 * @param <T> The setting type 142 */ 139 143 abstract public static class AbstractSetting<T> implements Setting<T> { 140 private T value; 144 private final T value; 145 /** 146 * Constructs a new {@code AbstractSetting} with the given value 147 * @param value The setting value 148 */ 141 149 public AbstractSetting(T value) { 142 150 this.value = value; 143 151 } 144 @Override 145 public T getValue() { 152 @Override public T getValue() { 146 153 return value; 147 154 } 148 @Override 149 public String toString() { 155 @Override public String toString() { 150 156 return value != null ? value.toString() : "null"; 151 157 } 152 158 } 153 159 160 /** 161 * Setting containing a {@link String} value. 162 */ 154 163 public static class StringSetting extends AbstractSetting<String> { 164 /** 165 * Constructs a new {@code StringSetting} with the given value 166 * @param value The setting value 167 */ 155 168 public StringSetting(String value) { 156 169 super(value); 157 170 } 158 public void visit(SettingVisitor visitor) {171 @Override public void visit(SettingVisitor visitor) { 159 172 visitor.visit(this); 160 173 } 161 public StringSetting getNullInstance() {174 @Override public StringSetting getNullInstance() { 162 175 return new StringSetting(null); 163 176 } 164 177 } 165 178 179 /** 180 * Setting containing a {@link List} of {@link String} values. 181 */ 166 182 public static class ListSetting extends AbstractSetting<List<String>> { 183 /** 184 * Constructs a new {@code ListSetting} with the given value 185 * @param value The setting value 186 */ 167 187 public ListSetting(List<String> value) { 168 188 super(value); 169 189 } 170 public void visit(SettingVisitor visitor) {190 @Override public void visit(SettingVisitor visitor) { 171 191 visitor.visit(this); 172 192 } 173 public ListSetting getNullInstance() {193 @Override public ListSetting getNullInstance() { 174 194 return new ListSetting(null); 175 195 } 176 196 } 177 197 198 /** 199 * Setting containing a {@link List} of {@code List}s of {@link String} values. 200 */ 178 201 public static class ListListSetting extends AbstractSetting<List<List<String>>> { 202 /** 203 * Constructs a new {@code ListListSetting} with the given value 204 * @param value The setting value 205 */ 179 206 public ListListSetting(List<List<String>> value) { 180 207 super(value); 181 208 } 182 public void visit(SettingVisitor visitor) {209 @Override public void visit(SettingVisitor visitor) { 183 210 visitor.visit(this); 184 211 } 185 public ListListSetting getNullInstance() {212 @Override public ListListSetting getNullInstance() { 186 213 return new ListListSetting(null); 187 214 } 188 215 } 189 216 217 /** 218 * Setting containing a {@link List} of {@link Map}s of {@link String} values. 219 */ 190 220 public static class MapListSetting extends AbstractSetting<List<Map<String, String>>> { 221 /** 222 * Constructs a new {@code MapListSetting} with the given value 223 * @param value The setting value 224 */ 191 225 public MapListSetting(List<Map<String, String>> value) { 192 226 super(value); 193 227 } 194 public void visit(SettingVisitor visitor) {228 @Override public void visit(SettingVisitor visitor) { 195 229 visitor.visit(this); 196 230 } 197 public MapListSetting getNullInstance() {231 @Override public MapListSetting getNullInstance() { 198 232 return new MapListSetting(null); 199 233 } … … 265 299 266 300 /** 267 * Return the location of the user defined preferences file 301 * Returns the location of the user defined preferences directory 302 * @return The location of the user defined preferences directory 268 303 */ 269 304 public String getPreferencesDir() { … … 274 309 } 275 310 311 /** 312 * Returns the user defined preferences directory 313 * @return The user defined preferences directory 314 */ 276 315 public File getPreferencesDirFile() { 277 316 if (preferencesDirFile != null) … … 292 331 } 293 332 333 /** 334 * Returns the user preferences file 335 * @return The user preferences file 336 */ 294 337 public File getPreferenceFile() { 295 338 return new File(getPreferencesDirFile(), "preferences.xml"); 296 339 } 297 340 341 /** 342 * Returns the user plugin directory 343 * @return The user plugin directory 344 */ 298 345 public File getPluginsDirectory() { 299 346 return new File(getPreferencesDirFile(), "plugins"); … … 551 598 552 599 // Backup old preferences if there are old preferences 553 if (prefFile.exists()) {554 copyFile(prefFile, backupFile);600 if (prefFile.exists()) { 601 Utils.copyFile(prefFile, backupFile); 555 602 } 556 603 … … 558 605 new FileOutputStream(prefFile + "_tmp"), "utf-8"), false); 559 606 out.print(toXML(false)); 560 out.close();607 Utils.close(out); 561 608 562 609 File tmpFile = new File(prefFile + "_tmp"); 563 copyFile(tmpFile, prefFile);610 Utils.copyFile(tmpFile, prefFile); 564 611 tmpFile.delete(); 565 612 … … 575 622 file.setReadable(true, true); 576 623 file.setWritable(true, true); 577 }578 579 /**580 * Simple file copy function that will overwrite the target file581 * Taken from http://www.rgagnon.com/javadetails/java-0064.html (CC-NC-BY-SA)582 * @param in583 * @param out584 * @throws IOException585 */586 public static void copyFile(File in, File out) throws IOException {587 FileChannel inChannel = new FileInputStream(in).getChannel();588 FileChannel outChannel = new FileOutputStream(out).getChannel();589 try {590 inChannel.transferTo(0, inChannel.size(),591 outChannel);592 }593 catch (IOException e) {594 throw e;595 }596 finally {597 if (inChannel != null) {598 inChannel.close();599 }600 if (outChannel != null) {601 outChannel.close();602 }603 }604 624 } 605 625 … … 615 635 fromXML(in); 616 636 } finally { 617 in.close();637 Utils.close(in); 618 638 } 619 639 } -
trunk/src/org/openstreetmap/josm/data/ServerSidePreferences.java
r4874 r5874 22 22 import org.openstreetmap.josm.io.OsmConnection; 23 23 import org.openstreetmap.josm.tools.Base64; 24 import org.openstreetmap.josm.tools.Utils; 24 25 25 26 /** … … 91 92 PrintWriter out = new PrintWriter(new OutputStreamWriter(con.getOutputStream())); 92 93 out.println(s); 93 out.close();94 con.getInputStream().close();94 Utils.close(out); 95 Utils.close(con.getInputStream()); 95 96 con.disconnect(); 96 97 JOptionPane.showMessageDialog( -
trunk/src/org/openstreetmap/josm/data/Version.java
r5868 r5874 44 44 } 45 45 } finally { 46 in.close();46 Utils.close(in); 47 47 } 48 48 s = sb.toString(); -
trunk/src/org/openstreetmap/josm/data/imagery/WmsCache.java
r5763 r5874 156 156 } 157 157 } finally { 158 try { 159 if (fis != null) { 160 fis.close(); 161 } 162 if (fos != null) { 163 fos.close(); 164 } 165 } catch (IOException e) { 166 e.printStackTrace(); 167 } 158 Utils.close(fos); 159 Utils.close(fis); 168 160 } 169 161 … … 532 524 totalFileSize += Utils.copyStream(imageData, os); 533 525 } finally { 534 os.close();526 Utils.close(os); 535 527 } 536 528 } -
trunk/src/org/openstreetmap/josm/data/projection/datum/NTV2GridShiftFile.java
r5073 r5874 25 25 import java.util.ArrayList; 26 26 import java.util.HashMap; 27 28 import org.openstreetmap.josm.tools.Utils; 27 29 28 30 /** … … 151 153 lastSubGrid = topLevelSubGrid[0]; 152 154 153 in.close();155 Utils.close(in); 154 156 } 155 157 -
trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java
r5644 r5874 57 57 import org.openstreetmap.josm.gui.preferences.ValidatorPreference; 58 58 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference; 59 import org.openstreetmap.josm.tools.Utils; 59 60 60 61 /** … … 167 168 168 169 public static void saveIgnoredErrors() { 170 PrintWriter out = null; 169 171 try { 170 final PrintWriterout = new PrintWriter(new FileWriter(getValidatorDir() + "ignorederrors"), false);172 out = new PrintWriter(new FileWriter(getValidatorDir() + "ignorederrors"), false); 171 173 for (String e : ignoredErrors) { 172 174 out.println(e); 173 175 } 174 out.close(); 175 } catch (final IOException e) { 176 } catch (IOException e) { 176 177 e.printStackTrace(); 178 } finally { 179 Utils.close(out); 177 180 } 178 181 }
Note:
See TracChangeset
for help on using the changeset viewer.