vassalengine-svn Mailing List for VASSAL Engine
Brought to you by:
rodneykinney,
uckelman
You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(2) |
Oct
(187) |
Nov
(124) |
Dec
(101) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(51) |
Feb
(91) |
Mar
(139) |
Apr
(84) |
May
(151) |
Jun
(125) |
Jul
(54) |
Aug
(49) |
Sep
(89) |
Oct
(111) |
Nov
(19) |
Dec
(189) |
2008 |
Jan
(150) |
Feb
(231) |
Mar
(218) |
Apr
(111) |
May
(199) |
Jun
(71) |
Jul
(178) |
Aug
(149) |
Sep
(68) |
Oct
(204) |
Nov
(219) |
Dec
(121) |
2009 |
Jan
(288) |
Feb
(192) |
Mar
(255) |
Apr
(99) |
May
(142) |
Jun
(111) |
Jul
(84) |
Aug
(102) |
Sep
(70) |
Oct
(152) |
Nov
(114) |
Dec
(53) |
2010 |
Jan
(71) |
Feb
(134) |
Mar
(50) |
Apr
(168) |
May
(123) |
Jun
(44) |
Jul
(99) |
Aug
(85) |
Sep
(126) |
Oct
(160) |
Nov
(85) |
Dec
(80) |
2011 |
Jan
(41) |
Feb
(14) |
Mar
(22) |
Apr
(5) |
May
(1) |
Jun
(5) |
Jul
(41) |
Aug
(64) |
Sep
(63) |
Oct
(112) |
Nov
(54) |
Dec
(3) |
2012 |
Jan
(33) |
Feb
(32) |
Mar
(25) |
Apr
(31) |
May
(49) |
Jun
(17) |
Jul
(46) |
Aug
(54) |
Sep
(79) |
Oct
(34) |
Nov
(9) |
Dec
(103) |
2013 |
Jan
(6) |
Feb
(22) |
Mar
(50) |
Apr
(62) |
May
(61) |
Jun
(43) |
Jul
(27) |
Aug
(7) |
Sep
(33) |
Oct
(40) |
Nov
(62) |
Dec
(13) |
2014 |
Jan
(33) |
Feb
(23) |
Mar
(13) |
Apr
|
May
|
Jun
(87) |
Jul
(25) |
Aug
(10) |
Sep
(7) |
Oct
|
Nov
|
Dec
(12) |
2015 |
Jan
|
Feb
|
Mar
(5) |
Apr
(2) |
May
(12) |
Jun
|
Jul
|
Aug
|
Sep
(4) |
Oct
(1) |
Nov
(1) |
Dec
|
2016 |
Jan
(3) |
Feb
|
Mar
(2) |
Apr
(14) |
May
(4) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(6) |
Nov
(10) |
Dec
(3) |
2017 |
Jan
(3) |
Feb
|
Mar
|
Apr
|
May
|
Jun
(3) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2019 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(33) |
Nov
(5) |
Dec
|
2020 |
Jan
|
Feb
|
Mar
(43) |
Apr
(41) |
May
(70) |
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
From: <swa...@us...> - 2020-10-05 22:15:10
|
Revision: 9454 http://sourceforge.net/p/vassalengine/svn/9454 Author: swampwallaby Date: 2020-10-05 22:15:09 +0000 (Mon, 05 Oct 2020) Log Message: ----------- For Vassal 3.4 Compatibility Added Paths: ----------- VSQL-src-8554/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <swa...@us...> - 2020-06-07 22:45:03
|
Revision: 9453 http://sourceforge.net/p/vassalengine/svn/9453 Author: swampwallaby Date: 2020-06-07 22:45:00 +0000 (Sun, 07 Jun 2020) Log Message: ----------- Beach Fixes Attack Wizard fixes Modified Paths: -------------- VSQL-src/trunk/tdc/AttackWizard.java VSQL-src/trunk/tdc/CommandRangeChecker.java VSQL-src/trunk/tdc/TdcBasicPiece.java VSQL-src/trunk/tdc/TdcCounterDetailViewer.java VSQL-src/trunk/tdc/TdcProperties.java VSQL-src/trunk/tdc/TdcScenarioOptions.java VSQL-src/trunk/tdc/TdcWizard.java VSQL-src/trunk/tdc/UnitInfo.java VSQL-src/trunk/tdc/attack/AttackModel.java VSQL-src/trunk/tdc/attack/AttackView.java VSQL-src/trunk/tdc/attack/FireModifier.java Modified: VSQL-src/trunk/tdc/AttackWizard.java =================================================================== --- VSQL-src/trunk/tdc/AttackWizard.java 2020-05-31 19:19:07 UTC (rev 9452) +++ VSQL-src/trunk/tdc/AttackWizard.java 2020-06-07 22:45:00 UTC (rev 9453) @@ -433,6 +433,8 @@ if (targetPieces.size() > 0) { buildDialog(rangeToTarget); myDialog.setVisible(true); + // Send focus back to Main Frame + GameModule.getGameModule().getFrame().requestFocus(); } } Modified: VSQL-src/trunk/tdc/CommandRangeChecker.java =================================================================== --- VSQL-src/trunk/tdc/CommandRangeChecker.java 2020-05-31 19:19:07 UTC (rev 9452) +++ VSQL-src/trunk/tdc/CommandRangeChecker.java 2020-06-07 22:45:00 UTC (rev 9453) @@ -23,8 +23,8 @@ import java.awt.Point; import java.util.ArrayList; +import java.util.Iterator; -import terrain.TerrainBasicPiece; import VASSAL.build.GameModule; import VASSAL.build.module.Map; import VASSAL.build.module.map.boardPicker.Board; @@ -38,6 +38,7 @@ import VASSAL.counters.Properties; import VASSAL.counters.PropertiesPieceFilter; import VASSAL.counters.Stack; +import terrain.TerrainBasicPiece; /** * Checks command ranges and finds leaders. @@ -254,7 +255,7 @@ final String op = (String) TdcMap.getTerrainProperty(piece, TdcProperties.OP); return "true".equals(op) || "true".equals(strongpoint) || TdcProperties.CITY.equals(terrain) || TdcProperties.TOWN.equals(terrain) || TdcProperties.FORTIFIED.equals(terrain); } - // In D-DAY, Units of some Divisions can have telephone capability + // In GJS, Units of some Divisions can have telephone capability // Note, German Leaders do not need to be in any special terrain to have Telephone capability else if (TdcProperties.DIVISION_716.equals(division) || TdcProperties.DIVISION_352.equals(division)) { // Unit must have Telephone capability @@ -273,32 +274,44 @@ return true; } - // The following does not apply in D-DAY - // Leaders must be in appropriate terrain or stacked with another - // telephone unit. - // Town, City or Fortified Hex -// final String terrain = (String) TdcMap.getTerrainProperty(piece, TerrainBasicPiece.CURRENT_TERRAIN); -// if (TdcProperties.CITY.equals(terrain) || TdcProperties.TOWN.equals(terrain) || TdcProperties.FORTIFIED.equals(terrain)) { -// return true; -// } -// -// final Stack stack = piece.getParent(); -// for (Iterator<GamePiece> i = stack.getPiecesIterator(); i.hasNext();) { -// final GamePiece p = i.next(); -// if (!TdcProperties.LEADER.equals(p.getProperty(TdcProperties.TYPE))) { -// if (division.equals(p.getProperty(TdcProperties.DIVISION))) { -// if ("true".equals(p.getProperty(TdcProperties.HAS_TELEPHONE))) { -// if (!"2".equals(piece.getProperty(TdcProperties.LAYER_TELEPHONE + "_Level"))) { -// return true; -// } -// } -// } -// } -// } -// return false; - return true; } + // In Utah: + // Only units of the 709 Division with a Telephone symbol have Telephone Capability, as long as lines are not cut. + // Only Leader Oberst Keil has Telephone, but only if stacked with another unit with Telephone Capability. + else if (TdcProperties.DIVISION_709.equals(division)) { + // Unit must have Telephone capability + if (!hasTelephone) { + return false; + } + // Check if Telephone has been cut + final boolean isTelephoneCut = "2".equals(piece.getProperty(TdcProperties.LAYER_TELEPHONE + "_Level")); + if (isTelephoneCut) { + return false; + } + + // Non-leader with telephone not cut has telephone regardless of terrain + if (!isLeader) { + return true; + } + + + final Stack stack = piece.getParent(); + for (Iterator<GamePiece> i = stack.getPiecesIterator(); i.hasNext();) { + final GamePiece p = i.next(); + if (!TdcProperties.LEADER.equals(p.getProperty(TdcProperties.TYPE))) { + if (division.equals(p.getProperty(TdcProperties.DIVISION))) { + if ("true".equals(p.getProperty(TdcProperties.HAS_TELEPHONE))) { + if (!"2".equals(p.getProperty(TdcProperties.LAYER_TELEPHONE + "_Level"))) { + return true; + } + } + } + } + } + return false; + } + return false; } Modified: VSQL-src/trunk/tdc/TdcBasicPiece.java =================================================================== --- VSQL-src/trunk/tdc/TdcBasicPiece.java 2020-05-31 19:19:07 UTC (rev 9452) +++ VSQL-src/trunk/tdc/TdcBasicPiece.java 2020-06-07 22:45:00 UTC (rev 9453) @@ -21,7 +21,7 @@ import terrain.TerrainBasicPiece; /** - * A subclass of TerrainbasicPiece that adjusted Current Terrain of Beach hexes + * A subclass of TerrainbasicPiece that adjusted Current Terrain of Beach hexes */ public class TdcBasicPiece extends TerrainBasicPiece { @@ -33,7 +33,7 @@ public TdcBasicPiece(String type) { super(type); } - + public Object getProperty(Object key) { if (CURRENT_TERRAIN.equals(key)) { final String terrain = (String) super.getProperty(key); // Base terrain @@ -40,20 +40,28 @@ final String overlay = (String) super.getProperty(TdcProperties.OVERLAY); // Is hex on an overlay? final boolean isBeach = "true".equals(super.getProperty(TdcProperties.TERRAIN_BEACH)); // Is it an overlay beach hex? if (isBeach) { - final String overlay_level = (String) super.getProperty("Overlay-"+overlay); - if ("2".equals(overlay_level)) { // Is overlay active? - return TdcProperties.TERRAIN_BEACH; // Convert to Beach terrain + if (overlay.startsWith("Utah")) { + final String overlay_level = (String) super.getProperty("Overlay-Utah"); + if (("2".equals(overlay_level) && "Utah-pl".equals(overlay)) || ("3".equals(overlay_level) && "Utah-act".equals(overlay))) { // Is overlay active? + return TdcProperties.TERRAIN_BEACH; // Convert to Beach terrain + } } + else { + final String overlay_level = (String) super.getProperty("Overlay-" + overlay); + if ("2".equals(overlay_level)) { // Is overlay active? + return TdcProperties.TERRAIN_BEACH; // Convert to Beach terrain + } + } } return terrain; } - return super.getProperty(key); + return super.getProperty(key); } - - public Object getLocalizedProperty(Object key) { + + public Object getLocalizedProperty(Object key) { if (CURRENT_TERRAIN.equals(key)) { return getProperty(key); } - return super.getLocalizedProperty(key); + return super.getLocalizedProperty(key); } } \ No newline at end of file Modified: VSQL-src/trunk/tdc/TdcCounterDetailViewer.java =================================================================== --- VSQL-src/trunk/tdc/TdcCounterDetailViewer.java 2020-05-31 19:19:07 UTC (rev 9452) +++ VSQL-src/trunk/tdc/TdcCounterDetailViewer.java 2020-06-07 22:45:00 UTC (rev 9453) @@ -626,10 +626,18 @@ final String overlay = (String) hgrid.getProperty(TdcProperties.OVERLAY, snapPt); // Is hex on an overlay? final boolean isBeach = "true".equals(hgrid.getProperty(TdcProperties.TERRAIN_BEACH, snapPt)); // Is it an overlay beach hex? if (isBeach) { - final String overlay_level = (String) GameModule.getGameModule().getProperty("Overlay-" + overlay); - if ("2".equals(overlay_level)) { // Is overlay active? - terrain = TdcProperties.TERRAIN_BEACH; // Convert to Beach terrain + if (overlay.startsWith("Utah")) { + final String overlay_level = (String) GameModule.getGameModule().getProperty("Overlay-Utah"); + if (("2".equals(overlay_level) && "Utah-pl".equals(overlay)) || ("3".equals(overlay_level) && "Utah-act".equals(overlay))) { // Is overlay active? + terrain = TdcProperties.TERRAIN_BEACH; // Convert to Beach terrain + } } + else { + final String overlay_level = (String) GameModule.getGameModule().getProperty("Overlay-" + overlay); + if ("2".equals(overlay_level)) { // Is overlay active? + terrain = TdcProperties.TERRAIN_BEACH; // Convert to Beach terrain + } + } } final String basicTerrain = terrain; Modified: VSQL-src/trunk/tdc/TdcProperties.java =================================================================== --- VSQL-src/trunk/tdc/TdcProperties.java 2020-05-31 19:19:07 UTC (rev 9452) +++ VSQL-src/trunk/tdc/TdcProperties.java 2020-06-07 22:45:00 UTC (rev 9453) @@ -118,6 +118,7 @@ public static final String DIVISION_352 = "352"; public static final String DIVISION_CDO = "cdo"; public static final String DIVISION_NAVAL = "Naval"; + public static final String DIVISION_709 = "709"; public static final String FORMATION_POLISH = "Polish Para Brigade"; public static final String FORMATION_HARDER = "KG Harder"; @@ -140,7 +141,13 @@ public static final String RULES_TINIAN = "TINIAN"; public static final String RULES_CRETE = "CRETE"; public static final String RULES_AMD = "AMD"; - + + public static final String SUB_RULESET = "SubRuleset"; + public static final String RULES_GJS = "1"; + public static final String RULES_UTAH = "2"; + public static final String RULES_OMAHA = "3"; + public static final String RULES_COMBINED = "4"; + public static final String SDZ_1AB = "SDZ-1AB"; public static final String SDZ_52AL = "SDZ-52AL"; public static final String SDZ_82AB = "SDZ-82AB"; Modified: VSQL-src/trunk/tdc/TdcScenarioOptions.java =================================================================== --- VSQL-src/trunk/tdc/TdcScenarioOptions.java 2020-05-31 19:19:07 UTC (rev 9452) +++ VSQL-src/trunk/tdc/TdcScenarioOptions.java 2020-06-07 22:45:00 UTC (rev 9453) @@ -79,6 +79,8 @@ protected BooleanOption creteDivfjr1; protected BooleanOption creteDivfjr2; + protected StringEnumOption subRuleSet; + public TdcScenarioOptions() { super(); } @@ -164,14 +166,20 @@ ddBox.add(telephoneCommand736.getControls()); ddBox.add(new JLabel(" ")); - attach_22arm = new AttachOption("Attach-22Arm", "22 Arm Brigade are attached to division ", new String[] { TdcProperties.DIVISION_7TH, TdcProperties.DIVISION_50TH }, "7th-v-50th"); + attach_22arm = new AttachOption("Attach-22Arm", "22 Arm Brigade are attached to division: ", new String[] { TdcProperties.DIVISION_7TH, TdcProperties.DIVISION_50TH }, "7th-v-50th"); ddBox.add(attach_22arm.getControls()); optionBox.add(ddBox); - add10toSwordNavalRange = new BooleanOption(TdcProperties.ADD_10_TO_SWORD_NAVAL_RANGE, "+10 hexes to naval Range?"); + add10toSwordNavalRange = new BooleanOption(TdcProperties.ADD_10_TO_SWORD_NAVAL_RANGE, "+10 hexes to Sword Naval Range?"); ddBox.add(add10toSwordNavalRange.getControls()); ddBox.add(new JLabel(" ")); + + + subRuleSet = new StringEnumOption (TdcProperties.SUB_RULESET, "The Greatest Day Rule Subset (1=GJS, 2=Utah, 3=Omaha, 4=Combined): ", new String[] {TdcProperties.RULES_GJS, TdcProperties.RULES_UTAH, TdcProperties.RULES_OMAHA, TdcProperties.RULES_COMBINED}); + ddBox.add(subRuleSet.getControls()); + ddBox.add(new JLabel(" ")); + optionBox.add(ddBox); } Modified: VSQL-src/trunk/tdc/TdcWizard.java =================================================================== --- VSQL-src/trunk/tdc/TdcWizard.java 2020-05-31 19:19:07 UTC (rev 9452) +++ VSQL-src/trunk/tdc/TdcWizard.java 2020-06-07 22:45:00 UTC (rev 9453) @@ -182,7 +182,8 @@ final String dd = (String) getProperty(TdcProperties.DD); - final String overlay = (String) getProperty(TdcProperties.OVERLAY); + String overlay = (String) getProperty(TdcProperties.OVERLAY); + if (overlay != null && overlay.startsWith("Utah-")) overlay = "Utah"; final GameModule gm = GameModule.getGameModule(); final boolean nestsRemaining = !"0".equals(gm.getProperty(overlay + "-Nests")); final boolean obstaclesRemaining = !"0".equals(gm.getProperty(overlay + "-Obstacles")); Modified: VSQL-src/trunk/tdc/UnitInfo.java =================================================================== --- VSQL-src/trunk/tdc/UnitInfo.java 2020-05-31 19:19:07 UTC (rev 9452) +++ VSQL-src/trunk/tdc/UnitInfo.java 2020-06-07 22:45:00 UTC (rev 9453) @@ -1172,12 +1172,12 @@ boolean sourceSeen = false; boolean finished = false; boolean landingCraftSeen = false; - + for (Iterator<GamePiece> i = parent.getPiecesIterator(); i.hasNext();) { final GamePiece piece = i.next(); final String type = (String) piece.getProperty(TdcProperties.TYPE); final String unitClass = (String) piece.getProperty(TdcProperties.CLASS); - + // Check for Barrage Counter if (TdcProperties.TYPE_BARRAGE.equals(type)) { final String barrageLevel = (String) piece.getProperty("Barrage_Level"); @@ -1219,12 +1219,13 @@ thisMass += TRUE.equals(active) ? 1 : 2; } } + if (!landingCraftSeen && TdcProperties.CLASS_LANDING_CRAFT.equals(unitClass)) { landingCraftSeen = true; } // If the counter is a landing craft and we have seen a landing craft in - // the stack, the add the mass + // the stack, the add the mass, as the Landing Craft is below us!!!! // ie. This stack item is the landing craft or above it. if (isLandingCraft()) { if (landingCraftSeen) { @@ -1232,9 +1233,9 @@ } } // Our counter is not a landing craft, so we ignore the mass any landing - // craft in the stack + // craft in the stack above us else { - if (!TdcProperties.CLASS_LANDING_CRAFT.equals(unitClass)) { + if (!TdcProperties.CLASS_LANDING_CRAFT.equals(unitClass) || ! landingCraftSeen) { mass += thisMass; } } Modified: VSQL-src/trunk/tdc/attack/AttackModel.java =================================================================== --- VSQL-src/trunk/tdc/attack/AttackModel.java 2020-05-31 19:19:07 UTC (rev 9452) +++ VSQL-src/trunk/tdc/attack/AttackModel.java 2020-06-07 22:45:00 UTC (rev 9453) @@ -97,7 +97,7 @@ else { sourceInfo = new UnitInfo(source, true); } - + determineMode(); selectTarget(0); determineMode(); @@ -147,8 +147,7 @@ // a) The source and target units are both Artillery // b) The source and target units are on different maps to each other // c) Neither the source or target units are on the main map - isCounterBatteryFire = sourceInfo.isArtillery() && targetInfo.isArtillery() && sourceInfo.getUnit().getMap() != targetInfo.getUnit().getMap() - && !TdcMap.isOnMainMap(sourceInfo.getUnit()) && !TdcMap.isOnMainMap(targetInfo.getUnit()); + isCounterBatteryFire = sourceInfo.isArtillery() && targetInfo.isArtillery() && sourceInfo.getUnit().getMap() != targetInfo.getUnit().getMap() && !TdcMap.isOnMainMap(sourceInfo.getUnit()) && !TdcMap.isOnMainMap(targetInfo.getUnit()); } change(); } @@ -209,35 +208,34 @@ return sourceInfo.isPartisanAttack(); } - - public static int[] xOffsets = new int[] {0, 100, 100, 0, -100, -100}; - public static int[] yOffsets = new int[] {-100, -50, 50, 100, -50, 50}; - + public static int[] xOffsets = new int[] { 0, 100, 100, 0, -100, -100 }; + public static int[] yOffsets = new int[] { -100, -50, 50, 100, -50, 50 }; + public int getAirDefenceRating() { airDefenceRating = 0; airDefenceDescription = ""; // Determine the best Air Defence terrain in the targets current and surrounding hexes - if (isAirPower()) { + if (isAirPower()) { final Map targetMap = target.getMap(); if (targetMap != null && targetMap instanceof TdcMap) { - final TdcMap tdcMap = (TdcMap) targetMap; + final TdcMap tdcMap = (TdcMap) targetMap; final Point targetPos = target.getPosition(); checkAirDefenceTerrain(tdcMap.getTerrainName(targetPos)); for (int i = 0; i < xOffsets.length; i++) { - final Point testPos = new Point (targetPos.x + xOffsets[i], targetPos.y + yOffsets[i]); + final Point testPos = new Point(targetPos.x + xOffsets[i], targetPos.y + yOffsets[i]); final String terrain = tdcMap.getTerrainName(testPos); checkAirDefenceTerrain(terrain); } - } - } + } + } return airDefenceRating; } - - protected void checkAirDefenceTerrain (String terrain) { + + protected void checkAirDefenceTerrain(String terrain) { int modifier = 0; if (TdcProperties.TERRAIN_FORTIFIED.equals(terrain)) { - modifier = 5; + modifier = 5; } else if (TdcProperties.TERRAIN_CITY.equals(terrain)) { modifier = 4; @@ -250,11 +248,11 @@ airDefenceDescription = terrain; } } - - public String getAirDefenceDescription () { + + public String getAirDefenceDescription() { return airDefenceDescription; } - + public boolean isAirDefence() { return targetInfo == null ? false : targetInfo.isAirPower(); } @@ -288,12 +286,12 @@ } public int getFireRating() { - if (curRating < 0) - return 0; - if (curRating > 9) - return 9; - return curRating; - } + if (curRating < 0) + return 0; + if (curRating > 9) + return 9; + return curRating; + } public int getAttackModifierTotal() { return attackModifierTotal; @@ -409,10 +407,10 @@ public boolean isModeIndirect() { return mode == MODE_INDIRECT; } - + protected void update() { String r; - + if (isAirDefence()) { r = sourceInfo.getBaseRatings().get(TdcRatings.FLAK_RATING); } @@ -419,7 +417,7 @@ else { r = sourceInfo.getBaseRatings().get(TdcRatings.FIRE_RATING); } - + if ("No".equals(r)) { curRating = -99; } @@ -498,18 +496,17 @@ } public List<String> getReportText() { - + final ArrayList<String> text = new ArrayList<String>(); if (isAirDefence()) { - text.add(sourceInfo.getArmy() + " unit " + source.getName() + " [" + source.getProperty(BasicPiece.LOCATION_NAME) + "] attacks " + targetInfo.getArmy() - + " Fighter Bomber [" + target.getProperty(BasicPiece.LOCATION_NAME) + "]"); + text.add(sourceInfo.getArmy() + " unit " + source.getName() + " [" + source.getProperty(BasicPiece.LOCATION_NAME) + "] attacks " + targetInfo.getArmy() + " Fighter Bomber [" + target.getProperty(BasicPiece.LOCATION_NAME) + "]"); text.add("Range: " + range + "/8"); - text.add( "Fire Rating " + getFireRating() + " [No modifiers]"); + text.add("Fire Rating " + getFireRating() + " [No modifiers]"); } else if (specialAttackType == AttackWizard.NO_SPECIAL_ATTACK) { - text.add(sourceInfo.getArmy() + " unit " + source.getName() + " [" + source.getProperty(BasicPiece.LOCATION_NAME) + "] attacks " + targetInfo.getArmy() - + " unit " + target.getName() + " [" + target.getProperty(BasicPiece.LOCATION_NAME) + "]"); + text.add(sourceInfo.getArmy() + " unit " + source.getName() + " [" + source.getProperty(BasicPiece.LOCATION_NAME) + "] attacks " + targetInfo.getArmy() + " unit " + target.getName() + " [" + + target.getProperty(BasicPiece.LOCATION_NAME) + "]"); if (isCounterBatteryFire) { text.add(COUNTER_BATTERY_FIRE); } @@ -517,8 +514,7 @@ text.add("Range: " + range + "/*"); } else { - text.add("Range " + range + "/" + sourceInfo.getEffectiveRange() - + (sourceInfo.getRangeDetails().length() > 0 ? " (" + sourceInfo.getRangeDetails() + ")" : "")); + text.add("Range " + range + "/" + sourceInfo.getEffectiveRange() + (sourceInfo.getRangeDetails().length() > 0 ? " (" + sourceInfo.getRangeDetails() + ")" : "")); if (range > sourceInfo.getEffectiveRange()) { text.add("*** OUT OF RANGE ***"); } @@ -660,8 +656,7 @@ } if ((!info.isInColumn() && terrainModifier != 0) || terrainModifier > 0) { - addDefenceModifier(new FireModifier(terrainInfo.getTerrainPrintable() - + (UnitInfo.isTgdRules() ? " ( " + targetInfos.get(i).getArmourString() + ")" : ""), terrainModifier, targets.get(i))); + addDefenceModifier(new FireModifier(terrainInfo.getTerrainPrintable() + (UnitInfo.isTgdRules() ? " ( " + targetInfos.get(i).getArmourString() + ")" : ""), terrainModifier, targets.get(i))); } int rangeBonus = 0; @@ -717,72 +712,78 @@ for (FireModifier mod : info.getDefenceModifiers()) { if ((mod.getOwner() == null && i == 0) || mod.getOwner() != null) { - addDefenceModifier(mod); + addDefenceModifier(mod); } } - } - final int mass = targetInfo.getMass(); - int massBonus = 0; - String massDesc = ""; + final int mass = targetInfos.get(i).getMass(); + int massBonus = 0; + String massDesc = ""; - if (UnitInfo.isGTS2Rules() ) { - if (mass >= 8) { - massBonus = 3; - massDesc = "8+"; + if (UnitInfo.isGTS2Rules()) { + if (mass >= 8) { + massBonus = 3; + massDesc = "8+"; + } + else if (mass >= 6) { + massBonus = 2; + massDesc = "6-7"; + } + else if (mass >= 4) { + massBonus = 1; + massDesc = "4-5"; + } + else if (mass == 0) { + massBonus = -1; + massDesc = "0"; + } } - else if (mass >= 6) { - massBonus = 2; - massDesc = "6-7"; + else { + if (mass >= 9) { + massBonus = 3; + massDesc = "9+"; + } + else if (mass >= 7) { + massBonus = 2; + massDesc = "7-8"; + } + else if (mass >= 5) { + massBonus = 1; + massDesc = "5-6"; + } } - else if (mass >= 4) { - massBonus = 1; - massDesc = "4-5"; + if (massBonus != 0) { + addDefenceModifier(new FireModifier("Mass " + massDesc + " steps", massBonus, FireModifier.BASIC, true, true, true, this, targets.get(i))); } - else if (mass == 0) { - massBonus = -1; - massDesc = "0"; + // Yucko, but need to do this to keep the order the same now that non-adj Ridge option + // if (i == targets.size()-1) { + defenceModifier = new FireModifier("Base Defence Rating", targetInfos.get(i).getDefenceRating(), FireModifier.BASIC, true, true, true, this, targets.get(i)); + addDefenceModifier(defenceModifier); + + //} + + if (!isSpecialAttack() && !isAirPower()) { + addDefenceModifier(new FireModifier("LOS crosses non-adj Ridge", (targetInfos.get(i).isArmoured() ? -2 : -1), FireModifier.ONOFF, true, false, true, this, targets.get(i))); } + } - else { - if (mass >= 9) { - massBonus = 3; - massDesc = "9+"; - } - else if (mass >= 7) { - massBonus = 2; - massDesc = "7-8"; - } - else if (mass >= 5) { - massBonus = 1; - massDesc = "5-6"; - } - } - if (massBonus != 0) { - addDefenceModifier(new FireModifier("Mass " + massDesc + " steps", massBonus, FireModifier.BASIC, true, true, true, this)); - } - - defenceModifier = new FireModifier("Base Defence Rating", targetInfo.getDefenceRating(), FireModifier.BASIC, true, true, true); - addDefenceModifier(defenceModifier); final int fz_to_fz_modifier = UnitInfo.isGTS2Rules() ? 2 : 3; addDefenceModifier(new FireModifier(FZ_TO_FZ, fz_to_fz_modifier, FireModifier.ONOFF, false, false, true, this)); addDefenceModifier(new FireModifier(FZ_TO_NON_FZ, -1, FireModifier.ONOFF, false, false, true, this)); addDefenceModifier(new FireModifier("Running from Assault", 2, FireModifier.ONOFF, false, false, true, this)); - if (!isSpecialAttack() && !isAirPower()) { - addDefenceModifier(new FireModifier("LOS crosses non-adj Ridge", (targetInfo.isArmoured() ? -2 : -1), FireModifier.ONOFF, true, false, true, this)); - } + } return defenceModifiers; } protected void addAttackModifier(FireModifier modifier) { - if (! isIgnoreAllModifiers() && (!isIgnoreNegativeModifiers() || modifier.getValue() >= 0)) { + if (!isIgnoreAllModifiers() && (!isIgnoreNegativeModifiers() || modifier.getValue() >= 0)) { attackModifiers.add(modifier); } } protected void addDefenceModifier(FireModifier modifier) { - if (! isIgnoreAllModifiers() && (!isIgnoreNegativeModifiers() || modifier.getValue() >= 0)) { + if (!isIgnoreAllModifiers() && (!isIgnoreNegativeModifiers() || modifier.getValue() >= 0)) { defenceModifiers.add(modifier); } } Modified: VSQL-src/trunk/tdc/attack/AttackView.java =================================================================== --- VSQL-src/trunk/tdc/attack/AttackView.java 2020-05-31 19:19:07 UTC (rev 9452) +++ VSQL-src/trunk/tdc/attack/AttackView.java 2020-06-07 22:45:00 UTC (rev 9453) @@ -31,15 +31,15 @@ import javax.swing.JLabel; import javax.swing.JPanel; -import net.miginfocom.swing.MigLayout; -import tdc.AttackWizard; -import tdc.AttackWizard.WizardTargetCommand; -import tdc.UnitInfo; import VASSAL.build.GameModule; import VASSAL.command.Command; import VASSAL.counters.GamePiece; import VASSAL.tools.imageop.Op; import VASSAL.tools.imageop.OpIcon; +import net.miginfocom.swing.MigLayout; +import tdc.AttackWizard; +import tdc.AttackWizard.WizardTargetCommand; +import tdc.UnitInfo; public class AttackView { protected static Font boldFont; Modified: VSQL-src/trunk/tdc/attack/FireModifier.java =================================================================== --- VSQL-src/trunk/tdc/attack/FireModifier.java 2020-05-31 19:19:07 UTC (rev 9452) +++ VSQL-src/trunk/tdc/attack/FireModifier.java 2020-06-07 22:45:00 UTC (rev 9453) @@ -106,6 +106,11 @@ this.owner = owner; } + public FireModifier(String description, int value, int type, boolean dir, boolean ind, boolean opp, AttackModel model, GamePiece owner) { + this(description, value, type, dir, ind, opp, model); + this.owner = owner; + } + public FireModifier(String description, int value, int type, boolean dir, boolean ind, boolean opp, AttackModel model) { this.description = description; this.modifier = value; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uck...@us...> - 2020-05-31 19:19:08
|
Revision: 9452 http://sourceforge.net/p/vassalengine/svn/9452 Author: uckelman Date: 2020-05-31 19:19:07 +0000 (Sun, 31 May 2020) Log Message: ----------- Bug 12825: SocketHander now sends an empty message to keep the connection alive 2 minutes after the previous message was sent. Modified Paths: -------------- VASSAL-src/trunk/src/VASSAL/chat/node/SocketHandler.java Modified: VASSAL-src/trunk/src/VASSAL/chat/node/SocketHandler.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/node/SocketHandler.java 2020-05-27 21:38:48 UTC (rev 9451) +++ VASSAL-src/trunk/src/VASSAL/chat/node/SocketHandler.java 2020-05-31 19:19:07 UTC (rev 9452) @@ -28,6 +28,7 @@ import java.nio.charset.StandardCharsets; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; public class SocketHandler { private Socket sock; @@ -36,8 +37,8 @@ private BufferedWriter writer; private BlockingQueue<String> writeQueue = new LinkedBlockingQueue<>(); private boolean isOpen = true; - private Thread readThread; - private Thread writeThread; + private Thread readThread = null; + private Thread writeThread = null; private static final String SIGN_OFF = "!BYE"; //$NON-NLS-1$ @@ -63,7 +64,7 @@ public void run() { String line; try { - while ((line = readNext()) != null) { + while ((line = reader.readLine()) != null) { if (SIGN_OFF.equals(line)) { break; } @@ -71,8 +72,8 @@ try { handler.handleMessage(line); } - // FIXME: review error message catch (Exception e) { + // FIXME: review error message // Handler threw an exception. Keep reading. System.err.println("Caught " + e.getClass().getName() + " handling " + line); //$NON-NLS-1$ //$NON-NLS-2$ e.printStackTrace(); @@ -104,10 +105,27 @@ String line; try { while (true) { - if ((line = getLine()) != null) { + try { + line = writeQueue.poll(2, TimeUnit.MINUTES); + } + catch (InterruptedException e) { + // FIXME: should we really ignore this?! + e.printStackTrace(); + continue; + } + + if (line != null) { + // send the message we took off the queue writeNext(line); - if (SIGN_OFF.equals(line)) break; + if (SIGN_OFF.equals(line)) { + break; + } } + else { + // send a keep-alive, since we timed out + writeLine(""); + System.err.println("Sent keep-alive"); + } } } catch (IOException ignore) { @@ -127,10 +145,6 @@ return t; } - private String readNext() throws IOException { - return reader.readLine(); - } - private void writeNext(String line) throws IOException { writer.write(line + '\n'); writer.flush(); @@ -141,24 +155,19 @@ writeQueue.put(pMessage); } catch (InterruptedException e) { + // The queue can have Integer.MAX_VALUE elements, so if put() ever + // blocks and gets interrupted, everything is hosed anyway so it + // doesn't matter what we do here. e.printStackTrace(); } } - private String getLine() { - try { - return writeQueue.take(); - } - catch (InterruptedException e) { - e.printStackTrace(); - return null; - } - } - public void close() { writeLine(SIGN_OFF); } + // FIXME: stream closing is probalby totally broken + // FIXME: nothing stops the threads private void closeStreams() throws IOException { writer.close(); reader.close(); @@ -169,14 +178,14 @@ try { closeStreams(); } - // FIXME: review error message catch (IOException ignore) { + // FIXME: review error message } try { sock.close(); } - // FIXME: review error message catch (IOException ignore) { + // FIXME: review error message } close(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uck...@us...> - 2020-05-27 21:38:50
|
Revision: 9451 http://sourceforge.net/p/vassalengine/svn/9451 Author: uckelman Date: 2020-05-27 21:38:48 +0000 (Wed, 27 May 2020) Log Message: ----------- Cleanup. Modified Paths: -------------- VASSAL-src/trunk/src/VASSAL/chat/node/NodeClient.java VASSAL-src/trunk/src/VASSAL/chat/node/ServerNode.java VASSAL-src/trunk/src/VASSAL/chat/node/SocketNodeClient.java Modified: VASSAL-src/trunk/src/VASSAL/chat/node/NodeClient.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/node/NodeClient.java 2020-05-27 21:38:42 UTC (rev 9450) +++ VASSAL-src/trunk/src/VASSAL/chat/node/NodeClient.java 2020-05-27 21:38:48 UTC (rev 9451) @@ -639,13 +639,14 @@ roomControls.uninitializeControls(controls); serverStatusControls.uninitializeControls(controls); playerStatusControls.uninitializeControls(controls); - GameModule.getGameModule().removeCommandEncoder(synchEncoder); - GameModule.getGameModule().removeCommandEncoder(privateChatEncoder); - GameModule.getGameModule().removeCommandEncoder(soundEncoder); - GameModule.getGameModule().removeCommandEncoder(inviteEncoder); - GameModule.getGameModule().getPrefs().getOption(GameModule.REAL_NAME) - .removePropertyChangeListener(nameChangeListener); - GameModule.getGameModule().getPrefs().getOption(GameModule.PERSONAL_INFO) - .removePropertyChangeListener(profileChangeListener); + final GameModule g = GameModule.getGameModule(); + g.removeCommandEncoder(synchEncoder); + g.removeCommandEncoder(privateChatEncoder); + g.removeCommandEncoder(soundEncoder); + g.removeCommandEncoder(inviteEncoder); + g.getPrefs().getOption(GameModule.REAL_NAME) + .removePropertyChangeListener(nameChangeListener); + g.getPrefs().getOption(GameModule.PERSONAL_INFO) + .removePropertyChangeListener(profileChangeListener); } } Modified: VASSAL-src/trunk/src/VASSAL/chat/node/ServerNode.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/node/ServerNode.java 2020-05-27 21:38:42 UTC (rev 9450) +++ VASSAL-src/trunk/src/VASSAL/chat/node/ServerNode.java 2020-05-27 21:38:48 UTC (rev 9451) @@ -186,6 +186,7 @@ final Node defaultRoomNode = roomNode.getParent().getChildren()[0]; move(kickeeNode, defaultRoomNode.getPath()); } + private static class SendContentsTask extends TimerTask { // FIXME: should modules be wrapped by Collections.synchronizedMap()? private Set<Node> modules = new HashSet<>(); Modified: VASSAL-src/trunk/src/VASSAL/chat/node/SocketNodeClient.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/node/SocketNodeClient.java 2020-05-27 21:38:42 UTC (rev 9450) +++ VASSAL-src/trunk/src/VASSAL/chat/node/SocketNodeClient.java 2020-05-27 21:38:48 UTC (rev 9451) @@ -63,7 +63,6 @@ Socket s = new Socket(serverInfo.getHostName(), serverInfo.getPort()); sender = new SocketHandler(s, this); sender.start(); - } @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uck...@us...> - 2020-05-27 21:38:45
|
Revision: 9450 http://sourceforge.net/p/vassalengine/svn/9450 Author: uckelman Date: 2020-05-27 21:38:42 +0000 (Wed, 27 May 2020) Log Message: ----------- Cleanup. Modified Paths: -------------- VASSAL-src/trunk/src/VASSAL/chat/node/SocketHandler.java Modified: VASSAL-src/trunk/src/VASSAL/chat/node/SocketHandler.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/node/SocketHandler.java 2020-05-27 21:38:38 UTC (rev 9449) +++ VASSAL-src/trunk/src/VASSAL/chat/node/SocketHandler.java 2020-05-27 21:38:42 UTC (rev 9450) @@ -80,11 +80,13 @@ } } } - // FIXME: review error message catch (IOException ignore) { + // FIXME: review error message +/* String msg = ignore.getClass().getName(); msg = msg.substring(msg.lastIndexOf('.') + 1); -// System.err.println("Caught " + msg + "(" + ignore.getMessage() + ") reading socket."); + System.err.println("Caught " + msg + "(" + ignore.getMessage() + ") reading socket."); +*/ } closeSocket(); } @@ -108,11 +110,13 @@ } } } - // FIXME: review error message catch (IOException ignore) { + // FIXME: review error message +/* String msg = ignore.getClass().getName(); msg = msg.substring(msg.lastIndexOf('.') + 1); -// System.err.println("Caught " + msg + "(" + ignore.getMessage() + ") writing to socket."); + System.err.println("Caught " + msg + "(" + ignore.getMessage() + ") writing to socket."); +*/ } closeSocket(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uck...@us...> - 2020-05-27 21:38:40
|
Revision: 9449 http://sourceforge.net/p/vassalengine/svn/9449 Author: uckelman Date: 2020-05-27 21:38:38 +0000 (Wed, 27 May 2020) Log Message: ----------- Cleanup. Modified Paths: -------------- VASSAL-src/trunk/src/VASSAL/chat/node/SocketHandler.java Modified: VASSAL-src/trunk/src/VASSAL/chat/node/SocketHandler.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/node/SocketHandler.java 2020-05-27 21:38:33 UTC (rev 9448) +++ VASSAL-src/trunk/src/VASSAL/chat/node/SocketHandler.java 2020-05-27 21:38:38 UTC (rev 9449) @@ -58,7 +58,7 @@ } private Thread startReadThread() { - Runnable runnable = new Runnable() { + final Runnable r = new Runnable() { @Override public void run() { String line; @@ -89,13 +89,14 @@ closeSocket(); } }; - Thread t = new Thread(runnable, "read " + sock.getInetAddress()); + + final Thread t = new Thread(r, "read " + sock.getInetAddress()); t.start(); return t; } private Thread startWriteThread() { - Runnable runnable = new Runnable() { + final Runnable r = new Runnable() { @Override public void run() { String line; @@ -116,16 +117,12 @@ closeSocket(); } }; - Thread t = new Thread(runnable, "write " + sock.getInetAddress()); + + final Thread t = new Thread(r, "write " + sock.getInetAddress()); t.start(); return t; } - private void closeStreams() throws IOException { - writer.close(); - reader.close(); - } - private String readNext() throws IOException { return reader.readLine(); } @@ -144,10 +141,25 @@ } } + private String getLine() { + try { + return writeQueue.take(); + } + catch (InterruptedException e) { + e.printStackTrace(); + return null; + } + } + public void close() { writeLine(SIGN_OFF); } + private void closeStreams() throws IOException { + writer.close(); + reader.close(); + } + private synchronized void closeSocket() { if (isOpen) { try { @@ -169,17 +181,6 @@ } } - private String getLine() { - try { - return writeQueue.take(); - } - catch (InterruptedException e) { - e.printStackTrace(); - } - - return null; - } - public InetAddress getInetAddress() { return sock.getInetAddress(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uck...@us...> - 2020-05-27 21:38:35
|
Revision: 9448 http://sourceforge.net/p/vassalengine/svn/9448 Author: uckelman Date: 2020-05-27 21:38:33 +0000 (Wed, 27 May 2020) Log Message: ----------- Folded BufferedSocketHandler into SocketHandler. Modified Paths: -------------- VASSAL-src/trunk/src/VASSAL/chat/node/LockWatcher.java VASSAL-src/trunk/src/VASSAL/chat/node/PlayerNode.java VASSAL-src/trunk/src/VASSAL/chat/node/Server.java VASSAL-src/trunk/src/VASSAL/chat/node/SocketHandler.java VASSAL-src/trunk/src/VASSAL/chat/node/SocketNodeClient.java Removed Paths: ------------- VASSAL-src/trunk/src/VASSAL/chat/node/BufferedSocketHandler.java Deleted: VASSAL-src/trunk/src/VASSAL/chat/node/BufferedSocketHandler.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/node/BufferedSocketHandler.java 2020-05-27 21:38:26 UTC (rev 9447) +++ VASSAL-src/trunk/src/VASSAL/chat/node/BufferedSocketHandler.java 2020-05-27 21:38:33 UTC (rev 9448) @@ -1,54 +0,0 @@ -/* - * - * Copyright (c) 2000-2007 by Rodney Kinney - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License (LGPL) as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, copies are available - * at http://www.opensource.org. - */ -package VASSAL.chat.node; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.net.Socket; -import java.nio.charset.StandardCharsets; - -public class BufferedSocketHandler extends SocketHandler { - protected BufferedReader reader; - protected BufferedWriter writer; - - public BufferedSocketHandler(Socket sock, SocketWatcher handler) throws IOException { - super(sock, handler); - reader = new BufferedReader(new InputStreamReader(sock.getInputStream(), StandardCharsets.UTF_8)); //$NON-NLS-1$ - writer = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(), StandardCharsets.UTF_8)); //$NON-NLS-1$ - } - - @Override - protected void closeStreams() throws IOException { - writer.close(); - reader.close(); - } - - @Override - protected String readNext() throws IOException { - return reader.readLine(); - } - - @Override - protected void writeNext(String line) throws IOException { - writer.write(line+'\n'); - writer.flush(); - } -} Modified: VASSAL-src/trunk/src/VASSAL/chat/node/LockWatcher.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/node/LockWatcher.java 2020-05-27 21:38:26 UTC (rev 9447) +++ VASSAL-src/trunk/src/VASSAL/chat/node/LockWatcher.java 2020-05-27 21:38:33 UTC (rev 9448) @@ -68,7 +68,7 @@ System.err.println("Server closed socket"); //$NON-NLS-1$ } }; - SocketHandler sender = new BufferedSocketHandler(s, watcher); + SocketHandler sender = new SocketHandler(s, watcher); sender.start(); t.start(); sender.writeLine(Protocol.encodeRegisterCommand("pinger", "ping/Main", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ Modified: VASSAL-src/trunk/src/VASSAL/chat/node/PlayerNode.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/node/PlayerNode.java 2020-05-27 21:38:26 UTC (rev 9447) +++ VASSAL-src/trunk/src/VASSAL/chat/node/PlayerNode.java 2020-05-27 21:38:33 UTC (rev 9448) @@ -38,8 +38,8 @@ public PlayerNode(Socket socket, AsynchronousServerNode server) throws IOException { super(null,null,null); - this.server = server; - this.input = new BufferedSocketHandler(socket,this); + server = server; + input = new SocketHandler(socket, this); input.start(); } @@ -61,7 +61,7 @@ // Always update IP on client info in case client 'forgets' their IP @Override public String getInfo() { - String ip = input.sock.getInetAddress().getHostAddress(); + final String ip = input.getInetAddress().getHostAddress(); return info + (ip.length() > 0 ? "|ip=" + ip : ""); } Modified: VASSAL-src/trunk/src/VASSAL/chat/node/Server.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/node/Server.java 2020-05-27 21:38:26 UTC (rev 9447) +++ VASSAL-src/trunk/src/VASSAL/chat/node/Server.java 2020-05-27 21:38:33 UTC (rev 9448) @@ -71,7 +71,7 @@ } if (p.getProperty("test") != null) { //$NON-NLS-1$ Socket soc = new Socket("localHost", port); //$NON-NLS-1$ - SocketHandler handler = new BufferedSocketHandler(soc, new SocketWatcher() { + SocketHandler handler = new SocketHandler(soc, new SocketWatcher() { @Override public void handleMessage(String msg) { System.err.println(msg); @@ -98,7 +98,7 @@ } else if (line.startsWith("HELLO")) { //$NON-NLS-1$ soc = new Socket("localHost", port); //$NON-NLS-1$ - handler = new BufferedSocketHandler(soc, new SocketWatcher() { + handler = new SocketHandler(soc, new SocketWatcher() { @Override public void handleMessage(String msg) { System.err.println(msg); Modified: VASSAL-src/trunk/src/VASSAL/chat/node/SocketHandler.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/node/SocketHandler.java 2020-05-27 21:38:26 UTC (rev 9447) +++ VASSAL-src/trunk/src/VASSAL/chat/node/SocketHandler.java 2020-05-27 21:38:33 UTC (rev 9448) @@ -18,23 +18,34 @@ */ package VASSAL.chat.node; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.InputStreamReader; import java.io.IOException; +import java.io.OutputStreamWriter; +import java.net.InetAddress; import java.net.Socket; +import java.nio.charset.StandardCharsets; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; -public abstract class SocketHandler { - protected Socket sock; - protected SocketWatcher handler; +public class SocketHandler { + private Socket sock; + private SocketWatcher handler; + private BufferedReader reader; + private BufferedWriter writer; private BlockingQueue<String> writeQueue = new LinkedBlockingQueue<>(); private boolean isOpen = true; private Thread readThread; private Thread writeThread; + private static final String SIGN_OFF = "!BYE"; //$NON-NLS-1$ public SocketHandler(Socket sock, SocketWatcher handler) throws IOException { this.sock = sock; this.handler = handler; + reader = new BufferedReader(new InputStreamReader(sock.getInputStream(), StandardCharsets.UTF_8)); + writer = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(), StandardCharsets.UTF_8)); } public void start() { @@ -110,11 +121,19 @@ return t; } - protected abstract void closeStreams() throws IOException; + private void closeStreams() throws IOException { + writer.close(); + reader.close(); + } - protected abstract String readNext() throws IOException; + private String readNext() throws IOException { + return reader.readLine(); + } - protected abstract void writeNext(String line) throws IOException; + private void writeNext(String line) throws IOException { + writer.write(line + '\n'); + writer.flush(); + } public void writeLine(String pMessage) { try { @@ -160,4 +179,8 @@ return null; } + + public InetAddress getInetAddress() { + return sock.getInetAddress(); + } } Modified: VASSAL-src/trunk/src/VASSAL/chat/node/SocketNodeClient.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/node/SocketNodeClient.java 2020-05-27 21:38:26 UTC (rev 9447) +++ VASSAL-src/trunk/src/VASSAL/chat/node/SocketNodeClient.java 2020-05-27 21:38:33 UTC (rev 9448) @@ -61,7 +61,7 @@ @Override protected void initializeConnection() throws UnknownHostException, IOException { Socket s = new Socket(serverInfo.getHostName(), serverInfo.getPort()); - sender = new BufferedSocketHandler(s, this); + sender = new SocketHandler(s, this); sender.start(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uck...@us...> - 2020-05-27 21:38:29
|
Revision: 9447 http://sourceforge.net/p/vassalengine/svn/9447 Author: uckelman Date: 2020-05-27 21:38:26 +0000 (Wed, 27 May 2020) Log Message: ----------- Cleanup. Modified Paths: -------------- VASSAL-src/trunk/src/VASSAL/build/GameModule.java VASSAL-src/trunk/src/VASSAL/build/module/ModuleExtension.java VASSAL-src/trunk/src/VASSAL/chat/jabber/JabberClient.java VASSAL-src/trunk/src/VASSAL/chat/node/LockWatcher.java VASSAL-src/trunk/src/VASSAL/chat/node/Server.java VASSAL-src/trunk/src/VASSAL/chat/node/SocketNodeClient.java Modified: VASSAL-src/trunk/src/VASSAL/build/GameModule.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/GameModule.java 2020-05-27 21:38:20 UTC (rev 9446) +++ VASSAL-src/trunk/src/VASSAL/build/GameModule.java 2020-05-27 21:38:26 UTC (rev 9447) @@ -1020,7 +1020,7 @@ try { final String save = buildString(); writer.addFile(BUILDFILE, - new ByteArrayInputStream(save.getBytes(StandardCharsets.UTF_8))); //$NON-NLS-1$ + new ByteArrayInputStream(save.getBytes(StandardCharsets.UTF_8))); if (saveAs) writer.saveAs(true); else writer.save(true); Modified: VASSAL-src/trunk/src/VASSAL/build/module/ModuleExtension.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/module/ModuleExtension.java 2020-05-27 21:38:20 UTC (rev 9446) +++ VASSAL-src/trunk/src/VASSAL/build/module/ModuleExtension.java 2020-05-27 21:38:26 UTC (rev 9447) @@ -116,7 +116,7 @@ } public void build() { - final String fileName = GameModule.BUILDFILE; //$NON-NLS-1$ + final String fileName = GameModule.BUILDFILE; GameModule.getGameModule().getDataArchive().addExtension(archive); @@ -413,7 +413,7 @@ final String save = buildString(); w.addFile(GameModule.BUILDFILE, - new ByteArrayInputStream(save.getBytes(StandardCharsets.UTF_8))); //$NON-NLS-1$ + new ByteArrayInputStream(save.getBytes(StandardCharsets.UTF_8))); if (saveAs) w.saveAs(true); else w.save(true); Modified: VASSAL-src/trunk/src/VASSAL/chat/jabber/JabberClient.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/jabber/JabberClient.java 2020-05-27 21:38:20 UTC (rev 9446) +++ VASSAL-src/trunk/src/VASSAL/chat/jabber/JabberClient.java 2020-05-27 21:38:26 UTC (rev 9447) @@ -659,7 +659,7 @@ protected String encodeMessage(String clearText) { try (FastByteArrayOutputStream ba = new FastByteArrayOutputStream(); ObfuscatingOutputStream out = new ObfuscatingOutputStream(ba)) { - out.write(clearText.getBytes(StandardCharsets.UTF_8)); //$NON-NLS-1$ + out.write(clearText.getBytes(StandardCharsets.UTF_8)); return new String(ba.toByteArray()); } catch (IOException e) { @@ -677,7 +677,7 @@ protected String decodeMessage(String encodedMessage) { try (ByteArrayInputStream ba = new ByteArrayInputStream(encodedMessage.getBytes()); DeobfuscatingInputStream in = new DeobfuscatingInputStream(ba)) { - return IOUtils.toString(in, StandardCharsets.UTF_8); //$NON-NLS-1$ + return IOUtils.toString(in, StandardCharsets.UTF_8); } catch (IOException e) { e.printStackTrace(); Modified: VASSAL-src/trunk/src/VASSAL/chat/node/LockWatcher.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/node/LockWatcher.java 2020-05-27 21:38:20 UTC (rev 9446) +++ VASSAL-src/trunk/src/VASSAL/chat/node/LockWatcher.java 2020-05-27 21:38:26 UTC (rev 9447) @@ -21,9 +21,8 @@ import java.net.Socket; /** - * Watches for thread lock on a server. Kills the runtime if unable to establish new connection - * Copyright (c) 2003 by Rodney Kinney. All rights reserved. - * Date: Jul 20, 2003 + * Watches for thread lock on a server. + * Kills the runtime if unable to establish new connection */ public class LockWatcher extends Thread { private long delay; @@ -86,6 +85,7 @@ e.printStackTrace(); } } + private class Timeout implements Runnable { @Override public void run() { Modified: VASSAL-src/trunk/src/VASSAL/chat/node/Server.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/node/Server.java 2020-05-27 21:38:20 UTC (rev 9446) +++ VASSAL-src/trunk/src/VASSAL/chat/node/Server.java 2020-05-27 21:38:26 UTC (rev 9447) @@ -14,10 +14,6 @@ * License along with this library; if not, copies are available * at http://www.opensource.org. */ -/* - * Copyright (c) 2003 by Rodney Kinney. All rights reserved. - * Date: Jun 4, 2003 - */ package VASSAL.chat.node; import java.io.BufferedReader; Modified: VASSAL-src/trunk/src/VASSAL/chat/node/SocketNodeClient.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/node/SocketNodeClient.java 2020-05-27 21:38:20 UTC (rev 9446) +++ VASSAL-src/trunk/src/VASSAL/chat/node/SocketNodeClient.java 2020-05-27 21:38:26 UTC (rev 9447) @@ -40,7 +40,6 @@ public SocketNodeClient(String moduleName, String playerId, CommandEncoder encoder, final String host, final int port, MessageBoard msgSvr, WelcomeMessageServer welcomer) { this(moduleName, playerId, encoder, new NodeServerInfo() { - @Override public String getHostName() { return host; @@ -52,7 +51,6 @@ } }, msgSvr, welcomer); - } @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uck...@us...> - 2020-05-27 21:38:22
|
Revision: 9446 http://sourceforge.net/p/vassalengine/svn/9446 Author: uckelman Date: 2020-05-27 21:38:20 +0000 (Wed, 27 May 2020) Log Message: ----------- Use Properties.stringPropertyNames() now that we're at Java >= 6. Modified Paths: -------------- VASSAL-src/trunk/src/VASSAL/chat/node/PlayerNode.java VASSAL-src/trunk/src/VASSAL/preferences/Prefs.java Modified: VASSAL-src/trunk/src/VASSAL/chat/node/PlayerNode.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/node/PlayerNode.java 2020-05-27 21:38:14 UTC (rev 9445) +++ VASSAL-src/trunk/src/VASSAL/chat/node/PlayerNode.java 2020-05-27 21:38:20 UTC (rev 9446) @@ -120,9 +120,7 @@ server.kick(this, info[0]); } else if ((p = Protocol.decodeRoomsInfo(line)) != null) { -// FIXME: Use Properties.stringPropertyNames() in 1.6+. - for (Object o : p.keySet()) { - String roomName = (String) o; + for (String roomName : p.stringPropertyNames()) { Node target = server.getModule(this).getDescendant(roomName); if (target != null) { target.setInfo(p.getProperty(roomName)); Modified: VASSAL-src/trunk/src/VASSAL/preferences/Prefs.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/preferences/Prefs.java 2020-05-27 21:38:14 UTC (rev 9445) +++ VASSAL-src/trunk/src/VASSAL/preferences/Prefs.java 2020-05-27 21:38:20 UTC (rev 9446) @@ -73,10 +73,7 @@ read(); - // FIXME: Use stringPropertyNames() in 1.6+ - // for (String key : storedValues.stringPropertyNames()) { - for (Enumeration<?> e = storedValues.keys(); e.hasMoreElements();) { - final String key = (String) e.nextElement(); + for (String key : storedValues.stringPropertyNames()) { final String value = storedValues.getProperty(key); final Configurer c = options.get(key); if (c != null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uck...@us...> - 2020-05-27 21:38:17
|
Revision: 9445 http://sourceforge.net/p/vassalengine/svn/9445 Author: uckelman Date: 2020-05-27 21:38:14 +0000 (Wed, 27 May 2020) Log Message: ----------- Removed redundant copyright information. (It's already at the top.) Modified Paths: -------------- VASSAL-src/trunk/src/VASSAL/chat/node/BufferedSocketHandler.java VASSAL-src/trunk/src/VASSAL/chat/node/PlayerNode.java VASSAL-src/trunk/src/VASSAL/chat/node/Protocol.java VASSAL-src/trunk/src/VASSAL/chat/node/SocketHandler.java VASSAL-src/trunk/src/VASSAL/chat/node/SocketWatcher.java Modified: VASSAL-src/trunk/src/VASSAL/chat/node/BufferedSocketHandler.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/node/BufferedSocketHandler.java 2020-05-27 21:38:09 UTC (rev 9444) +++ VASSAL-src/trunk/src/VASSAL/chat/node/BufferedSocketHandler.java 2020-05-27 21:38:14 UTC (rev 9445) @@ -25,7 +25,6 @@ import java.net.Socket; import java.nio.charset.StandardCharsets; - public class BufferedSocketHandler extends SocketHandler { protected BufferedReader reader; protected BufferedWriter writer; Modified: VASSAL-src/trunk/src/VASSAL/chat/node/PlayerNode.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/node/PlayerNode.java 2020-05-27 21:38:09 UTC (rev 9444) +++ VASSAL-src/trunk/src/VASSAL/chat/node/PlayerNode.java 2020-05-27 21:38:14 UTC (rev 9445) @@ -15,10 +15,6 @@ * License along with this library; if not, copies are available * at http://www.opensource.org. */ -/* - * Copyright (c) 2003 by Rodney Kinney. All rights reserved. - * Date: May 9, 2003 - */ package VASSAL.chat.node; import java.io.IOException; Modified: VASSAL-src/trunk/src/VASSAL/chat/node/Protocol.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/node/Protocol.java 2020-05-27 21:38:09 UTC (rev 9444) +++ VASSAL-src/trunk/src/VASSAL/chat/node/Protocol.java 2020-05-27 21:38:14 UTC (rev 9445) @@ -15,10 +15,6 @@ * License along with this library; if not, copies are available * at http://www.opensource.org. */ -/* - * Copyright (c) 2003 by Rodney Kinney. All rights reserved. - * Date: May 14, 2003 - */ package VASSAL.chat.node; import java.io.IOException; Modified: VASSAL-src/trunk/src/VASSAL/chat/node/SocketHandler.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/node/SocketHandler.java 2020-05-27 21:38:09 UTC (rev 9444) +++ VASSAL-src/trunk/src/VASSAL/chat/node/SocketHandler.java 2020-05-27 21:38:14 UTC (rev 9445) @@ -23,10 +23,6 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; -/** - * Copyright (c) 2003 by Rodney Kinney. All rights reserved. - * Date: Aug 27, 2003 - */ public abstract class SocketHandler { protected Socket sock; protected SocketWatcher handler; Modified: VASSAL-src/trunk/src/VASSAL/chat/node/SocketWatcher.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/node/SocketWatcher.java 2020-05-27 21:38:09 UTC (rev 9444) +++ VASSAL-src/trunk/src/VASSAL/chat/node/SocketWatcher.java 2020-05-27 21:38:14 UTC (rev 9445) @@ -15,10 +15,6 @@ * License along with this library; if not, copies are available * at http://www.opensource.org. */ -/* - * Copyright (c) 2003 by Rodney Kinney. All rights reserved. - * Date: May 14, 2003 - */ package VASSAL.chat.node; /** Generic interface for listening to a socket */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uck...@us...> - 2020-05-27 21:38:11
|
Revision: 9444 http://sourceforge.net/p/vassalengine/svn/9444 Author: uckelman Date: 2020-05-27 21:38:09 +0000 (Wed, 27 May 2020) Log Message: ----------- Removed cruft. Modified Paths: -------------- VASSAL-src/trunk/dist/windows/nsis/installer.nsi Modified: VASSAL-src/trunk/dist/windows/nsis/installer.nsi =================================================================== --- VASSAL-src/trunk/dist/windows/nsis/installer.nsi 2020-05-26 19:31:18 UTC (rev 9443) +++ VASSAL-src/trunk/dist/windows/nsis/installer.nsi 2020-05-27 21:38:09 UTC (rev 9444) @@ -31,7 +31,6 @@ !define VNAME "VASSAL (${VERSION})" !define UROOT "${UNINST}\${VNAME}" !define AROOT "Software\Classes" -!define JAVA_MINIMUM "1.6.0_45" Name "VASSAL" OutFile "${TMPDIR}/VASSAL-${VERSION}-windows.exe" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uck...@us...> - 2020-05-26 19:31:20
|
Revision: 9443 http://sourceforge.net/p/vassalengine/svn/9443 Author: uckelman Date: 2020-05-26 19:31:18 +0000 (Tue, 26 May 2020) Log Message: ----------- Removed redundant copyright information. (It's already at the top.) Modified Paths: -------------- VASSAL-src/trunk/src/VASSAL/chat/node/BufferedSocketHandler.java Modified: VASSAL-src/trunk/src/VASSAL/chat/node/BufferedSocketHandler.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/node/BufferedSocketHandler.java 2020-05-25 22:45:29 UTC (rev 9442) +++ VASSAL-src/trunk/src/VASSAL/chat/node/BufferedSocketHandler.java 2020-05-26 19:31:18 UTC (rev 9443) @@ -25,10 +25,7 @@ import java.net.Socket; import java.nio.charset.StandardCharsets; -/** - * Copyright (c) 2003 by Rodney Kinney. All rights reserved. - * Date: Aug 27, 2003 - */ + public class BufferedSocketHandler extends SocketHandler { protected BufferedReader reader; protected BufferedWriter writer; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uck...@us...> - 2020-05-25 22:45:31
|
Revision: 9442 http://sourceforge.net/p/vassalengine/svn/9442 Author: uckelman Date: 2020-05-25 22:45:29 +0000 (Mon, 25 May 2020) Log Message: ----------- Added some type parameters. Modified Paths: -------------- VASSAL-src/trunk/src/VASSAL/chat/ServerAddressBook.java VASSAL-src/trunk/src/VASSAL/i18n/TranslateWindow.java Modified: VASSAL-src/trunk/src/VASSAL/chat/ServerAddressBook.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/ServerAddressBook.java 2020-05-25 22:17:31 UTC (rev 9441) +++ VASSAL-src/trunk/src/VASSAL/chat/ServerAddressBook.java 2020-05-25 22:45:29 UTC (rev 9442) @@ -519,7 +519,7 @@ decodeAddressBook(addressConfig.getValueString()); // Remove any PeerClientEntry's, these are obsolete - final DefaultListModel newAddressBook = new DefaultListModel(); + final DefaultListModel<AddressBookEntry> newAddressBook = new DefaultListModel<>(); for (Enumeration<AddressBookEntry> e = addressBook.elements(); e.hasMoreElements();) { final AddressBookEntry entry = e.nextElement(); if (entry instanceof LegacyEntry) { @@ -531,7 +531,6 @@ } addressBook = newAddressBook; - // Ensure that the Address Book has the basic // servers in it. boolean legacy = false; Modified: VASSAL-src/trunk/src/VASSAL/i18n/TranslateWindow.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/i18n/TranslateWindow.java 2020-05-25 22:17:31 UTC (rev 9441) +++ VASSAL-src/trunk/src/VASSAL/i18n/TranslateWindow.java 2020-05-25 22:45:29 UTC (rev 9442) @@ -90,7 +90,7 @@ protected Translatable keyTarget; protected JTree tree; protected Translation currentTranslation = null; - protected JComboBox langBox; + protected JComboBox<String> langBox; protected ActionListener boxListener; protected int lastSelectedLangIndex; protected String currentKey = ""; //$NON-NLS-1$ @@ -129,7 +129,7 @@ protected Component getHeaderPanel() { JPanel langPanel = new JPanel(); langPanel.add(new JLabel("Language: ")); - langBox = new JComboBox(Localization.getInstance().getTranslationList()); + langBox = new JComboBox<>(Localization.getInstance().getTranslationList()); langPanel.add(langBox); boxListener = new ActionListener() { @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uck...@us...> - 2020-05-25 22:17:34
|
Revision: 9441 http://sourceforge.net/p/vassalengine/svn/9441 Author: uckelman Date: 2020-05-25 22:17:31 +0000 (Mon, 25 May 2020) Log Message: ----------- More adjustments to use try with resources. Modified Paths: -------------- VASSAL-src/trunk/src/VASSAL/build/module/Inventory.java VASSAL-src/trunk/src/VASSAL/build/module/dice/DieServer.java VASSAL-src/trunk/src/VASSAL/build/module/map/TextSaver.java VASSAL-src/trunk/src/VASSAL/counters/Deck.java VASSAL-src/trunk/src/VASSAL/script/ExpressionInterpreter.java VASSAL-src/trunk/src/VASSAL/tools/icon/IconFactory.java VASSAL-src/trunk/src/VASSAL/tools/imports/adc2/ADC2Module.java VASSAL-src/trunk/src/VASSAL/tools/imports/adc2/SymbolSet.java VASSAL-src/trunk/src/VASSAL/tools/version/VersionUtils.java Modified: VASSAL-src/trunk/src/VASSAL/build/module/Inventory.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/module/Inventory.java 2020-05-25 21:49:56 UTC (rev 9440) +++ VASSAL-src/trunk/src/VASSAL/build/module/Inventory.java 2020-05-25 22:17:31 UTC (rev 9441) @@ -37,6 +37,7 @@ import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; +import java.io.Writer; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -105,7 +106,6 @@ import VASSAL.tools.ScrollPane; import VASSAL.tools.WriteErrorDialog; import VASSAL.tools.filechooser.FileChooser; -import VASSAL.tools.io.IOUtils; import VASSAL.tools.swing.SwingUtils; public class Inventory extends AbstractConfigurable @@ -409,12 +409,10 @@ // .substring(1).replaceAll( // mapSeparator, System.getProperty("line.separator")); - PrintWriter p = null; - try { - p = new PrintWriter(new BufferedWriter(new FileWriter(file))); - + try (Writer fw = new FileWriter(file); + BufferedWriter bw = new BufferedWriter(fw); + PrintWriter p = new PrintWriter(bw)) { p.print(output); - p.close(); final Command c = new Chatter.DisplayText( GameModule.getGameModule().getChatter(), @@ -425,9 +423,6 @@ catch (IOException e) { WriteErrorDialog.error(e, file); } - finally { - IOUtils.closeQuietly(p); - } } public GamePiece getSelectedCounter() { Modified: VASSAL-src/trunk/src/VASSAL/build/module/dice/DieServer.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/module/dice/DieServer.java 2020-05-25 21:49:56 UTC (rev 9440) +++ VASSAL-src/trunk/src/VASSAL/build/module/dice/DieServer.java 2020-05-25 22:17:31 UTC (rev 9441) @@ -1,8 +1,10 @@ package VASSAL.build.module.dice; import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; import java.io.IOException; -import java.io.InputStreamReader; +import java.io.OutputStream; import java.io.PrintWriter; import java.net.URL; import java.net.URLConnection; @@ -21,9 +23,7 @@ import VASSAL.build.module.InternetDiceButton; import VASSAL.tools.ErrorDialog; import VASSAL.tools.FormattedString; -import VASSAL.tools.io.IOUtils; - /** * Base DieServer Class * Does most of the work. Individual Die Servers just need to implement @@ -271,28 +271,21 @@ final URLConnection connection = url.openConnection(); connection.setDoOutput(true); - final PrintWriter out = new PrintWriter(connection.getOutputStream()); - try { - for (String s : rollString) out.println(s); - out.close(); + try (OutputStream os = connection.getOutputStream(); + PrintWriter out = new PrintWriter(os)) { + for (String s : rollString) { + out.println(s); + } } - finally { - IOUtils.closeQuietly(out); - } - BufferedReader in = null; - try { - in = new BufferedReader( - new InputStreamReader(connection.getInputStream())); - + try (InputStream is = connection.getInputStream(); + InputStreamReader isr = new InputStreamReader(is); + BufferedReader in = new BufferedReader(isr)) { String inputLine; - while ((inputLine = in.readLine()) != null) returnString.add(inputLine); - - in.close(); + while ((inputLine = in.readLine()) != null) { + returnString.add(inputLine); + } } - finally { - IOUtils.closeQuietly(in); - } parseInternetRollString(toss, new Vector<>(returnString)); } Modified: VASSAL-src/trunk/src/VASSAL/build/module/map/TextSaver.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/module/map/TextSaver.java 2020-05-25 21:49:56 UTC (rev 9440) +++ VASSAL-src/trunk/src/VASSAL/build/module/map/TextSaver.java 2020-05-25 22:17:31 UTC (rev 9441) @@ -25,6 +25,7 @@ import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; +import java.io.Writer; import javax.swing.JOptionPane; @@ -43,7 +44,6 @@ import VASSAL.tools.NamedKeyStroke; import VASSAL.tools.WriteErrorDialog; import VASSAL.tools.filechooser.FileChooser; -import VASSAL.tools.io.IOUtils; public class TextSaver extends AbstractConfigurable { @@ -150,10 +150,9 @@ if (fc.showSaveDialog(map.getView()) != FileChooser.APPROVE_OPTION) return; final File file = fc.getSelectedFile(); - PrintWriter p = null; - try { - p = new PrintWriter(new BufferedWriter(new FileWriter(file))); - + try (Writer fw = new FileWriter(file); + BufferedWriter bw = new BufferedWriter(fw); + PrintWriter p = new PrintWriter(bw)) { for (GamePiece gp : map.getPieces()) { final String s = gp.getName(); if (s.length() > 0) { @@ -160,15 +159,10 @@ p.println(map.locationName(gp.getPosition()) + ": " + s); } } - - p.close(); } catch (IOException e) { WriteErrorDialog.error(e, file); } - finally { - IOUtils.closeQuietly(p); - } } @Override Modified: VASSAL-src/trunk/src/VASSAL/counters/Deck.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/counters/Deck.java 2020-05-25 21:49:56 UTC (rev 9440) +++ VASSAL-src/trunk/src/VASSAL/counters/Deck.java 2020-05-25 22:17:31 UTC (rev 9441) @@ -33,6 +33,8 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.io.Reader; +import java.io.Writer; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -1390,17 +1392,12 @@ comm = comm.append(new AddPiece(p)); } - BufferedWriter out = null; - try { - out = new BufferedWriter(new FileWriter(f)); + try (Writer fw = new FileWriter(f); + BufferedWriter out = new BufferedWriter(fw)) { GameModule.getGameModule().addCommandEncoder(commandEncoder); out.write(GameModule.getGameModule().encode(comm)); GameModule.getGameModule().removeCommandEncoder(commandEncoder); - out.close(); } - finally { - IOUtils.closeQuietly(out); - } } private File getLoadFileName() { @@ -1433,16 +1430,12 @@ } public Command loadDeck(File f) throws IOException { - BufferedReader in = null; String ds = null; - try { - in = new BufferedReader(new FileReader(f)); + + try (Reader fr = new FileReader(f); + BufferedReader in = new BufferedReader(fr)) { ds = IOUtils.toString(in); - in.close(); } - finally { - IOUtils.closeQuietly(in); - } GameModule.getGameModule().addCommandEncoder(commandEncoder); Command c = GameModule.getGameModule().decode(ds); Modified: VASSAL-src/trunk/src/VASSAL/script/ExpressionInterpreter.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/script/ExpressionInterpreter.java 2020-05-25 21:49:56 UTC (rev 9440) +++ VASSAL-src/trunk/src/VASSAL/script/ExpressionInterpreter.java 2020-05-25 22:17:31 UTC (rev 9441) @@ -19,8 +19,9 @@ package VASSAL.script; import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; import java.io.IOException; -import java.io.InputStreamReader; import java.net.URL; import java.util.ArrayList; import java.util.HashMap; @@ -167,12 +168,10 @@ // Read the Expression initialisation script into the top level namespace URL ini = getClass().getResource(INIT_SCRIPT); logger.info("Attempting to load "+INIT_SCRIPT+" URI generated="+ ini); - BufferedReader in = null; - try { - in = new BufferedReader( - new InputStreamReader( - ini.openStream())); + try (InputStream is = ini.openStream(); + InputStreamReader isr = new InputStreamReader(is); + BufferedReader in = new BufferedReader(isr)) { try { eval(in); } @@ -185,9 +184,6 @@ logger.error("Error trying to read init script: "+ ini); WarningDialog.show(e, ""); } - finally { - IOUtils.closeQuietly(in); - } } /** @@ -396,4 +392,4 @@ } return result; } -} \ No newline at end of file +} Modified: VASSAL-src/trunk/src/VASSAL/tools/icon/IconFactory.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/icon/IconFactory.java 2020-05-25 21:49:56 UTC (rev 9440) +++ VASSAL-src/trunk/src/VASSAL/tools/icon/IconFactory.java 2020-05-25 22:17:31 UTC (rev 9441) @@ -20,8 +20,9 @@ import java.awt.image.BufferedImage; import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; import java.io.IOException; -import java.io.InputStreamReader; import java.net.JarURLConnection; import java.net.URL; import java.util.ArrayList; @@ -45,7 +46,6 @@ import VASSAL.tools.ErrorDialog; import VASSAL.tools.JarArchive; import VASSAL.tools.ReadErrorDialog; -import VASSAL.tools.io.IOUtils; /** * Manage and Provide Icons in standard sizes. @@ -316,9 +316,10 @@ protected void findLocalSizedIcons(int size) throws IOException { final String path = DataArchive.ICON_DIR+IconFamily.SIZE_DIRS[size]; final URL sizeURL = jar.getURL(path); - BufferedReader br = null; - try { - br = new BufferedReader(new InputStreamReader(sizeURL.openStream())); + + try (InputStream in = sizeURL.openStream(); + InputStreamReader isr = new InputStreamReader(in); + BufferedReader br = new BufferedReader(isr)) { String imageName = ""; //$NON-NLS-1$ while (imageName != null) { imageName = br.readLine(); @@ -334,9 +335,6 @@ } } } - finally { - IOUtils.closeQuietly(br); - } } /** @@ -348,9 +346,10 @@ private void findLocalScalableIcons() throws IOException { final String scalablePath = DataArchive.ICON_DIR+IconFamily.SCALABLE_DIR; final URL url = jar.getURL(scalablePath); - BufferedReader br = null; - try { - br= new BufferedReader(new InputStreamReader(url.openStream())); + + try (InputStream in = url.openStream(); + InputStreamReader isr = new InputStreamReader(in); + BufferedReader br = new BufferedReader(isr)) { String imageName = ""; //$NON-NLS-1$ while (imageName != null) { imageName = br.readLine(); @@ -366,9 +365,6 @@ } } } - finally { - IOUtils.closeQuietly(br); - } } /** Modified: VASSAL-src/trunk/src/VASSAL/tools/imports/adc2/ADC2Module.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/imports/adc2/ADC2Module.java 2020-05-25 21:49:56 UTC (rev 9440) +++ VASSAL-src/trunk/src/VASSAL/tools/imports/adc2/ADC2Module.java 2020-05-25 22:17:31 UTC (rev 9441) @@ -44,6 +44,7 @@ import java.io.FileReader; import java.io.InputStream; import java.io.IOException; +import java.io.Reader; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -119,7 +120,6 @@ import VASSAL.tools.imports.FileFormatException; import VASSAL.tools.imports.Importer; import VASSAL.tools.imports.adc2.SymbolSet.SymbolData; -import VASSAL.tools.io.IOUtils; public class ADC2Module extends Importer { @@ -2394,10 +2394,9 @@ StringBuilder sb = new StringBuilder(); sb.append("<html><body>"); - BufferedReader input = null; - try { - input = new BufferedReader(new FileReader(f)); + try (Reader fr = new FileReader(f); + BufferedReader input = new BufferedReader(fr)) { String line = null; do { line = input.readLine(); @@ -2413,12 +2412,7 @@ sb.append("</body></html>"); gameModule.getArchiveWriter().addFile(f.getName(), sb.toString().getBytes()); w.setAttribute(HtmlChart.FILE, f.getName()); - - input.close(); } - finally { - IOUtils.closeQuietly(input); - } } tab.propertyChange(new PropertyChangeEvent(w, Configurable.NAME_PROPERTY, "", infoPages[i])); } Modified: VASSAL-src/trunk/src/VASSAL/tools/imports/adc2/SymbolSet.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/imports/adc2/SymbolSet.java 2020-05-25 21:49:56 UTC (rev 9440) +++ VASSAL-src/trunk/src/VASSAL/tools/imports/adc2/SymbolSet.java 2020-05-25 22:17:31 UTC (rev 9441) @@ -36,6 +36,7 @@ import java.io.FileReader; import java.io.InputStream; import java.io.IOException; +import java.io.Reader; import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -47,7 +48,6 @@ import VASSAL.tools.imports.FileFormatException; import VASSAL.tools.imports.ImportAction; import VASSAL.tools.imports.Importer; -import VASSAL.tools.io.IOUtils; /** * ADC2 game piece and terrain symbols. @@ -593,10 +593,9 @@ File sdx = new File(forceExtension(f.getPath(), "sdx")); sdx = action.getCaseInsensitiveFile(sdx, f, false, null); if (sdx != null) { // must reorder image indeces - BufferedReader input = null; - try { - input = new BufferedReader(new FileReader(sdx)); + try (Reader fr = new FileReader(sdx); + BufferedReader input = new BufferedReader(fr)) { final SymbolData[] pieces = Arrays.copyOf(gamePieceData, gamePieceData.length); @@ -621,12 +620,7 @@ finally { gamePieceData = pieces; } - - input.close(); } - finally { - IOUtils.closeQuietly(input); - } } } Modified: VASSAL-src/trunk/src/VASSAL/tools/version/VersionUtils.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/version/VersionUtils.java 2020-05-25 21:49:56 UTC (rev 9440) +++ VASSAL-src/trunk/src/VASSAL/tools/version/VersionUtils.java 2020-05-25 22:17:31 UTC (rev 9441) @@ -44,11 +44,8 @@ public static boolean isReportable(String version) throws IOException, NumberFormatException { - InputStream in = null; - try { - in = new URL(baseURL + bugCheck + version).openStream(); + try (InputStream in = new URL(baseURL + bugCheck + version).openStream()) { final int result = Integer.parseInt(IOUtils.toString(in)); - in.close(); switch (result) { case 0: return false; @@ -57,9 +54,6 @@ throw new NumberFormatException("bad return value: " + result); } } - finally { - IOUtils.closeQuietly(in); - } } */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uck...@us...> - 2020-05-25 21:49:58
|
Revision: 9440 http://sourceforge.net/p/vassalengine/svn/9440 Author: uckelman Date: 2020-05-25 21:49:56 +0000 (Mon, 25 May 2020) Log Message: ----------- Adjusted AudioSystemClip to use try with resources. (This is somewhat gnarly due to all the exceptions which can be thrown and the fact that the Clip has to be returned open.) Modified Paths: -------------- VASSAL-src/trunk/src/VASSAL/tools/AudioSystemClip.java Modified: VASSAL-src/trunk/src/VASSAL/tools/AudioSystemClip.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/AudioSystemClip.java 2020-05-25 21:49:51 UTC (rev 9439) +++ VASSAL-src/trunk/src/VASSAL/tools/AudioSystemClip.java 2020-05-25 21:49:56 UTC (rev 9440) @@ -41,9 +41,9 @@ in = new BufferedInputStream(in); } - // try to get a Clip Clip clip = null; try { + // try to get a Clip try { clip = AudioSystem.getClip(); } @@ -54,25 +54,25 @@ // wrap the input stream AudioInputStream ais = null; try { + ais = AudioSystem.getAudioInputStream(in); + } + catch (UnsupportedAudioFileException e) { + throw new IOException(e); + } + + try (AudioInputStream a = ais) { + // convert the audio stream to the type the clip wants + AudioInputStream cais = null; try { - ais = AudioSystem.getAudioInputStream(in); + cais = AudioSystem.getAudioInputStream(clip.getFormat(), a); } - catch (UnsupportedAudioFileException e) { + catch (IllegalArgumentException e) { throw new IOException(e); } - // convert the audio stream to the type the clip wants - AudioInputStream cais = null; - try { + try (AudioInputStream ca = cais) { try { - cais = AudioSystem.getAudioInputStream(clip.getFormat(), ais); - } - catch (IllegalArgumentException e) { - throw new IOException(e); - } - - try { - clip.open(cais); + clip.open(ca); return clip; } catch (IllegalArgumentException | SecurityException | LineUnavailableException e) { @@ -79,13 +79,7 @@ throw new IOException(e); } } - finally { - IOUtils.closeQuietly(cais); - } } - finally { - IOUtils.closeQuietly(ais); - } } catch (Exception e) { IOUtils.closeQuietly(clip); @@ -94,14 +88,9 @@ } public AudioSystemClip(URL url) throws IOException { - InputStream in = null; - try { - in = url.openStream(); + try (InputStream in = url.openStream()) { the_clip = getClip(in); } - finally { - IOUtils.closeQuietly(in); - } } public AudioSystemClip(InputStream in) throws IOException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uck...@us...> - 2020-05-25 21:49:53
|
Revision: 9439 http://sourceforge.net/p/vassalengine/svn/9439 Author: uckelman Date: 2020-05-25 21:49:51 +0000 (Mon, 25 May 2020) Log Message: ----------- Object cast is required to stop varargs ambiguity warning. Modified Paths: -------------- VASSAL-src/trunk/src/VASSAL/launch/LaunchRequestException.java Modified: VASSAL-src/trunk/src/VASSAL/launch/LaunchRequestException.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/launch/LaunchRequestException.java 2020-05-25 21:49:46 UTC (rev 9438) +++ VASSAL-src/trunk/src/VASSAL/launch/LaunchRequestException.java 2020-05-25 21:49:51 UTC (rev 9439) @@ -39,6 +39,6 @@ * @param vals {@link Resources} arguments */ public LaunchRequestException(String key, String... vals) { - super(Resources.getString(key, vals)); + super(Resources.getString(key, (Object) vals)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uck...@us...> - 2020-05-25 21:49:48
|
Revision: 9438 http://sourceforge.net/p/vassalengine/svn/9438 Author: uckelman Date: 2020-05-25 21:49:46 +0000 (Mon, 25 May 2020) Log Message: ----------- Fixed three "try" warnings. Modified Paths: -------------- VASSAL-src/trunk/src/VASSAL/tools/ZipUpdater.java VASSAL-src/trunk/src/VASSAL/tools/imports/adc2/SymbolSet.java Modified: VASSAL-src/trunk/src/VASSAL/tools/ZipUpdater.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/ZipUpdater.java 2020-05-25 21:49:40 UTC (rev 9437) +++ VASSAL-src/trunk/src/VASSAL/tools/ZipUpdater.java 2020-05-25 21:49:46 UTC (rev 9438) @@ -110,7 +110,7 @@ } try (BufferedInputStream in = new BufferedInputStream(newContents)) { - long cs = writeEntry(newContents, output, newEntry); + long cs = writeEntry(in, output, newEntry); return cs; } } @@ -293,7 +293,7 @@ } try (BufferedInputStream in = new BufferedInputStream(is)) { - writeEntry(is, out, classEntry); + writeEntry(in, out, classEntry); } } } Modified: VASSAL-src/trunk/src/VASSAL/tools/imports/adc2/SymbolSet.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/imports/adc2/SymbolSet.java 2020-05-25 21:49:40 UTC (rev 9437) +++ VASSAL-src/trunk/src/VASSAL/tools/imports/adc2/SymbolSet.java 2020-05-25 21:49:46 UTC (rev 9438) @@ -571,8 +571,6 @@ maskData[i] = new SymbolData(maskImages, true).read(in); } - in.close(); - /* See if there is a single-image underlay for the map. */ underlay = loadSymbolImage(baseName, 'z', false); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uck...@us...> - 2020-05-25 21:49:43
|
Revision: 9437 http://sourceforge.net/p/vassalengine/svn/9437 Author: uckelman Date: 2020-05-25 21:49:40 +0000 (Mon, 25 May 2020) Log Message: ----------- Deprecated copyOf, copyOfRange functions in ArrayUtils. Use the ones from Arrays instead. Modified Paths: -------------- VASSAL-src/trunk/src/VASSAL/build/module/SpecialDiceButton.java VASSAL-src/trunk/src/VASSAL/chat/node/ServerNode.java VASSAL-src/trunk/src/VASSAL/configure/ChooseComponentPathDialog.java VASSAL-src/trunk/src/VASSAL/counters/Deck.java VASSAL-src/trunk/src/VASSAL/counters/Stack.java VASSAL-src/trunk/src/VASSAL/tools/ArrayUtils.java VASSAL-src/trunk/src/VASSAL/tools/SequenceEncoder.java VASSAL-src/trunk/src/VASSAL/tools/filechooser/ExtensionFileFilter.java VASSAL-src/trunk/src/VASSAL/tools/imports/adc2/SymbolSet.java Modified: VASSAL-src/trunk/src/VASSAL/build/module/SpecialDiceButton.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/module/SpecialDiceButton.java 2020-05-25 21:49:31 UTC (rev 9436) +++ VASSAL-src/trunk/src/VASSAL/build/module/SpecialDiceButton.java 2020-05-25 21:49:40 UTC (rev 9437) @@ -27,6 +27,7 @@ import java.awt.event.HierarchyEvent; import java.awt.event.HierarchyListener; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import javax.swing.Icon; @@ -58,7 +59,6 @@ import VASSAL.configure.VisibilityCondition; import VASSAL.i18n.Resources; import VASSAL.i18n.TranslatableConfigurerFactory; -import VASSAL.tools.ArrayUtils; import VASSAL.tools.FormattedString; import VASSAL.tools.KeyStrokeListener; import VASSAL.tools.LaunchButton; @@ -626,7 +626,7 @@ public ShowResults(SpecialDiceButton oTarget, int[] results) { target = oTarget; - rolls = ArrayUtils.copyOf(results); + rolls = Arrays.copyOf(results, results.length); } @Override Modified: VASSAL-src/trunk/src/VASSAL/chat/node/ServerNode.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/node/ServerNode.java 2020-05-25 21:49:31 UTC (rev 9436) +++ VASSAL-src/trunk/src/VASSAL/chat/node/ServerNode.java 2020-05-25 21:49:40 UTC (rev 9437) @@ -27,7 +27,6 @@ import java.util.TimerTask; import java.util.logging.Logger; -import VASSAL.tools.ArrayUtils; import VASSAL.tools.PropertiesEncoder; import VASSAL.tools.SequenceEncoder; @@ -87,7 +86,7 @@ } } - final MsgSender[] senders = ArrayUtils.copyOf(target); + final MsgSender[] senders = Arrays.copyOf(target, target.length); return new MsgSender() { @Override Modified: VASSAL-src/trunk/src/VASSAL/configure/ChooseComponentPathDialog.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/configure/ChooseComponentPathDialog.java 2020-05-25 21:49:31 UTC (rev 9436) +++ VASSAL-src/trunk/src/VASSAL/configure/ChooseComponentPathDialog.java 2020-05-25 21:49:40 UTC (rev 9437) @@ -19,6 +19,7 @@ package VASSAL.configure; import java.awt.Frame; +import java.util.Arrays; import javax.swing.event.TreeSelectionEvent; import javax.swing.tree.DefaultMutableTreeNode; @@ -26,7 +27,6 @@ import VASSAL.build.Buildable; import VASSAL.build.Configurable; -import VASSAL.tools.ArrayUtils; /** * Widget for selecting the full path of a Component in the Buildable hierarchy @@ -57,7 +57,7 @@ userObjectPath[i] = (Configurable) x[i]; } - path = ArrayUtils.copyOfRange(userObjectPath, 1, userObjectPath.length); + path = Arrays.copyOfRange(userObjectPath, 1, userObjectPath.length); } else { path = null; Modified: VASSAL-src/trunk/src/VASSAL/counters/Deck.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/counters/Deck.java 2020-05-25 21:49:31 UTC (rev 9436) +++ VASSAL-src/trunk/src/VASSAL/counters/Deck.java 2020-05-25 21:49:40 UTC (rev 9437) @@ -72,7 +72,6 @@ import VASSAL.configure.PropertyExpression; import VASSAL.i18n.Localization; import VASSAL.i18n.Resources; -import VASSAL.tools.ArrayUtils; import VASSAL.tools.ErrorDialog; import VASSAL.tools.FormattedString; import VASSAL.tools.NamedKeyStroke; @@ -566,7 +565,7 @@ } } - this.countExpressions = ArrayUtils.copyOf(c, goodExpressionCount); + this.countExpressions = Arrays.copyOf(c, goodExpressionCount); while (countExpressions.length > expressionProperties.size()) { expressionProperties.add(new MutableProperty.Impl("",this)); } Modified: VASSAL-src/trunk/src/VASSAL/counters/Stack.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/counters/Stack.java 2020-05-25 21:49:31 UTC (rev 9436) +++ VASSAL-src/trunk/src/VASSAL/counters/Stack.java 2020-05-25 21:49:40 UTC (rev 9437) @@ -25,6 +25,7 @@ import java.awt.Shape; import java.awt.geom.Area; import java.util.ArrayList; +import java.util.Arrays; import java.util.Enumeration; import java.util.Iterator; @@ -34,7 +35,6 @@ import VASSAL.build.module.Map; import VASSAL.build.module.map.StackMetrics; import VASSAL.command.Command; -import VASSAL.tools.ArrayUtils; import VASSAL.tools.EnumeratedIterator; import VASSAL.tools.ErrorDialog; import VASSAL.tools.SequenceEncoder; @@ -692,7 +692,7 @@ private final GamePiece[] p; public AllPieceIterator() { - p = ArrayUtils.copyOf(contents, pieceCount); + p = Arrays.copyOf(contents, pieceCount); } @Override @@ -716,7 +716,7 @@ private final GamePiece[] p; public ReversePieceIterator() { - p = ArrayUtils.copyOf(contents, pieceCount); + p = Arrays.copyOf(contents, pieceCount); } @Override Modified: VASSAL-src/trunk/src/VASSAL/tools/ArrayUtils.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/ArrayUtils.java 2020-05-25 21:49:31 UTC (rev 9436) +++ VASSAL-src/trunk/src/VASSAL/tools/ArrayUtils.java 2020-05-25 21:49:40 UTC (rev 9437) @@ -19,6 +19,7 @@ package VASSAL.tools; import java.lang.reflect.Array; +import java.util.Arrays; /** * @author Joel Uckelman @@ -27,220 +28,151 @@ public class ArrayUtils { private ArrayUtils() {} + @Deprecated public static boolean[] copyOf(boolean[] orig) { - return copyOf(orig, orig.length); + return Arrays.copyOf(orig, orig.length); } + @Deprecated public static byte[] copyOf(byte[] orig) { - return copyOf(orig, orig.length); + return Arrays.copyOf(orig, orig.length); } + @Deprecated public static char[] copyOf(char[] orig) { - return copyOf(orig, orig.length); + return Arrays.copyOf(orig, orig.length); } + @Deprecated public static double[] copyOf(double[] orig) { - return copyOf(orig, orig.length); + return Arrays.copyOf(orig, orig.length); } + @Deprecated public static float[] copyOf(float[] orig) { - return copyOf(orig, orig.length); + return Arrays.copyOf(orig, orig.length); } + @Deprecated public static int[] copyOf(int[] orig) { - return copyOf(orig, orig.length); + return Arrays.copyOf(orig, orig.length); } + @Deprecated public static long[] copyOf(long[] orig) { - return copyOf(orig, orig.length); + return Arrays.copyOf(orig, orig.length); } + @Deprecated public static short[] copyOf(short[] orig) { - return copyOf(orig, orig.length); + return Arrays.copyOf(orig, orig.length); } + @Deprecated public static <T> T[] copyOf(T[] orig) { - return copyOf(orig, orig.length); + return Arrays.copyOf(orig, orig.length); } - // FIXME: replace with Arrays.copyOf() in Java 1.6 + @Deprecated public static boolean[] copyOf(boolean[] orig, int newLength) { - final boolean[] copy = new boolean[newLength]; - System.arraycopy(orig, 0, copy, 0, Math.min(orig.length, newLength)); - return copy; + return Arrays.copyOf(orig, newLength); } - // FIXME: replace with Arrays.copyOf() in Java 1.6 + @Deprecated public static byte[] copyOf(byte[] orig, int newLength) { - final byte[] copy = new byte[newLength]; - System.arraycopy(orig, 0, copy, 0, Math.min(orig.length, newLength)); - return copy; + return Arrays.copyOf(orig, newLength); } - // FIXME: replace with Arrays.copyOf() in Java 1.6 + @Deprecated public static char[] copyOf(char[] orig, int newLength) { - final char[] copy = new char[newLength]; - System.arraycopy(orig, 0, copy, 0, Math.min(orig.length, newLength)); - return copy; + return Arrays.copyOf(orig, newLength); } - // FIXME: replace with Arrays.copyOf() in Java 1.6 + @Deprecated public static double[] copyOf(double[] orig, int newLength) { - final double[] copy = new double[newLength]; - System.arraycopy(orig, 0, copy, 0, Math.min(orig.length, newLength)); - return copy; + return Arrays.copyOf(orig, newLength); } - // FIXME: replace with Arrays.copyOf() in Java 1.6 + @Deprecated public static float[] copyOf(float[] orig, int newLength) { - final float[] copy = new float[newLength]; - System.arraycopy(orig, 0, copy, 0, Math.min(orig.length, newLength)); - return copy; + return Arrays.copyOf(orig, newLength); } - // FIXME: replace with Arrays.copyOf() in Java 1.6 + @Deprecated public static int[] copyOf(int[] orig, int newLength) { - final int[] copy = new int[newLength]; - System.arraycopy(orig, 0, copy, 0, Math.min(orig.length, newLength)); - return copy; + return Arrays.copyOf(orig, newLength); } - // FIXME: replace with Arrays.copyOf() in Java 1.6 + @Deprecated public static long[] copyOf(long[] orig, int newLength) { - final long[] copy = new long[newLength]; - System.arraycopy(orig, 0, copy, 0, Math.min(orig.length, newLength)); - return copy; + return Arrays.copyOf(orig, newLength); } - // FIXME: replace with Arrays.copyOf() in Java 1.6 + @Deprecated public static short[] copyOf(short[] orig, int newLength) { - final short[] copy = new short[newLength]; - System.arraycopy(orig, 0, copy, 0, Math.min(orig.length, newLength)); - return copy; + return Arrays.copyOf(orig, newLength); } - // FIXME: replace with Arrays.copyOf() in Java 1.6 - @SuppressWarnings("unchecked") + @Deprecated public static <T> T[] copyOf(T[] orig, int newLength) { - return (T[]) copyOf(orig, newLength, orig.getClass()); + return Arrays.copyOf(orig, newLength); } - // FIXME: replace with Arrays.copyOf() in Java 1.6 - @SuppressWarnings("unchecked") + @Deprecated public static <T,U> T[] copyOf(U[] orig, int newLength, Class<? extends T[]> newType) { - final T[] copy = - (T[]) Array.newInstance(newType.getComponentType(), newLength); - System.arraycopy(orig, 0, copy, 0, Math.min(orig.length, newLength)); - return copy; + return Arrays.copyOf(orig, newLength, newType); } - // FIXME: replace with Arrays.copyOfRange() in Java 1.6 + @Deprecated public static boolean[] copyOfRange(boolean[] orig, int from, int to) { - final int newLength = to - from; - if (newLength < 0) throw new IllegalArgumentException(); - - final boolean[] copy = new boolean[newLength]; - System.arraycopy(orig, from, copy, 0, - Math.min(orig.length - from, newLength)); - return copy; + return Arrays.copyOfRange(orig, from, to); } - // FIXME: replace with Arrays.copyOfRange() in Java 1.6 + @Deprecated public static byte[] copyOfRange(byte[] orig, int from, int to) { - final int newLength = to - from; - if (newLength < 0) throw new IllegalArgumentException(); - - final byte[] copy = new byte[newLength]; - System.arraycopy(orig, from, copy, 0, - Math.min(orig.length - from, newLength)); - return copy; + return Arrays.copyOfRange(orig, from, to); } - // FIXME: replace with Arrays.copyOfRange() in Java 1.6 + @Deprecated public static char[] copyOfRange(char[] orig, int from, int to) { - final int newLength = to - from; - if (newLength < 0) throw new IllegalArgumentException(); - - final char[] copy = new char[newLength]; - System.arraycopy(orig, from, copy, 0, - Math.min(orig.length - from, newLength)); - return copy; + return Arrays.copyOfRange(orig, from, to); } - // FIXME: replace with Arrays.copyOfRange() in Java 1.6 + @Deprecated public static double[] copyOfRange(double[] orig, int from, int to) { - final int newLength = to - from; - if (newLength < 0) throw new IllegalArgumentException(); - - final double[] copy = new double[newLength]; - System.arraycopy(orig, from, copy, 0, - Math.min(orig.length - from, newLength)); - return copy; + return Arrays.copyOfRange(orig, from, to); } - // FIXME: replace with Arrays.copyOfRange() in Java 1.6 + @Deprecated public static float[] copyOfRange(float[] orig, int from, int to) { - final int newLength = to - from; - if (newLength < 0) throw new IllegalArgumentException(); - - final float[] copy = new float[newLength]; - System.arraycopy(orig, from, copy, 0, - Math.min(orig.length - from, newLength)); - return copy; + return Arrays.copyOfRange(orig, from, to); } - // FIXME: replace with Arrays.copyOfRange() in Java 1.6 + @Deprecated public static int[] copyOfRange(int[] orig, int from, int to) { - final int newLength = to - from; - if (newLength < 0) throw new IllegalArgumentException(); - - final int[] copy = new int[newLength]; - System.arraycopy(orig, from, copy, 0, - Math.min(orig.length - from, newLength)); - return copy; + return Arrays.copyOfRange(orig, from, to); } - // FIXME: replace with Arrays.copyOfRange() in Java 1.6 + @Deprecated public static long[] copyOfRange(long[] orig, int from, int to) { - final int newLength = to - from; - if (newLength < 0) throw new IllegalArgumentException(); - - final long[] copy = new long[newLength]; - System.arraycopy(orig, from, copy, 0, - Math.min(orig.length - from, newLength)); - return copy; + return Arrays.copyOfRange(orig, from, to); } - // FIXME: replace with Arrays.copyOfRange() in Java 1.6 + @Deprecated public static short[] copyOfRange(short[] orig, int from, int to) { - final int newLength = to - from; - if (newLength < 0) throw new IllegalArgumentException(); - - final short[] copy = new short[newLength]; - System.arraycopy(orig, from, copy, 0, - Math.min(orig.length - from, newLength)); - return copy; + return Arrays.copyOfRange(orig, from, to); } - // FIXME: replace with Arrays.copyOfRange() in Java 1.6 - @SuppressWarnings("unchecked") + @Deprecated public static <T> T[] copyOfRange(T[] orig, int from, int to) { - return (T[]) copyOfRange(orig, from, to, orig.getClass()); + return Arrays.copyOfRange(orig, from, to); } - // FIXME: replace with Arrays.copyOfRange() in Java 1.6 - @SuppressWarnings("unchecked") + @Deprecated public static <T,U> T[] copyOfRange(U[] orig, int from, int to, Class<? extends T[]> newType) { - final int newLength = to - from; - if (newLength < 0) throw new IllegalArgumentException(); - - final T[] copy = - (T[]) Array.newInstance(newType.getComponentType(), newLength); - System.arraycopy(orig, from, copy, 0, - Math.min(orig.length - from, newLength)); - return copy; + return Arrays.copyOfRange(orig, from, to, newType); } public static boolean[] prepend(boolean[] orig, boolean e) { @@ -315,49 +247,49 @@ } public static boolean[] append(boolean[] orig, boolean e) { - final boolean[] tmp = copyOf(orig, orig.length+1); + final boolean[] tmp = Arrays.copyOf(orig, orig.length+1); tmp[orig.length] = e; return tmp; } public static byte[] append(byte[] orig, byte e) { - final byte[] tmp = copyOf(orig, orig.length+1); + final byte[] tmp = Arrays.copyOf(orig, orig.length+1); tmp[orig.length] = e; return tmp; } public static char[] append(char[] orig, char e) { - final char[] tmp = copyOf(orig, orig.length+1); + final char[] tmp = Arrays.copyOf(orig, orig.length+1); tmp[orig.length] = e; return tmp; } public static double[] append(double[] orig, double e) { - final double[] tmp = copyOf(orig, orig.length+1); + final double[] tmp = Arrays.copyOf(orig, orig.length+1); tmp[orig.length] = e; return tmp; } public static float[] append(float[] orig, float e) { - final float[] tmp = copyOf(orig, orig.length+1); + final float[] tmp = Arrays.copyOf(orig, orig.length+1); tmp[orig.length] = e; return tmp; } public static int[] append(int[] orig, int e) { - final int[] tmp = copyOf(orig, orig.length+1); + final int[] tmp = Arrays.copyOf(orig, orig.length+1); tmp[orig.length] = e; return tmp; } public static long[] append(long[] orig, long e) { - final long[] tmp = copyOf(orig, orig.length+1); + final long[] tmp = Arrays.copyOf(orig, orig.length+1); tmp[orig.length] = e; return tmp; } public static short[] append(short[] orig, short e) { - final short[] tmp = copyOf(orig, orig.length+1); + final short[] tmp = Arrays.copyOf(orig, orig.length+1); tmp[orig.length] = e; return tmp; } @@ -369,7 +301,7 @@ public static <T,X extends T,Y extends T> T[] append(Class<T[]> type, X[] orig, Y e) { - final T[] tmp = copyOf(orig, orig.length+1, type); + final T[] tmp = Arrays.copyOf(orig, orig.length+1, type); tmp[orig.length] = e; return tmp; } Modified: VASSAL-src/trunk/src/VASSAL/tools/SequenceEncoder.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/SequenceEncoder.java 2020-05-25 21:49:31 UTC (rev 9436) +++ VASSAL-src/trunk/src/VASSAL/tools/SequenceEncoder.java 2020-05-25 21:49:40 UTC (rev 9437) @@ -20,6 +20,7 @@ import java.awt.Color; import java.awt.event.InputEvent; +import java.util.Arrays; import java.util.Iterator; import java.util.NoSuchElementException; @@ -358,7 +359,7 @@ } if (retVal.length < minLength) { - retVal = ArrayUtils.copyOf(retVal, minLength); + retVal = Arrays.copyOf(retVal, minLength); } return retVal; Modified: VASSAL-src/trunk/src/VASSAL/tools/filechooser/ExtensionFileFilter.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/filechooser/ExtensionFileFilter.java 2020-05-25 21:49:31 UTC (rev 9436) +++ VASSAL-src/trunk/src/VASSAL/tools/filechooser/ExtensionFileFilter.java 2020-05-25 21:49:40 UTC (rev 9437) @@ -19,10 +19,10 @@ package VASSAL.tools.filechooser; import java.io.File; +import java.util.Arrays; import org.apache.commons.lang3.StringUtils; -import VASSAL.tools.ArrayUtils; /** * A generic by-extension FileFilter. @@ -40,7 +40,7 @@ public ExtensionFileFilter(String desc, String[] types) { super(); this.desc = desc + " (*" + StringUtils.join(types, ", *") + ")"; - this.types = ArrayUtils.copyOf(types); + this.types = Arrays.copyOf(types, types.length); } /** Modified: VASSAL-src/trunk/src/VASSAL/tools/imports/adc2/SymbolSet.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/imports/adc2/SymbolSet.java 2020-05-25 21:49:31 UTC (rev 9436) +++ VASSAL-src/trunk/src/VASSAL/tools/imports/adc2/SymbolSet.java 2020-05-25 21:49:40 UTC (rev 9437) @@ -36,6 +36,7 @@ import java.io.FileReader; import java.io.InputStream; import java.io.IOException; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -42,7 +43,6 @@ import javax.imageio.ImageIO; import VASSAL.build.GameModule; -import VASSAL.tools.ArrayUtils; import VASSAL.tools.filechooser.BMPFileFilter; import VASSAL.tools.imports.FileFormatException; import VASSAL.tools.imports.ImportAction; @@ -600,7 +600,7 @@ try { input = new BufferedReader(new FileReader(sdx)); - final SymbolData[] pieces = ArrayUtils.copyOf(gamePieceData); + final SymbolData[] pieces = Arrays.copyOf(gamePieceData, gamePieceData.length); String line = null; try { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uck...@us...> - 2020-05-25 21:49:34
|
Revision: 9436 http://sourceforge.net/p/vassalengine/svn/9436 Author: uckelman Date: 2020-05-25 21:49:31 +0000 (Mon, 25 May 2020) Log Message: ----------- Replaced deprecated DigestUtils.shaHex() with DigestUtils.sha1Hex(). Modified Paths: -------------- VASSAL-src/trunk/src/VASSAL/build/GameModule.java VASSAL-src/trunk/src/VASSAL/launch/AbstractLaunchAction.java VASSAL-src/trunk/src/VASSAL/launch/ModuleManagerWindow.java VASSAL-src/trunk/src/VASSAL/tools/image/tilecache/TileUtils.java Modified: VASSAL-src/trunk/src/VASSAL/build/GameModule.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/GameModule.java 2020-05-25 21:49:25 UTC (rev 9435) +++ VASSAL-src/trunk/src/VASSAL/build/GameModule.java 2020-05-25 21:49:31 UTC (rev 9436) @@ -961,7 +961,7 @@ // are properly set at this point. final String hstr = - DigestUtils.shaHex(getGameName() + "_" + getGameVersion()); + DigestUtils.sha1Hex(getGameName() + "_" + getGameVersion()); final File tc = new File(Info.getConfDir(), "tiles/" + hstr); tcache = new ImageTileDiskCache(tc.getAbsolutePath()); Modified: VASSAL-src/trunk/src/VASSAL/launch/AbstractLaunchAction.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/launch/AbstractLaunchAction.java 2020-05-25 21:49:25 UTC (rev 9435) +++ VASSAL-src/trunk/src/VASSAL/launch/AbstractLaunchAction.java 2020-05-25 21:49:31 UTC (rev 9436) @@ -262,7 +262,7 @@ final String aname = lr.module.getAbsolutePath(); final ModuleMetaData meta = new ModuleMetaData(new ZipFile(aname)); final String hstr = - DigestUtils.shaHex(meta.getName() + "_" + meta.getVersion()); + DigestUtils.sha1Hex(meta.getName() + "_" + meta.getVersion()); final File cdir = new File(Info.getConfDir(), "tiles/" + hstr); Modified: VASSAL-src/trunk/src/VASSAL/launch/ModuleManagerWindow.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/launch/ModuleManagerWindow.java 2020-05-25 21:49:25 UTC (rev 9435) +++ VASSAL-src/trunk/src/VASSAL/launch/ModuleManagerWindow.java 2020-05-25 21:49:31 UTC (rev 9436) @@ -1430,7 +1430,7 @@ } public void cleanupTileCache() { - final String hstr = DigestUtils.shaHex( + final String hstr = DigestUtils.sha1Hex( metadata.getName() + "_" + metadata.getVersion() ); Modified: VASSAL-src/trunk/src/VASSAL/tools/image/tilecache/TileUtils.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/image/tilecache/TileUtils.java 2020-05-25 21:49:25 UTC (rev 9435) +++ VASSAL-src/trunk/src/VASSAL/tools/image/tilecache/TileUtils.java 2020-05-25 21:49:31 UTC (rev 9436) @@ -393,7 +393,7 @@ * @return the name of the tile file */ public static String tileName(String iname, int tileX, int tileY, int div) { - final String sha = DigestUtils.shaHex( + final String sha = DigestUtils.sha1Hex( iname + "(" + tileX + "," + tileY + "@1:" + div ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uck...@us...> - 2020-05-25 21:49:28
|
Revision: 9435 http://sourceforge.net/p/vassalengine/svn/9435 Author: uckelman Date: 2020-05-25 21:49:25 +0000 (Mon, 25 May 2020) Log Message: ----------- Resolved layout note for Java 6. Modified Paths: -------------- VASSAL-src/trunk/src/VASSAL/tools/UsernameAndPasswordDialog.java Modified: VASSAL-src/trunk/src/VASSAL/tools/UsernameAndPasswordDialog.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/UsernameAndPasswordDialog.java 2020-05-25 21:49:21 UTC (rev 9434) +++ VASSAL-src/trunk/src/VASSAL/tools/UsernameAndPasswordDialog.java 2020-05-25 21:49:25 UTC (rev 9435) @@ -112,9 +112,6 @@ final GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); -/* - // FIXME: This is the layout code for Java 1.6 - layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); @@ -148,42 +145,7 @@ .addComponent(cancel))); layout.linkSize(ok, cancel); -*/ - layout.setAutoCreateGaps(true); - layout.setAutoCreateContainerGaps(true); - - layout.setHorizontalGroup( - layout.createParallelGroup(GroupLayout.Alignment.LEADING, true) - .addComponent(nc) - .addComponent(p1) - .addComponent(p2) - .addComponent(note) - .addGroup(layout.createSequentialGroup() - .addGap(0, 0, Integer.MAX_VALUE) - .addComponent(error) - .addGap(0, 0, Integer.MAX_VALUE)) - .addGroup(layout.createSequentialGroup() - .addGap(0, 0, Integer.MAX_VALUE) - .addComponent(ok) - .addComponent(cancel))); - - layout.setVerticalGroup( - layout.createSequentialGroup() - .addComponent(nc) - .addComponent(p1) - .addComponent(p2) - .addComponent(note) - .addComponent(error) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, - GroupLayout.DEFAULT_SIZE, Integer.MAX_VALUE) - .addGroup( - layout.createParallelGroup(GroupLayout.Alignment.BASELINE, false) - .addComponent(ok) - .addComponent(cancel))); - - layout.linkSize(new Component[]{ok, cancel}); - add(panel); pack(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uck...@us...> - 2020-05-25 21:49:23
|
Revision: 9434 http://sourceforge.net/p/vassalengine/svn/9434 Author: uckelman Date: 2020-05-25 21:49:21 +0000 (Mon, 25 May 2020) Log Message: ----------- Removed cruft. Applied some changes marked for Java 6. (!) Modified Paths: -------------- VASSAL-src/trunk/src/VASSAL/tools/swing/EDTExecutorService.java Removed Paths: ------------- VASSAL-src/trunk/src/VASSAL/tools/ThreadManager.java Deleted: VASSAL-src/trunk/src/VASSAL/tools/ThreadManager.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/ThreadManager.java 2020-05-25 21:49:16 UTC (rev 9433) +++ VASSAL-src/trunk/src/VASSAL/tools/ThreadManager.java 2020-05-25 21:49:21 UTC (rev 9434) @@ -1,140 +0,0 @@ -/* - * $Id$ - * - * Copyright (c) 2007 by Joel Uckelman - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License (LGPL) as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, copies are available - * at http://www.opensource.org. - */ - -package VASSAL.tools; - -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.Future; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -import javax.swing.SwingWorker; - -/** - * - * - * @since 3.1.0 - * @author Joel Uckelman - */ -public class ThreadManager { - private ThreadManager() { } - - private static final BlockingQueue<Runnable> requestQueue = - new LinkedBlockingQueue<>(); -/* - new LinkedBlockingQueue<Runnable>() { - @Override - public boolean offer(Runnable r) { - boolean ret = super.offer(r); - if (ret) System.out.println("queued " + r); - else System.out.println("failed to queue " + r); - - for (Iterator<Runnable> i = requestQueue.iterator(); i.hasNext(); ) { - System.out.println("in queue: " + i.next()); - } - - return ret; - } - - @Override - public Runnable take() throws InterruptedException { - Runnable r = super.take(); - System.out.println("took " + r); - - for (Iterator<Runnable> i = requestQueue.iterator(); i.hasNext(); ) { - System.out.println("in queue: " + i.next()); - } - - return r; - } - - @Override - public Runnable poll(long timeout, TimeUnit unit) throws InterruptedException { - Runnable r = super.poll(timeout, unit); - System.out.println("polled " + r); - - for (Iterator<Runnable> i = requestQueue.iterator(); i.hasNext(); ) { - System.out.println("in queue: " + i.next()); - } - - return r; - } - }; -*/ - -/* - private static final BlockingQueue<Runnable> requestQueue = - new PriorityBlockingQueue<Runnable>(20, new PriorityOrdering()); - - private static final class PriorityOrdering implements Comparator<Runnable> { - public int compare(Runnable x, Runnable y) { - return - (x instanceof Prioritizable ? ((Prioritizable) x).getPriority() : 0) - - (y instanceof Prioritizable ? ((Prioritizable) y).getPriority() : 0); - } - } -*/ - - private static final class Ex extends ThreadPoolExecutor { - public Ex(int corePoolSize, int maximumPoolSize, long keepAliveTime, - TimeUnit unit, BlockingQueue<Runnable> workQueue) { - super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue); - } - - public <V> Future<V> submit(SwingWorker<V,?> req) { - execute(req); - return req; - } - -/* - @Override - protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) { - return runnable instanceof RunnableFuture ? - (RunnableFuture<T>) runnable : super.newTaskFor(runnable, value); - } -*/ - } - -// private static final ExecutorService threadPool = -// Executors.newFixedThreadPool(2); -// Executors.newCachedThreadPool(); -// new ThreadPoolExecutor(2, 2, 60, TimeUnit.SECONDS, requestQueue); - private static final Ex threadPool = - new Ex(2, 2, 60, TimeUnit.SECONDS, requestQueue); - - // FIXME: RunnableFuture does not exist in Java 1.5. Remove this - // once we switch to 1.6. - @SuppressWarnings("unchecked") - public static <V> Future<V> submit(Runnable task) { -//System.out.println("thread queue: " + requestQueue.size()); - return (Future<V>) threadPool.submit(task); - } - - public static <V> Future<V> submit(SwingWorker<V,?> req) { - return threadPool.submit(req); - } - -/* - public static <V> Future<V> submit(RunnableFuture<V> task) { -System.out.println("thread queue: " + requestQueue.size()); - return (Future<V>) threadPool.submit(task); - } -*/ -} Modified: VASSAL-src/trunk/src/VASSAL/tools/swing/EDTExecutorService.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/swing/EDTExecutorService.java 2020-05-25 21:49:16 UTC (rev 9433) +++ VASSAL-src/trunk/src/VASSAL/tools/swing/EDTExecutorService.java 2020-05-25 21:49:21 UTC (rev 9434) @@ -19,8 +19,6 @@ package VASSAL.tools.swing; import java.awt.EventQueue; -import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.concurrent.AbstractExecutorService; @@ -104,9 +102,9 @@ return Collections.<Runnable>emptyList(); } - // FIXME: rename to newTaskFor(), mark as @Override in Java 1.6+ /** {@inheritDoc} */ - protected <T> RunnableFuture<T> newTask(final Callable<T> cable) { + @Override + protected <T> RunnableFuture<T> newTaskFor(Callable<T> cable) { return new EDTRunnableFuture<>() { @Override protected void runOnEDT() throws Exception { @@ -115,9 +113,9 @@ }; } - // FIXME: rename to newTaskFor(), mark as @Override in Java 1.6+ /** {@inheritDoc} */ - protected <T> RunnableFuture<T> newTask(final Runnable rable, T result) { + @Override + protected <T> RunnableFuture<T> newTaskFor(Runnable rable, T result) { return new EDTRunnableFuture<>(result) { @Override protected void runOnEDT() { @@ -126,36 +124,6 @@ }; } - // FIXME: remove for Java 1.6+ - /** {@inheritDoc} */ - @Override - public Future<?> submit(Runnable task) { - if (task == null) throw new NullPointerException(); - final RunnableFuture<Void> ftask = newTask(task, null); - execute(ftask); - return ftask; - } - - // FIXME: remove for Java 1.6+ - /** {@inheritDoc} */ - @Override - public <T> Future<T> submit(Runnable task, T result) { - if (task == null) throw new NullPointerException(); - final RunnableFuture<T> ftask = newTask(task, result); - execute(ftask); - return ftask; - } - - // FIXME: remove for Java 1.6+ - /** {@inheritDoc} */ - @Override - public <T> Future<T> submit(Callable<T> task) { - if (task == null) throw new NullPointerException(); - final RunnableFuture<T> ftask = newTask(task); - execute(ftask); - return ftask; - } - /** * Submits a {@code EDTRunnableFuture} task for execution and returns it. * @@ -170,100 +138,8 @@ return task; } - // FIXME: remove for Java 1.6+ /** {@inheritDoc} */ @Override - public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) - throws InterruptedException { - if (tasks == null) throw new NullPointerException(); - - final List<Future<T>> futures = new ArrayList<>(tasks.size()); - boolean done = false; - try { - for (Callable<T> t : tasks) { - final RunnableFuture<T> f = newTask(t); - futures.add(f); - execute(f); - } - - for (Future<T> f : futures) { - if (!f.isDone()) { - try { - f.get(); - } - catch (CancellationException | ExecutionException ignore) { - } - } - } - - done = true; - return futures; - } - finally { - if (!done) { - for (Future<T> f : futures) f.cancel(true); - } - } - } - - // FIXME: remove for Java 1.6+ - /** {@inheritDoc} */ - @Override - public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, - long timeout, TimeUnit unit) - throws InterruptedException { - if (tasks == null) throw new NullPointerException(); - if (unit == null) throw new NullPointerException(); - - long nanos = unit.toNanos(timeout); - final List<Future<T>> futures = new ArrayList<>(tasks.size()); - boolean done = false; - try { - for (Callable<T> t : tasks) futures.add(newTask(t)); - - long lastTime = System.nanoTime(); - - // Interleave time checks and calls to execute in case - // executor doesn't have any/much parallelism. - for (Future<T> future : futures) { - execute((Runnable) future); - final long now = System.nanoTime(); - nanos -= now - lastTime; - lastTime = now; - if (nanos <= 0) return futures; - } - - for (Future<T> f : futures) { - if (!f.isDone()) { - if (nanos <= 0) return futures; - - try { - f.get(nanos, TimeUnit.NANOSECONDS); - } - catch (CancellationException | ExecutionException ignore) { - } - catch (TimeoutException toe) { - return futures; - } - - final long now = System.nanoTime(); - nanos -= now - lastTime; - lastTime = now; - } - } - - done = true; - return futures; - } - finally { - if (!done) { - for (Future<T> f : futures) f.cancel(true); - } - } - } - - /** {@inheritDoc} */ - @Override public void execute(Runnable r) { if (r == null) throw new NullPointerException(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uck...@us...> - 2020-05-25 21:49:18
|
Revision: 9433 http://sourceforge.net/p/vassalengine/svn/9433 Author: uckelman Date: 2020-05-25 21:49:16 +0000 (Mon, 25 May 2020) Log Message: ----------- Fixed IOUtils.toString(InputStream) deprecation warning. Modified Paths: -------------- VASSAL-src/trunk/src/VASSAL/build/widget/HtmlChart.java VASSAL-src/trunk/src/VASSAL/tools/BugUtils.java VASSAL-src/trunk/src/VASSAL/tools/version/VersionUtils.java Modified: VASSAL-src/trunk/src/VASSAL/build/widget/HtmlChart.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/widget/HtmlChart.java 2020-05-25 21:49:10 UTC (rev 9432) +++ VASSAL-src/trunk/src/VASSAL/build/widget/HtmlChart.java 2020-05-25 21:49:16 UTC (rev 9433) @@ -27,6 +27,7 @@ import java.io.File; import java.io.InputStream; import java.io.IOException; +import java.nio.charset.StandardCharsets; import javax.swing.JEditorPane; import javax.swing.JLabel; @@ -96,7 +97,7 @@ String s = null; try (InputStream inner = mda.getInputStream(fname); InputStream in = new BufferedInputStream(inner)) { - s = IOUtils.toString(in); + s = IOUtils.toString(in, StandardCharsets.UTF_8); } catch (IOException e) { ErrorDialog.dataError(new BadDataReport(this, Resources.getString("Error.not_found", "Chart"), fname, e)); Modified: VASSAL-src/trunk/src/VASSAL/tools/BugUtils.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/BugUtils.java 2020-05-25 21:49:10 UTC (rev 9432) +++ VASSAL-src/trunk/src/VASSAL/tools/BugUtils.java 2020-05-25 21:49:16 UTC (rev 9433) @@ -4,6 +4,7 @@ import java.io.FileReader; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; import VASSAL.Info; import VASSAL.tools.io.IOUtils; @@ -38,7 +39,7 @@ */ try (InputStream in = pb.post(url)) { - final String result = IOUtils.toString(in); + final String result = IOUtils.toString(in, StandardCharsets.UTF_8); // script should return zero on success, otherwise it failed try { Modified: VASSAL-src/trunk/src/VASSAL/tools/version/VersionUtils.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/version/VersionUtils.java 2020-05-25 21:49:10 UTC (rev 9432) +++ VASSAL-src/trunk/src/VASSAL/tools/version/VersionUtils.java 2020-05-25 21:49:16 UTC (rev 9433) @@ -3,6 +3,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.nio.charset.StandardCharsets; import VASSAL.Info; import VASSAL.tools.io.IOUtils; @@ -34,7 +35,7 @@ private static VassalVersion getVersion(String url) throws IOException { try (InputStream in = new URL(url).openStream()) { final VassalVersion version = - new VassalVersion(IOUtils.toString(in).trim()); + new VassalVersion(IOUtils.toString(in, StandardCharsets.UTF_8).trim()); return version; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uck...@us...> - 2020-05-25 21:49:12
|
Revision: 9432 http://sourceforge.net/p/vassalengine/svn/9432 Author: uckelman Date: 2020-05-25 21:49:10 +0000 (Mon, 25 May 2020) Log Message: ----------- Replaced VASSAL.tools.concurrent.RunnableFuture with java.util.concurrent.RunnableFuture. Modified Paths: -------------- VASSAL-src/trunk/src/VASSAL/tools/concurrent/SettableRunnableFuture.java VASSAL-src/trunk/src/VASSAL/tools/swing/EDTExecutorService.java Removed Paths: ------------- VASSAL-src/trunk/src/VASSAL/tools/concurrent/RunnableFuture.java Deleted: VASSAL-src/trunk/src/VASSAL/tools/concurrent/RunnableFuture.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/concurrent/RunnableFuture.java 2020-05-25 21:49:03 UTC (rev 9431) +++ VASSAL-src/trunk/src/VASSAL/tools/concurrent/RunnableFuture.java 2020-05-25 21:49:10 UTC (rev 9432) @@ -1,40 +0,0 @@ -/* - * $Id$ - * - * Copyright (c) 2010 by Joel Uckelman - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License (LGPL) as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, copies are available - * at http://www.opensource.org. - */ -package VASSAL.tools.concurrent; - -import java.util.concurrent.Future; - -/** - * A {@link Future} that is {@link Runnable}. - * - * This class exists for Java 1.5 compatibility. When we switch to Java 1.6, - * this class should be removed and replaced by - * {@link java.util.concurrent.RunnableFuture}. - * - * - * @param <V> the result type returned by this {@code Future}'s - * {@code get} method - * - * @author Joel Uckelman - * @since 3.2.0 - */ -public interface RunnableFuture<V> extends Runnable, Future<V> { - @Override - public void run(); -} Modified: VASSAL-src/trunk/src/VASSAL/tools/concurrent/SettableRunnableFuture.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/concurrent/SettableRunnableFuture.java 2020-05-25 21:49:03 UTC (rev 9431) +++ VASSAL-src/trunk/src/VASSAL/tools/concurrent/SettableRunnableFuture.java 2020-05-25 21:49:10 UTC (rev 9432) @@ -19,6 +19,8 @@ package VASSAL.tools.concurrent; +import java.util.concurrent.RunnableFuture; + /** * A {@link SettableFuture} that is a {@link RunnableFuture}. */ Modified: VASSAL-src/trunk/src/VASSAL/tools/swing/EDTExecutorService.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/swing/EDTExecutorService.java 2020-05-25 21:49:03 UTC (rev 9431) +++ VASSAL-src/trunk/src/VASSAL/tools/swing/EDTExecutorService.java 2020-05-25 21:49:10 UTC (rev 9432) @@ -30,13 +30,12 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.RunnableFuture; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.ReentrantLock; -import VASSAL.tools.concurrent.RunnableFuture; - /** * An {@link ExecutorService} which submits to Event Dispatch Thread. * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <uck...@us...> - 2020-05-25 21:49:05
|
Revision: 9431 http://sourceforge.net/p/vassalengine/svn/9431 Author: uckelman Date: 2020-05-25 21:49:03 +0000 (Mon, 25 May 2020) Log Message: ----------- Replaced calls to deprecated IOUtils.closeQuietly() with Java's automatic resource management (separated out nested streams) Modified Paths: -------------- VASSAL-src/trunk/src/VASSAL/build/module/GameState.java VASSAL-src/trunk/src/VASSAL/build/module/map/ImageSaver.java VASSAL-src/trunk/src/VASSAL/build/module/metadata/ExtensionMetaData.java VASSAL-src/trunk/src/VASSAL/build/module/metadata/MetaDataFactory.java VASSAL-src/trunk/src/VASSAL/build/module/metadata/ModuleMetaData.java VASSAL-src/trunk/src/VASSAL/build/module/metadata/SaveMetaData.java VASSAL-src/trunk/src/VASSAL/build/widget/HtmlChart.java VASSAL-src/trunk/src/VASSAL/chat/HttpRequestWrapper.java VASSAL-src/trunk/src/VASSAL/chat/jabber/JabberClient.java VASSAL-src/trunk/src/VASSAL/configure/SavedGameUpdaterDialog.java VASSAL-src/trunk/src/VASSAL/configure/SoundConfigurer.java VASSAL-src/trunk/src/VASSAL/i18n/TranslateVassalWindow.java VASSAL-src/trunk/src/VASSAL/i18n/Translation.java VASSAL-src/trunk/src/VASSAL/i18n/VassalTranslation.java VASSAL-src/trunk/src/VASSAL/launch/BasicModule.java VASSAL-src/trunk/src/VASSAL/launch/ModuleManager.java VASSAL-src/trunk/src/VASSAL/launch/ShutDownAction.java VASSAL-src/trunk/src/VASSAL/launch/TilingHandler.java VASSAL-src/trunk/src/VASSAL/preferences/Prefs.java VASSAL-src/trunk/src/VASSAL/preferences/ReadOnlyPrefs.java VASSAL-src/trunk/src/VASSAL/tools/BugUtils.java VASSAL-src/trunk/src/VASSAL/tools/Mp3AudioClip.java VASSAL-src/trunk/src/VASSAL/tools/ZipUpdater.java VASSAL-src/trunk/src/VASSAL/tools/image/FileImageTypeConverter.java VASSAL-src/trunk/src/VASSAL/tools/image/JPEGDecoder.java VASSAL-src/trunk/src/VASSAL/tools/image/svg/SVGRenderer.java VASSAL-src/trunk/src/VASSAL/tools/image/tilecache/TileUtils.java VASSAL-src/trunk/src/VASSAL/tools/image/tilecache/ZipFileImageTiler.java VASSAL-src/trunk/src/VASSAL/tools/imageop/SourceOpBitmapImpl.java VASSAL-src/trunk/src/VASSAL/tools/imageop/SourceOpSVGImpl.java VASSAL-src/trunk/src/VASSAL/tools/imports/adc2/ADC2Module.java VASSAL-src/trunk/src/VASSAL/tools/imports/adc2/MapBoard.java VASSAL-src/trunk/src/VASSAL/tools/imports/adc2/SymbolSet.java VASSAL-src/trunk/src/VASSAL/tools/io/DeobfuscatingInputStream.java VASSAL-src/trunk/src/VASSAL/tools/io/ObfuscatingOutputStream.java VASSAL-src/trunk/src/VASSAL/tools/io/ZipArchive.java Modified: VASSAL-src/trunk/src/VASSAL/build/module/GameState.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/module/GameState.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/build/module/GameState.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -750,16 +750,10 @@ out.write(save.getBytes(StandardCharsets.UTF_8)); } - FileArchive archive = null; - try { - archive = new ZipArchive(f); + try (FileArchive archive = new ZipArchive(f)) { archive.add(SAVEFILE_ZIP_ENTRY, ba.toInputStream()); (new SaveMetaData()).save(archive); - archive.close(); } - finally { - IOUtils.closeQuietly(archive); - } Launcher.getInstance().sendSaveCmd(f); Modified: VASSAL-src/trunk/src/VASSAL/build/module/map/ImageSaver.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/module/map/ImageSaver.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/build/module/map/ImageSaver.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -66,7 +66,6 @@ import VASSAL.tools.WriteErrorDialog; import VASSAL.tools.filechooser.FileChooser; import VASSAL.tools.filechooser.PNGFileFilter; -import VASSAL.tools.io.IOUtils; import VASSAL.tools.swing.ProgressDialog; // FIXME: Replace this in 3.2 with tiling code. @@ -385,10 +384,7 @@ public void writeAborted(ImageWriter source) { } }); - ImageOutputStream os = null; - try { - os = ImageIO.createImageOutputStream(f); - + try (ImageOutputStream os = ImageIO.createImageOutputStream(f)) { if (os == null) { throw new IOException("Failed to write file " + f.getAbsolutePath()); } @@ -395,11 +391,9 @@ iw.setOutput(os); iw.write(img); - os.close(); } finally { iw.dispose(); - IOUtils.closeQuietly(os); } } Modified: VASSAL-src/trunk/src/VASSAL/build/module/metadata/ExtensionMetaData.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/module/metadata/ExtensionMetaData.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/build/module/metadata/ExtensionMetaData.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -35,7 +35,6 @@ import VASSAL.build.GameModule; import VASSAL.build.module.ModuleExtension; import VASSAL.tools.ArchiveWriter; -import VASSAL.tools.io.IOUtils; public class ExtensionMetaData extends AbstractMetaData { private static final Logger logger = @@ -124,10 +123,12 @@ * - Check it has a Zip Entry named buildfile * - If it has a metadata file, read and parse it. * - * @param file Module File + * Closes the Zip file. + * + * @param zip Module File */ public void read(ZipFile zip) { - try { + try (zip) { // Try to parse the metadata. Failure is not catastrophic, we can // treat it like an old-style module with no metadata and parse // the first lines of the buildFile. @@ -162,8 +163,6 @@ if (moduleData == null) { moduleData = buildFileModuleData; } - - zip.close(); } catch (SAXEndException e) { // Indicates End of module/extension parsing. not an error. @@ -171,9 +170,6 @@ catch (IOException | SAXException e) { logger.error("", e); } - finally { - IOUtils.closeQuietly(zip); - } } /** Modified: VASSAL-src/trunk/src/VASSAL/build/module/metadata/MetaDataFactory.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/module/metadata/MetaDataFactory.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/build/module/metadata/MetaDataFactory.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -19,8 +19,9 @@ import java.io.BufferedReader; import java.io.File; +import java.io.InputStream; +import java.io.InputStreamReader; import java.io.IOException; -import java.io.InputStreamReader; import java.util.zip.ZipEntry; import java.util.zip.ZipException; import java.util.zip.ZipFile; @@ -31,7 +32,6 @@ import VASSAL.build.GameModule; import VASSAL.build.module.GameState; import VASSAL.tools.imports.ImportAction; -import VASSAL.tools.io.IOUtils; public class MetaDataFactory { private static final Logger logger = @@ -56,10 +56,8 @@ if (file == null || !file.exists() || !file.isFile()) return null; - ZipFile zip = null; - try { + try (ZipFile zip = new ZipFile(file)) { // Check it is a Zip file - zip = new ZipFile(file); // Check if it is a Save Game file ZipEntry entry = zip.getEntry(GameState.SAVEFILE_ZIP_ENTRY); @@ -85,29 +83,20 @@ } // read the first few lines of the buildFile - BufferedReader br = null; - try { - br = new BufferedReader(new InputStreamReader(zip - .getInputStream(buildFileEntry))); + try (InputStream zin = zip.getInputStream(buildFileEntry); + InputStreamReader isr = new InputStreamReader(zin); + BufferedReader br = new BufferedReader(isr)) { for (int i = 0; i < 10; i++) { final String s = br.readLine(); if (s.indexOf(BUILDFILE_MODULE_ELEMENT1) > 0 || s.indexOf(BUILDFILE_MODULE_ELEMENT2) > 0) { - br.close(); return new ModuleMetaData(zip); } else if (s.indexOf(BUILDFILE_EXTENSION_ELEMENT) > 0) { - br.close(); return new ExtensionMetaData(zip); } } - br.close(); } - finally { - IOUtils.closeQuietly(br); - } - - zip.close(); } catch (ZipException e) { // It is not a Zip file, check for an Importable file @@ -116,9 +105,6 @@ catch (IOException e) { logger.error("", e); } - finally { - IOUtils.closeQuietly(zip); - } return null; } Modified: VASSAL-src/trunk/src/VASSAL/build/module/metadata/ModuleMetaData.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/module/metadata/ModuleMetaData.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/build/module/metadata/ModuleMetaData.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -19,6 +19,7 @@ package VASSAL.build.module.metadata; import java.io.BufferedInputStream; +import java.io.InputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -33,7 +34,6 @@ import org.xml.sax.helpers.DefaultHandler; import VASSAL.build.GameModule; -import VASSAL.tools.io.IOUtils; /** * @@ -106,12 +106,14 @@ * - Check it has a Zip Entry named buildfile * - If it has a metadata file, read and parse it. * - * @param file Module File + * Closes the {@link ZipFile}. + * + * @param zip Module File */ public void read(ZipFile zip) { version = ""; - try { + try (zip) { // Try to parse the metadata. Failure is not catastrophic, we can // treat it like an old-style module with no metadata and parse // the first lines of the buildFile @@ -128,10 +130,8 @@ handler = new MetadataXMLHandler(); } - BufferedInputStream in = null; - try { - in = new BufferedInputStream(zip.getInputStream(data)); - + try (InputStream zin = zip.getInputStream(data); + BufferedInputStream in = new BufferedInputStream(zin)) { synchronized (parser) { parser.setContentHandler(handler); parser.setDTDHandler(handler); @@ -139,14 +139,7 @@ parser.setErrorHandler(handler); parser.parse(new InputSource(in)); } - - in.close(); } - finally { - IOUtils.closeQuietly(in); - } - - zip.close(); } catch (SAXEndException e) { // Indicates End of module/extension parsing. not an error. @@ -154,9 +147,6 @@ catch (IOException | SAXException e) { logger.error("", e); } - finally { - IOUtils.closeQuietly(zip); - } } /** Modified: VASSAL-src/trunk/src/VASSAL/build/module/metadata/SaveMetaData.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/module/metadata/SaveMetaData.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/build/module/metadata/SaveMetaData.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -19,6 +19,7 @@ package VASSAL.build.module.metadata; import java.io.BufferedInputStream; +import java.io.InputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -35,7 +36,6 @@ import VASSAL.build.GameModule; import VASSAL.i18n.Resources; import VASSAL.tools.io.FileArchive; -import VASSAL.tools.io.IOUtils; /** * Class representing the metadata for a Save Game/Log File. Details @@ -129,10 +129,12 @@ * Check that it has a Zip Entry named savedgame. * If it has a metadata file, read and parse it. * - * @param file Saved Game File + * Closes the {@link ZipFile} + * + * @param zip Saved Game File */ public void read(ZipFile zip) { - try { + try (zip) { // Try to parse the metadata. Failure is not catastrophic, we can // treat it like an old-style save with no metadata. final ZipEntry data = zip.getEntry(getZipEntryName()); @@ -142,10 +144,8 @@ final XMLHandler handler = new XMLHandler(); // parse! parse! - BufferedInputStream in = null; - try { - in = new BufferedInputStream(zip.getInputStream(data)); - + try (InputStream zin = zip.getInputStream(data); + BufferedInputStream in = new BufferedInputStream(zin)) { synchronized (parser) { parser.setContentHandler(handler); parser.setDTDHandler(handler); @@ -153,23 +153,13 @@ parser.setErrorHandler(handler); parser.parse(new InputSource(in)); } - - in.close(); } - finally { - IOUtils.closeQuietly(in); - } // read the matching Module data moduleData = new ModuleMetaData(zip); - - zip.close(); } catch (IOException | SAXException e) { logger.error("", e); } - finally { - IOUtils.closeQuietly(zip); - } } } Modified: VASSAL-src/trunk/src/VASSAL/build/widget/HtmlChart.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/widget/HtmlChart.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/build/widget/HtmlChart.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -25,8 +25,8 @@ import java.awt.event.MouseListener; import java.io.BufferedInputStream; import java.io.File; +import java.io.InputStream; import java.io.IOException; -import java.io.InputStream; import javax.swing.JEditorPane; import javax.swing.JLabel; @@ -48,6 +48,7 @@ import VASSAL.build.Widget; import VASSAL.build.module.documentation.HelpFile; import VASSAL.i18n.Resources; +import VASSAL.tools.DataArchive; import VASSAL.tools.ErrorDialog; import VASSAL.tools.ReadErrorDialog; import VASSAL.tools.ScrollPane; @@ -91,20 +92,15 @@ private String getFile(final String fname) { if (fname == null) return null; + final DataArchive mda = GameModule.getGameModule().getDataArchive(); String s = null; - InputStream in = null; - try { - in = new BufferedInputStream( - GameModule.getGameModule().getDataArchive().getInputStream(fname)); - s = IOUtils.toString(in); - in.close(); + try (InputStream inner = mda.getInputStream(fname); + InputStream in = new BufferedInputStream(inner)) { + s = IOUtils.toString(in); } catch (IOException e) { - ErrorDialog.dataError(new BadDataReport(this, Resources.getString("Error.not_found", "Chart"),fname,e)); + ErrorDialog.dataError(new BadDataReport(this, Resources.getString("Error.not_found", "Chart"), fname, e)); } - finally { - IOUtils.closeQuietly(in); - } return s; } Modified: VASSAL-src/trunk/src/VASSAL/chat/HttpRequestWrapper.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/HttpRequestWrapper.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/chat/HttpRequestWrapper.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.OutputStream; import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; @@ -32,8 +33,6 @@ import java.util.List; import java.util.Properties; -import VASSAL.tools.io.IOUtils; - /** * Performs Get and Post operations to a given URL */ @@ -49,10 +48,8 @@ } private List<String> readLines(InputStream is) throws IOException { - BufferedReader in = null; - try { - in = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); //$NON-NLS-1$ - + try (InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8); + BufferedReader in = new BufferedReader(isr)) { final ArrayList<String> l = new ArrayList<>(); String line; while ((line = in.readLine()) != null) l.add(line); @@ -59,9 +56,6 @@ return l; } - finally { - IOUtils.closeQuietly(in); - } } /** @@ -88,7 +82,9 @@ final URLConnection conn = new URL(url).openConnection(); conn.setUseCaches(false); - return readLines(conn.getInputStream()); + try (InputStream in = conn.getInputStream()) { + return readLines(in); + } } public List<String> doPost(Properties p) throws IOException { @@ -116,15 +112,13 @@ conn.setUseCaches(false); // conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); - DataOutputStream out = null; - try { - out = new DataOutputStream(conn.getOutputStream()); + try (OutputStream co = conn.getOutputStream(); + DataOutputStream out = new DataOutputStream(co)) { out.writeBytes(content); } - finally { - IOUtils.closeQuietly(out); - } - return readLines(conn.getInputStream()); + try (InputStream in = conn.getInputStream()) { + return readLines(in); + } } } Modified: VASSAL-src/trunk/src/VASSAL/chat/jabber/JabberClient.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/jabber/JabberClient.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/chat/jabber/JabberClient.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -657,22 +657,15 @@ * @return encoded text */ protected String encodeMessage(String clearText) { - ObfuscatingOutputStream out = null; - final FastByteArrayOutputStream ba = new FastByteArrayOutputStream(); - - try { - out = new ObfuscatingOutputStream(ba); + try (FastByteArrayOutputStream ba = new FastByteArrayOutputStream(); + ObfuscatingOutputStream out = new ObfuscatingOutputStream(ba)) { out.write(clearText.getBytes(StandardCharsets.UTF_8)); //$NON-NLS-1$ + return new String(ba.toByteArray()); } catch (IOException e) { e.printStackTrace(); + return ""; } - finally { - IOUtils.closeQuietly(out); - } - final String encodedText = new String(ba.toByteArray()); - IOUtils.closeQuietly(ba); - return encodedText; } /** @@ -682,23 +675,14 @@ * @return decoded text */ protected String decodeMessage(String encodedMessage) { - final ByteArrayInputStream ba = new ByteArrayInputStream(encodedMessage.getBytes()); - DeobfuscatingInputStream in = null; - String clearText = ""; - - try { - in = new DeobfuscatingInputStream(ba); - clearText = IOUtils.toString(in, StandardCharsets.UTF_8); //$NON-NLS-1$ + try (ByteArrayInputStream ba = new ByteArrayInputStream(encodedMessage.getBytes()); + DeobfuscatingInputStream in = new DeobfuscatingInputStream(ba)) { + return IOUtils.toString(in, StandardCharsets.UTF_8); //$NON-NLS-1$ } catch (IOException e) { e.printStackTrace(); + return ""; } - finally { - IOUtils.closeQuietly(ba); - IOUtils.closeQuietly(in); - } - - return clearText; } /** Modified: VASSAL-src/trunk/src/VASSAL/configure/SavedGameUpdaterDialog.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/configure/SavedGameUpdaterDialog.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/configure/SavedGameUpdaterDialog.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -29,7 +29,9 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.InputStream; import java.io.IOException; +import java.io.OutputStream; import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; import java.util.Properties; @@ -53,7 +55,6 @@ import VASSAL.tools.ErrorDialog; import VASSAL.tools.SavedGameUpdater; import VASSAL.tools.ScrollPane; -import VASSAL.tools.io.IOUtils; public class SavedGameUpdaterDialog extends JDialog { private static final long serialVersionUID = 1L; @@ -227,20 +228,13 @@ p.put(MODULE_NAME_KEY, GameModule.getGameModule().getGameName()); p.put(VERSION_KEY, GameModule.getGameModule().getGameVersion()); - BufferedOutputStream out = null; - try { - out = new BufferedOutputStream( - new FileOutputStream(fc.getSelectedFile())); + try (OutputStream fout = new FileOutputStream(fc.getSelectedFile()); + BufferedOutputStream out = new BufferedOutputStream(fout)) { p.store(out, null); - out.close(); } - // FIXME: review error message catch (IOException e) { - showErrorMessage(e, "Export failed","Unable to write info"); + showErrorMessage(e, "Export failed", "Unable to write info"); } - finally { - IOUtils.closeQuietly(out); - } } } @@ -249,11 +243,9 @@ if (JFileChooser.CANCEL_OPTION != fc.showOpenDialog(this)) { oldPieceInfo = new Properties(); - BufferedInputStream in = null; - try { - in = new BufferedInputStream(new FileInputStream(fc.getSelectedFile())); + try (InputStream fin = new FileInputStream(fc.getSelectedFile()); + BufferedInputStream in = new BufferedInputStream(fin)) { oldPieceInfo.load(in); - in.close(); String moduleVersion = oldPieceInfo.getProperty(VERSION_KEY); String moduleName = oldPieceInfo.getProperty(MODULE_NAME_KEY); @@ -280,9 +272,6 @@ showErrorMessage(e, "Import failed", "Malformed input file"); oldPieceInfo = null; } - finally { - IOUtils.closeQuietly(in); - } } updateButton.setEnabled(oldPieceInfo != null); } Modified: VASSAL-src/trunk/src/VASSAL/configure/SoundConfigurer.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/configure/SoundConfigurer.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/configure/SoundConfigurer.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -42,7 +42,6 @@ import VASSAL.tools.URLUtils; import VASSAL.tools.filechooser.AudioFileFilter; import VASSAL.tools.filechooser.FileChooser; -import VASSAL.tools.io.IOUtils; /** * Configurer for specifying a Clip. This class is intended to allow @@ -165,23 +164,17 @@ return new AudioClipFactory() { @Override public AudioClip getAudioClip(URL url) { - try { - final InputStream in = url.openStream(); - try { - if (url.toString().toLowerCase().endsWith(".mp3")) { - return new Mp3AudioClip(url); - } - else { - return new AudioSystemClip(in); - } + if (url.toString().toLowerCase().endsWith(".mp3")) { + return new Mp3AudioClip(url); + } + else { + try (InputStream in = url.openStream()) { + return new AudioSystemClip(in); } - finally { - IOUtils.closeQuietly(in); + catch (IOException e) { + return null; } } - catch (IOException e) { - return null; - } } }; } Modified: VASSAL-src/trunk/src/VASSAL/i18n/TranslateVassalWindow.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/i18n/TranslateVassalWindow.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/i18n/TranslateVassalWindow.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -48,7 +48,6 @@ import VASSAL.tools.WriteErrorDialog; import VASSAL.tools.filechooser.ExtensionFileFilter; import VASSAL.tools.filechooser.FileChooser; -import VASSAL.tools.io.IOUtils; public class TranslateVassalWindow extends TranslateWindow { private static final long serialVersionUID = 1L; @@ -107,19 +106,13 @@ final String filename = "VASSAL_" + l + ".properties"; final InputStream is = getClass().getResourceAsStream(filename); if (is != null) { - BufferedInputStream in = null; - try { - in = new BufferedInputStream(is); - ((VassalTranslation)target).loadProperties(in); + try (BufferedInputStream in = new BufferedInputStream(is)) { + ((VassalTranslation) target).loadProperties(in); ((MyTableModel) keyTable.getModel()).fireTableDataChanged(); - in.close(); } catch (IOException e) { ReadErrorDialog.error(e, filename); } - finally { - IOUtils.closeQuietly(in); - } } } else { @@ -220,18 +213,13 @@ localeConfig.setValue(locale); } - BufferedInputStream in = null; - try { - in = new BufferedInputStream(new FileInputStream(file)); + try (InputStream fin = new FileInputStream(file); + BufferedInputStream in = new BufferedInputStream(fin)) { ((VassalTranslation) target).loadProperties(in); - in.close(); } catch (IOException e) { ReadErrorDialog.error(e, file); } - finally { - IOUtils.closeQuietly(in); - } ((MyTableModel) keyTable.getModel()).fireTableDataChanged(); } Modified: VASSAL-src/trunk/src/VASSAL/i18n/Translation.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/i18n/Translation.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/i18n/Translation.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -21,6 +21,7 @@ import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.FileNotFoundException; +import java.io.InputStream; import java.io.IOException; import java.util.Locale; import java.util.Properties; @@ -33,8 +34,8 @@ import VASSAL.configure.Configurer; import VASSAL.configure.ConfigurerFactory; import VASSAL.tools.ArchiveWriter; +import VASSAL.tools.DataArchive; import VASSAL.tools.ReadErrorDialog; -import VASSAL.tools.io.IOUtils; public class Translation extends AbstractConfigurable implements Comparable<Translation> { @@ -178,27 +179,17 @@ localProperties = new Properties(); } - if (GameModule.getGameModule() != null) { - BufferedInputStream in = null; - try { - try { - in = new BufferedInputStream( - GameModule.getGameModule() - .getDataArchive() - .getInputStream(getBundleFileName()) - ); - } - catch (FileNotFoundException e) { - // ignore, properties have not been saved yet - dirty = false; - return; - } - + final GameModule g = GameModule.getGameModule(); + if (g != null) { + final DataArchive mda = g.getDataArchive(); + try (InputStream inner = mda.getInputStream(getBundleFileName()); + BufferedInputStream in = new BufferedInputStream(inner)) { localProperties.load(in); - in.close(); } - finally { - IOUtils.closeQuietly(in); + catch (FileNotFoundException e) { + // ignore, properties have not been saved yet + dirty = false; + return; } } @@ -206,21 +197,11 @@ } protected VassalResourceBundle getBundle() throws IOException { - BufferedInputStream in = null; - try { - in = new BufferedInputStream( - GameModule.getGameModule() - .getDataArchive() - .getInputStream(getBundleFileName()) - ); - - final VassalResourceBundle b = new VassalResourceBundle(in); - in.close(); - return b; + final DataArchive mda = GameModule.getGameModule().getDataArchive(); + try (InputStream inner = mda.getInputStream(getBundleFileName()); + BufferedInputStream in = new BufferedInputStream(inner)) { + return new VassalResourceBundle(in); } - finally { - IOUtils.closeQuietly(in); - } } /** Modified: VASSAL-src/trunk/src/VASSAL/i18n/VassalTranslation.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/i18n/VassalTranslation.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/i18n/VassalTranslation.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -23,14 +23,14 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.InputStream; import java.io.IOException; -import java.io.InputStream; +import java.io.OutputStream; import java.util.Arrays; import java.util.Locale; import java.util.Properties; import VASSAL.tools.ReadErrorDialog; -import VASSAL.tools.io.IOUtils; /** * Utility class to allow translation of VASSAL using the Component @@ -46,22 +46,14 @@ public VassalTranslation() { setConfigureName("VASSAL"); - final InputStream is = getClass().getResourceAsStream("VASSAL.properties"); - try { - if (is != null) { - BufferedInputStream in = null; - try { - in = new BufferedInputStream(is); - baseValues.load(in); - in.close(); - } - finally { - IOUtils.closeQuietly(in); - } - } - else { + try (InputStream is = getClass().getResourceAsStream("VASSAL.properties")) { + if (is == null) { throw new FileNotFoundException("VASSAL.properties not found"); } + + try (BufferedInputStream in = new BufferedInputStream(is)) { + baseValues.load(in); + } } catch (IOException e) { ReadErrorDialog.error(e, "VASSAL.properties"); @@ -116,26 +108,17 @@ } public void saveProperties(File file, Locale locale) throws IOException { - BufferedOutputStream out = null; - try { - out = new BufferedOutputStream(new FileOutputStream(file)); + try (OutputStream fout = new FileOutputStream(file); + BufferedOutputStream out = new BufferedOutputStream(fout)) { localProperties.store(out, locale.getDisplayName()); - out.close(); dirty = false; } - finally { - IOUtils.closeQuietly(out); - } } protected void loadProperties(InputStream in) throws IOException { - try { + try (in) { localProperties.load(in); dirty = false; - in.close(); } - finally { - IOUtils.closeQuietly(in); - } } } Modified: VASSAL-src/trunk/src/VASSAL/launch/BasicModule.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/launch/BasicModule.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/launch/BasicModule.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -24,6 +24,7 @@ import java.beans.PropertyChangeSupport; import java.io.BufferedInputStream; import java.io.File; +import java.io.InputStream; import java.io.IOException; import org.slf4j.Logger; @@ -68,7 +69,6 @@ import VASSAL.tools.DataArchive; import VASSAL.tools.ReflectionUtils; import VASSAL.tools.SequenceEncoder; -import VASSAL.tools.io.IOUtils; import VASSAL.tools.menu.MenuManager; public class BasicModule extends GameModule { @@ -94,27 +94,19 @@ } else { // existing module - BufferedInputStream in = null; - try { - try { - in = new BufferedInputStream(darch.getInputStream(BUILDFILE)); - } + try (InputStream inner = darch.getInputStream(BUILDFILE); + BufferedInputStream in = new BufferedInputStream(inner)) { + final Document doc = Builder.createDocument(in); + build(doc.getDocumentElement()); + } + catch (IOException e) { // FIXME: review error message // FIXME: this should be more specific, to separate the case where // we have failed I/O from when we read ok but have no module - catch (IOException e) { - throw new IOException( - Resources.getString("BasicModule.not_a_module"), //$NON-NLS-1$ - e); - } - - final Document doc = Builder.createDocument(in); - build(doc.getDocumentElement()); - in.close(); + throw new IOException( + Resources.getString("BasicModule.not_a_module"), //$NON-NLS-1$ + e); } - finally { - IOUtils.closeQuietly(in); - } } MenuManager.getInstance().addAction("Prefs.edit_preferences", Modified: VASSAL-src/trunk/src/VASSAL/launch/ModuleManager.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/launch/ModuleManager.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/launch/ModuleManager.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -139,11 +139,9 @@ int port = 0; long key = 0; - RandomAccessFile kraf = null; FileLock klock = null; - try { + try (RandomAccessFile kraf = new RandomAccessFile(keyfile, "rw")) { // acquire an exclusive lock on the key file - kraf = new RandomAccessFile(keyfile, "rw"); try { klock = kraf.getChannel().lock(); @@ -193,8 +191,6 @@ // read the security key from the key file key = kraf.readLong(); } - - kraf.close(); } catch (IOException e) { // FIXME: should be a dialog... @@ -202,10 +198,7 @@ e.printStackTrace(); System.exit(1); } - finally { - // this will also release the lock on the key file - IOUtils.closeQuietly(kraf); - } + // lock on the key file is released lr.key = key; Modified: VASSAL-src/trunk/src/VASSAL/launch/ShutDownAction.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/launch/ShutDownAction.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/launch/ShutDownAction.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -28,7 +28,6 @@ import VASSAL.i18n.Resources; import VASSAL.preferences.Prefs; import VASSAL.tools.WriteErrorDialog; -import VASSAL.tools.io.IOUtils; public class ShutDownAction extends AbstractAction { private static final long serialVersionUID = 1L; @@ -40,18 +39,12 @@ @Override public void actionPerformed(ActionEvent e) { if (GameModule.getGameModule() == null) { - Prefs p = null; - try { - p = Prefs.getGlobalPrefs(); + try (Prefs p = Prefs.getGlobalPrefs()) { p.write(); - p.close(); } catch (IOException ex) { WriteErrorDialog.error(ex, Prefs.getGlobalPrefs().getFile().getPath()); } - finally { - IOUtils.closeQuietly(p); - } System.exit(0); } Modified: VASSAL-src/trunk/src/VASSAL/launch/TilingHandler.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/launch/TilingHandler.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/launch/TilingHandler.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -330,16 +330,10 @@ new ArrayList<>(); Pair<Integer,Integer> s; - DataArchive archive = null; - try { - archive = new DataArchive(aname); + try (DataArchive archive = new DataArchive(aname)) { final FileStore tcache = new ImageTileDiskCache(cdir.getAbsolutePath()); s = findImages(archive, tcache, multi, failed); - archive.close(); } - finally { - IOUtils.closeQuietly(archive); - } // nothing to do if no images need tiling if (multi.isEmpty()) { Modified: VASSAL-src/trunk/src/VASSAL/preferences/Prefs.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/preferences/Prefs.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/preferences/Prefs.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -185,12 +185,10 @@ } protected void read() { - InputStream in = null; - try { - in = new BufferedInputStream(new FileInputStream(file)); + try (InputStream fin = new FileInputStream(file); + InputStream in = new BufferedInputStream(fin)) { storedValues.clear(); storedValues.load(in); - in.close(); } catch (FileNotFoundException e) { // First time for this module, not an error. @@ -198,9 +196,6 @@ catch (IOException e) { ReadErrorDialog.errorNoI18N(e, file); } - finally { - IOUtils.closeQuietly(in); - } } /** @@ -214,9 +209,7 @@ FileUtils.forceMkdir(Info.getPrefsDir()); } - RandomAccessFile raf = null; - try { - raf = new RandomAccessFile(file, "rw"); + try (RandomAccessFile raf = new RandomAccessFile(file, "rw")) { final FileChannel ch = raf.getChannel(); // lock the prefs file @@ -241,10 +234,7 @@ storedValues.store(out, null); out.flush(); } - finally { - // also closes the channel, the streams, and releases the lock - IOUtils.closeQuietly(raf); - } + // channel and streams closed, lock released } /** Save these preferences and write to disk. */ Modified: VASSAL-src/trunk/src/VASSAL/preferences/ReadOnlyPrefs.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/preferences/ReadOnlyPrefs.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/preferences/ReadOnlyPrefs.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -23,12 +23,12 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.InputStream; import java.io.IOException; import java.util.Properties; import VASSAL.Info; import VASSAL.tools.ReadErrorDialog; -import VASSAL.tools.io.IOUtils; /** * A simple preferences class which permits reading stored values. @@ -47,11 +47,9 @@ } protected ReadOnlyPrefs(File file) { - BufferedInputStream in = null; - try { - in = new BufferedInputStream(new FileInputStream(file)); + try (InputStream fin = new FileInputStream(file); + BufferedInputStream in = new BufferedInputStream(fin)) { storedValues.load(in); - in.close(); } catch (FileNotFoundException e) { // First time for this module, not an error. @@ -59,9 +57,6 @@ catch (IOException e) { ReadErrorDialog.error(e, file); } - finally { - IOUtils.closeQuietly(in); - } } /** Modified: VASSAL-src/trunk/src/VASSAL/tools/BugUtils.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/BugUtils.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/tools/BugUtils.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -16,9 +16,14 @@ Throwable t) throws IOException { final HTTPPostBuilder pb = new HTTPPostBuilder(); - InputStream in = null; - try { -/* + final String url = "http://www.vassalengine.org/util/bug.php"; + pb.setParameter("version", Info.getVersion()); + pb.setParameter("email", email); + pb.setParameter("summary", getSummary(t)); + pb.setParameter("description", description); + pb.setParameter("log", "errorLog", errorLog); + + /* final URL url = new URL("http://sourceforge.net/tracker/index.php"); pb.setParameter("group_id", "90612"); pb.setParameter("atid", "594231"); @@ -30,15 +35,9 @@ pb.setParameter("input_file", "errorLog", errorLog); pb.setParameter("file_description", "the errorLog"); pb.setParameter("submit", "SUBMIT"); -*/ - final String url = "http://www.vassalengine.org/util/bug.php"; - pb.setParameter("version", Info.getVersion()); - pb.setParameter("email", email); - pb.setParameter("summary", getSummary(t)); - pb.setParameter("description", description); - pb.setParameter("log", "errorLog", errorLog); + */ - in = pb.post(url); + try (InputStream in = pb.post(url)) { final String result = IOUtils.toString(in); // script should return zero on success, otherwise it failed @@ -50,12 +49,7 @@ catch (NumberFormatException e) { throw new IOException(e); } - - in.close(); } - finally { - IOUtils.closeQuietly(in); - } } private static String getSummary(Throwable t) { @@ -86,16 +80,13 @@ // FIXME: move this somewhere else? public static String getErrorLog() { String log = null; - FileReader r = null; - try { - r = new FileReader(new File(Info.getConfDir(), "errorLog")); + final File f = new File(Info.getConfDir(), "errorLog"); + try (FileReader r = new FileReader(f)) { log = IOUtils.toString(r); - r.close(); } catch (IOException e) { // Don't bother logging this---if we can't read the errorLog, // then we probably can't write to it either. - IOUtils.closeQuietly(r); } return log; Modified: VASSAL-src/trunk/src/VASSAL/tools/Mp3AudioClip.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/Mp3AudioClip.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/tools/Mp3AudioClip.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -37,11 +37,11 @@ protected URL url = null; protected String name = null; - public Mp3AudioClip(String name) throws IOException { + public Mp3AudioClip(String name) { this.name = name; } - public Mp3AudioClip(URL url) throws IOException { + public Mp3AudioClip(URL url) { this.url = url; } Modified: VASSAL-src/trunk/src/VASSAL/tools/ZipUpdater.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/ZipUpdater.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/tools/ZipUpdater.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -30,6 +30,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.OutputStream; import java.nio.charset.StandardCharsets; import java.util.Enumeration; import java.util.Properties; @@ -82,19 +83,14 @@ if (crc < 0) { CRC32 checksum = new CRC32(); - final InputStream in = file.getInputStream(entry); - try { + try (InputStream in = file.getInputStream(entry)) { final byte[] buffer = new byte[1024]; int count; while ((count = in.read(buffer)) >= 0) { checksum.update(buffer, 0, count); } - in.close(); crc = checksum.getValue(); } - finally { - IOUtils.closeQuietly(in); - } } } return crc; @@ -101,26 +97,23 @@ } private long copyEntry(ZipOutputStream output, ZipEntry newEntry) throws IOException { - return writeEntry(oldZipFile.getInputStream(new ZipEntry(newEntry.getName())), output, newEntry); + try (InputStream in = oldZipFile.getInputStream(new ZipEntry(newEntry.getName()))) { + return writeEntry(in, output, newEntry); + } } private long replaceEntry(ZipOutputStream output, ZipEntry newEntry) throws IOException { - final InputStream newContents = - getClass().getResourceAsStream("/" + ENTRIES_DIR + newEntry.getName()); - if (newContents == null) { - throw new IOException("This updater was created with an original that differs from the file you're trying to update.\nLocal entry does not match original: "+newEntry.getName()); - } + final String r = "/" + ENTRIES_DIR + newEntry.getName(); + try (InputStream newContents = getClass().getResourceAsStream(r)) { + if (newContents == null) { + throw new IOException("This updater was created with an original that differs from the file you're trying to update.\nLocal entry does not match original: " + newEntry.getName()); + } - BufferedInputStream in = null; - try { - in = new BufferedInputStream(newContents); - long cs = writeEntry(newContents, output, newEntry); - in.close(); - return cs; + try (BufferedInputStream in = new BufferedInputStream(newContents)) { + long cs = writeEntry(newContents, output, newEntry); + return cs; + } } - finally { - IOUtils.closeQuietly(in); - } } @@ -142,32 +135,25 @@ public void write(File destination) throws IOException { checkSums = new Properties(); - final InputStream rin = - ZipUpdater.class.getResourceAsStream("/" + CHECKSUM_RESOURCE); - if (rin == null) - throw new IOException("Resource not found: " + CHECKSUM_RESOURCE); + try (InputStream rin = ZipUpdater.class.getResourceAsStream("/" + CHECKSUM_RESOURCE)) { + if (rin == null) { + throw new IOException("Resource not found: " + CHECKSUM_RESOURCE); + } - BufferedInputStream in = null; - try { - in = new BufferedInputStream(rin); - checkSums.load(in); - in.close(); + try (BufferedInputStream in = new BufferedInputStream(rin)) { + checkSums.load(in); + } } - finally { - IOUtils.closeQuietly(in); - } final File tempFile = File.createTempFile("VSL", ".zip"); - oldZipFile = new ZipFile(oldFile.getPath()); - try { + try (ZipFile ozf = new ZipFile(oldFile.getPath())) { + oldZipFile = ozf; + final ZipOutputStream output = new ZipOutputStream(new FileOutputStream(tempFile)); try { -// FIXME: reinstate when we move to 1.6+. -// for (String entryName : checkSums.stringPropertyNames()) { - for (Enumeration<Object> e = checkSums.keys(); e.hasMoreElements();) { - final String entryName = (String) e.nextElement(); + for (String entryName : checkSums.stringPropertyNames()) { long targetSum; try { targetSum = @@ -202,9 +188,6 @@ } } } - finally { - oldZipFile.close(); - } if (destination.getName().equals(oldFile.getName())) { String updatedName = destination.getName(); @@ -215,6 +198,7 @@ throw new IOException("Unable to create backup file " + backup + ".\nUpdated file is in " + tempFile.getPath()); } } + if (!tempFile.renameTo(destination)) { throw new IOException("Unable to write to file " + destination.getPath()+ ".\nUpdated file is in " + tempFile.getPath()); } @@ -240,16 +224,14 @@ } checkSums = new Properties(); - try { - oldZipFile = new ZipFile(oldFile); + try (ZipFile ozf = new ZipFile(oldFile)) { + oldZipFile = ozf; final String inputArchiveName = oldFile.getName(); - final ZipFile goal = new ZipFile(newFile); - try { - JarOutputStream out = null; - try { - out = new JarOutputStream( - new BufferedOutputStream(new FileOutputStream(updaterFile))); + try (ZipFile goal = new ZipFile(newFile)) { + try (OutputStream fout = new FileOutputStream(updaterFile); + OutputStream bout = new BufferedOutputStream(fout); + JarOutputStream out = new JarOutputStream(bout)) { for (ZipEntry entry : iterate(goal.entries())) { final long goalCrc = getCrc(goal, entry); final long inputCrc = @@ -259,15 +241,10 @@ new ZipEntry(ENTRIES_DIR + entry.getName()); outputEntry.setMethod(entry.getMethod()); - InputStream gis = null; - try { - gis = new BufferedInputStream(goal.getInputStream(entry)); + try (InputStream inner = goal.getInputStream(entry); + InputStream gis = new BufferedInputStream(inner)) { writeEntry(gis, out, outputEntry); - gis.close(); } - finally { - IOUtils.closeQuietly(gis); - } } checkSums.put(entry.getName(), goalCrc + ""); } @@ -310,38 +287,18 @@ final ZipEntry classEntry = new ZipEntry(className); classEntry.setMethod(ZipEntry.DEFLATED); - final InputStream is = - getClass().getResourceAsStream("/" + className); - if (is == null) - throw new IOException("Resource not found: " + className); + try (InputStream is = getClass().getResourceAsStream("/" + className)) { + if (is == null) { + throw new IOException("Resource not found: " + className); + } - BufferedInputStream in = null; - try { - in = new BufferedInputStream(is); - writeEntry(is, out, classEntry); - in.close(); + try (BufferedInputStream in = new BufferedInputStream(is)) { + writeEntry(is, out, classEntry); + } } - finally { - IOUtils.closeQuietly(in); - } - - out.close(); } - finally { - IOUtils.closeQuietly(out); - } - - goal.close(); } - finally { - IOUtils.closeQuietly(goal); - } - - oldZipFile.close(); } - finally { - IOUtils.closeQuietly(oldZipFile); - } } private String fileName; Modified: VASSAL-src/trunk/src/VASSAL/tools/image/FileImageTypeConverter.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/image/FileImageTypeConverter.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/tools/image/FileImageTypeConverter.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -25,8 +25,8 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.InputStream; import java.io.IOException; -import java.io.InputStream; import java.io.OutputStream; import java.nio.ByteBuffer; import java.util.zip.GZIPInputStream; @@ -98,20 +98,14 @@ try { // write the converted image data to a file - OutputStream out = null; - try { - out = new BufferedOutputStream( - new GZIPOutputStream( - new FileOutputStream(tmp))); + try (OutputStream fout = new FileOutputStream(tmp); + OutputStream gzout = new GZIPOutputStream(fout); + OutputStream out = new BufferedOutputStream(gzout)) { write(src, out); - out.close(); } catch (IOException e) { throw new ImageIOException(tmp, e); } - finally { - IOUtils.closeQuietly(out); - } final int w = src.getWidth(); final int h = src.getHeight(); @@ -122,21 +116,15 @@ final BufferedImage dst = new BufferedImage(w, h, type); // read the converted image data back - InputStream in = null; - try { - in = new BufferedInputStream( - new GZIPInputStream( - new FileInputStream(tmp))); + try (InputStream fin = new FileInputStream(tmp); + InputStream gzin = new GZIPInputStream(fin); + InputStream in = new BufferedInputStream(gzin)) { read(in, dst); - in.close(); return dst; } catch (IOException e) { throw new ImageIOException(tmp, e); } - finally { - IOUtils.closeQuietly(in); - } } finally { // clean up the temporary file Modified: VASSAL-src/trunk/src/VASSAL/tools/image/JPEGDecoder.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/image/JPEGDecoder.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/tools/image/JPEGDecoder.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -21,10 +21,9 @@ import java.io.DataInputStream; import java.io.FileInputStream; +import java.io.InputStream; import java.io.IOException; -import VASSAL.tools.io.IOUtils; - /** * A (partial) JPEG decoder. * @@ -108,24 +107,19 @@ } public static void main(String[] args) throws IOException { - DataInputStream in = null; - try { - in = new DataInputStream(new FileInputStream(args[0])); - + try (InputStream fin = new FileInputStream(args[0]); + DataInputStream in = new DataInputStream(fin)) { if (!JPEGDecoder.decodeSignature(in)) { System.out.println("Not a JPEG"); } - JPEGDecoder.Chunk ch; + Chunk ch; do { ch = JPEGDecoder.decodeChunk(in); - System.out.println("type == " + Integer.toHexString(ch.type) + ", length == " + ch.data.length); + System.out.println("type == " + Integer.toHexString(ch.type) + ", length == " + ch.data.length); } while (ch.type != JPEGDecoder.EOI); } - finally { - IOUtils.closeQuietly(in); - } } } Modified: VASSAL-src/trunk/src/VASSAL/tools/image/svg/SVGRenderer.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/image/svg/SVGRenderer.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/tools/image/svg/SVGRenderer.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -64,8 +64,8 @@ import org.w3c.dom.Node; import VASSAL.build.GameModule; +import VASSAL.tools.DataArchive; import VASSAL.tools.image.ImageUtils; -import VASSAL.tools.io.IOUtils; /** * Render an SVG image to a {@link BufferedImage}. @@ -86,13 +86,19 @@ private final float defaultW, defaultH; private final Rasterizer r = new Rasterizer(); + /** + * Closes the {@link InputStream}. + */ public SVGRenderer(URL file, InputStream in) throws IOException { this(file.toString(), in); } + /** + * Closes the {@link InputStream}. + */ public SVGRenderer(String file, InputStream in) throws IOException { // load the SVG - try { + try (in) { // We synchronize on docFactory becuase it does internal caching // of the Documents it produces. This ensures that a Document is // being modified on one thread only. @@ -99,14 +105,10 @@ synchronized (docFactory) { doc = docFactory.createDocument(file, in); } - in.close(); } catch (DOMException e) { throw new IOException(e); } - finally { - IOUtils.closeQuietly(in); - } // get the default image size final Element root = doc.getDocumentElement(); @@ -188,23 +190,14 @@ public Document loadDocument(String uri) throws MalformedURLException, IOException { final String file = new File((new URL(uri)).getPath()).getName(); - - BufferedInputStream in = null; - try { - in = new BufferedInputStream( - GameModule.getGameModule() - .getDataArchive() - .getInputStream(file)); - final Document doc = loadDocument(uri, in); - in.close(); - return doc; + final DataArchive mda = GameModule.getGameModule().getDataArchive(); + try (InputStream inner = mda.getInputStream(file); + BufferedInputStream in = new BufferedInputStream(inner)) { + return loadDocument(uri, in); } catch (DOMException e) { throw new IOException(e); } - finally { - IOUtils.closeQuietly(in); - } } } Modified: VASSAL-src/trunk/src/VASSAL/tools/image/tilecache/TileUtils.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/image/tilecache/TileUtils.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/tools/image/tilecache/TileUtils.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -29,8 +29,8 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.InputStream; import java.io.IOException; -import java.io.InputStream; import java.io.OutputStream; import java.nio.ByteBuffer; import java.nio.IntBuffer; @@ -81,13 +81,9 @@ * @throws ImageNotFoundException if the file isn't found */ public static BufferedImage read(File src) throws ImageIOException { - InputStream in = null; - try { - in = new BufferedInputStream(new FileInputStream(src)); - - final BufferedImage img = read(in); - in.close(); - return img; + try (InputStream fin = new FileInputStream(src); + InputStream in = new BufferedInputStream(fin)) { + return read(in); } catch (FileNotFoundException e) { throw new ImageNotFoundException(src, e); @@ -95,9 +91,6 @@ catch (IOException e) { throw new ImageIOException(src, e); } - finally { - IOUtils.closeQuietly(in); - } } /** @@ -129,15 +122,10 @@ final byte[] cdata = IOUtils.toByteArray(in); // decompress the image data - InputStream zin = null; - try { - zin = new GZIPInputStream(new ByteArrayInputStream(cdata)); + try (InputStream bin = new ByteArrayInputStream(cdata); + InputStream zin = new GZIPInputStream(bin)) { bb = ByteBuffer.wrap(IOUtils.toByteArray(zin)); - zin.close(); } - finally { - IOUtils.closeQuietly(zin); - } // build the image final BufferedImage img = new BufferedImage(w, h, type); @@ -217,12 +205,9 @@ * @throws ImageNotFoundException if the file isn't found */ public static Dimension size(File src) throws ImageIOException { - InputStream in = null; - try { + try (InputStream in = new FileInputStream(src)) { // NB: We don't buffer here because we're reading only 18 bytes. - in = new FileInputStream(src); final Dimension d = size(in); - in.close(); return d; } catch (FileNotFoundException e) { @@ -231,9 +216,6 @@ catch (IOException e) { throw new ImageIOException(src, e); } - finally { - IOUtils.closeQuietly(in); - } } /** @@ -283,18 +265,13 @@ */ public static void write(BufferedImage tile, File dst) throws ImageIOException { - OutputStream out = null; - try { - out = new BufferedOutputStream(new FileOutputStream(dst)); + try (OutputStream fout = new FileOutputStream(dst); + OutputStream out = new BufferedOutputStream(fout)) { write(tile, out); - out.close(); } catch (IOException e) { throw new ImageIOException(dst, e); } - finally { - IOUtils.closeQuietly(out); - } } /** Modified: VASSAL-src/trunk/src/VASSAL/tools/image/tilecache/ZipFileImageTiler.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/image/tilecache/ZipFileImageTiler.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/tools/image/tilecache/ZipFileImageTiler.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -169,24 +169,16 @@ } }; - FileArchive fa = null; - try { - fa = new ZipArchive(zpath); - + try (FileArchive fa = new ZipArchive(zpath)) { // Tile the images tiler.run( fa, tpath, tw, th, ipaths, exec, loader, slicer, imageL, tileL, doneL ); - - fa.close(); } catch (IOException e) { logger.error("", e); } - finally { - IOUtils.closeQuietly(fa); - } dout.close(); if (sock != null) { Modified: VASSAL-src/trunk/src/VASSAL/tools/imageop/SourceOpBitmapImpl.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/imageop/SourceOpBitmapImpl.java 2020-05-25 21:48:45 UTC (rev 9430) +++ VASSAL-src/trunk/src/VASSAL/tools/imageop/SourceOpBitmapImpl.java 2020-05-25 21:49:03 UTC (rev 9431) @@ -34,7 +34,6 @@ import VASSAL.tools.image.ImageNotFoundException; import VASSAL.tools.image.ImageUtils; import VASSAL.tools.io.FileArchive; -import VASSAL.tools.io.IOUtils; /** * An {@link ImageOp} which loads an image from the {@link DataArchive}. @@ -111,12 +110,8 @@ */ @Override public BufferedImage eval() throws ImageIOException { - InputStream in = null; - try { - in = getInputStream(); - + try (InputStream in = getInputStream()) { final BufferedImage img = ImageUtils.getImage(name, in); - in.close(); return img; } catch (ImageIOException e) { @@ -129,9 +124,6 @@ catch (IOException e) { throw new ImageIOException(name, e); } - finally { - IOUtils.closeQuietly(in); - } } /** {@inheritDoc} */ @@ -147,12 +139,8 @@ protect... [truncated message content] |
From: <uck...@us...> - 2020-05-25 21:48:47
|
Revision: 9430 http://sourceforge.net/p/vassalengine/svn/9430 Author: uckelman Date: 2020-05-25 21:48:45 +0000 (Mon, 25 May 2020) Log Message: ----------- replaced calls to deprecated IOUtils.closeQuietly() with Java's automatic resource management Modified Paths: -------------- VASSAL-src/trunk/src/VASSAL/build/Builder.java VASSAL-src/trunk/src/VASSAL/build/module/BasicLogger.java VASSAL-src/trunk/src/VASSAL/build/module/GameState.java VASSAL-src/trunk/src/VASSAL/build/module/documentation/BrowserHelpFile.java VASSAL-src/trunk/src/VASSAL/build/module/metadata/AbstractMetaData.java VASSAL-src/trunk/src/VASSAL/build/module/metadata/ExtensionMetaData.java VASSAL-src/trunk/src/VASSAL/chat/AddressBookServerConfigurer.java VASSAL-src/trunk/src/VASSAL/launch/ModuleManager.java VASSAL-src/trunk/src/VASSAL/launch/TilingHandler.java VASSAL-src/trunk/src/VASSAL/tools/ArchiveWriter.java VASSAL-src/trunk/src/VASSAL/tools/CRCUtils.java VASSAL-src/trunk/src/VASSAL/tools/DataArchive.java VASSAL-src/trunk/src/VASSAL/tools/HTTPPostBuilder.java VASSAL-src/trunk/src/VASSAL/tools/Mp3AudioClip.java VASSAL-src/trunk/src/VASSAL/tools/image/ImageIOImageLoader.java VASSAL-src/trunk/src/VASSAL/tools/image/svg/SVGImageUtils.java VASSAL-src/trunk/src/VASSAL/tools/image/tilecache/FileArchiveImageTiler.java VASSAL-src/trunk/src/VASSAL/tools/image/tilecache/ImageToTiles.java VASSAL-src/trunk/src/VASSAL/tools/version/VersionUtils.java VASSAL-src/trunk/test/VASSAL/tools/image/ImageIOImageLoaderTest.java VASSAL-src/trunk/test/VASSAL/tools/io/TailerTest.java Modified: VASSAL-src/trunk/src/VASSAL/build/Builder.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/Builder.java 2020-05-25 21:48:32 UTC (rev 9429) +++ VASSAL-src/trunk/src/VASSAL/build/Builder.java 2020-05-25 21:48:45 UTC (rev 9430) @@ -47,7 +47,6 @@ import VASSAL.tools.DataArchive; import VASSAL.tools.ErrorDialog; import VASSAL.tools.ThrowableUtils; -import VASSAL.tools.io.IOUtils; /** * This class holds static convenience methods for building {@link Buildable} @@ -150,11 +149,10 @@ */ public static Document createDocument(InputStream in) throws IOException { - try { + try (in) { final Document doc = DocumentBuilderFactory.newInstance() - .newDocumentBuilder() - .parse(in); - in.close(); + .newDocumentBuilder() + .parse(in); return doc; } catch (ParserConfigurationException e) { @@ -164,9 +162,6 @@ catch (SAXException e) { throw new IOException(e); } - finally { - IOUtils.closeQuietly(in); - } } /** Modified: VASSAL-src/trunk/src/VASSAL/build/module/BasicLogger.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/module/BasicLogger.java 2020-05-25 21:48:32 UTC (rev 9429) +++ VASSAL-src/trunk/src/VASSAL/build/module/BasicLogger.java 2020-05-25 21:48:45 UTC (rev 9430) @@ -64,7 +64,6 @@ import VASSAL.tools.filechooser.LogFileFilter; import VASSAL.tools.io.FastByteArrayOutputStream; import VASSAL.tools.io.FileArchive; -import VASSAL.tools.io.IOUtils; import VASSAL.tools.io.ObfuscatingOutputStream; import VASSAL.tools.io.ZipArchive; import VASSAL.tools.menu.MenuManager; @@ -314,26 +313,14 @@ // FIXME: Extremely inefficient! Make encode write to an OutputStream final String s = GameModule.getGameModule().encode(log); final FastByteArrayOutputStream ba = new FastByteArrayOutputStream(); - OutputStream out = null; - try { - out = new ObfuscatingOutputStream(ba); + try (OutputStream out = new ObfuscatingOutputStream(ba)) { out.write(s.getBytes(StandardCharsets.UTF_8)); - out.close(); } - finally { - IOUtils.closeQuietly(out); - } - FileArchive archive = null; - try { - archive = new ZipArchive(outputFile); + try (FileArchive archive = new ZipArchive(outputFile)) { archive.add(GameState.SAVEFILE_ZIP_ENTRY, ba.toInputStream()); metadata.save(archive); - archive.close(); } - finally { - IOUtils.closeQuietly(archive); - } Launcher.getInstance().sendSaveCmd(outputFile); Modified: VASSAL-src/trunk/src/VASSAL/build/module/GameState.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/module/GameState.java 2020-05-25 21:48:32 UTC (rev 9429) +++ VASSAL-src/trunk/src/VASSAL/build/module/GameState.java 2020-05-25 21:48:45 UTC (rev 9430) @@ -746,15 +746,9 @@ // FIXME: Extremely inefficient! Write directly to ZipArchive OutputStream final String save = saveString(); final FastByteArrayOutputStream ba = new FastByteArrayOutputStream(); - OutputStream out = null; - try { - out = new ObfuscatingOutputStream(ba); + try (OutputStream out = new ObfuscatingOutputStream(ba)) { out.write(save.getBytes(StandardCharsets.UTF_8)); - out.close(); } - finally { - IOUtils.closeQuietly(out); - } FileArchive archive = null; try { @@ -793,12 +787,9 @@ new SwingWorker<Command,Void>() { @Override public Command doInBackground() throws Exception { - try { + try (in) { return decodeSavedGame(in); } - finally { - IOUtils.closeQuietly(in); - } } @Override @@ -922,31 +913,19 @@ } public Command decodeSavedGame(InputStream in) throws IOException { - ZipInputStream zipInput = null; - try { - zipInput = new ZipInputStream(in); + try (ZipInputStream zipInput = new ZipInputStream(in)) { for (ZipEntry entry = zipInput.getNextEntry(); entry != null; entry = zipInput.getNextEntry()) { if (SAVEFILE_ZIP_ENTRY.equals(entry.getName())) { - InputStream din = null; - try { - din = new DeobfuscatingInputStream(zipInput); -// FIXME: toString() is very inefficient, make decode() use the stream directly + try (InputStream din = new DeobfuscatingInputStream(zipInput)) { + // FIXME: toString() is very inefficient, make decode() use the stream directly final Command c = GameModule.getGameModule().decode( IOUtils.toString(din, StandardCharsets.UTF_8)); - din.close(); return c; } - finally { - IOUtils.closeQuietly(din); - } } } - zipInput.close(); } - finally { - IOUtils.closeQuietly(zipInput); - } // FIXME: give more specific error message throw new IOException("Invalid saveFile format"); Modified: VASSAL-src/trunk/src/VASSAL/build/module/documentation/BrowserHelpFile.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/module/documentation/BrowserHelpFile.java 2020-05-25 21:48:32 UTC (rev 9429) +++ VASSAL-src/trunk/src/VASSAL/build/module/documentation/BrowserHelpFile.java 2020-05-25 21:48:45 UTC (rev 9430) @@ -139,15 +139,9 @@ } else { // FIXME: no way to distinguish between read and write errors here - FileOutputStream fos = null; - try { - fos = new FileOutputStream(new File(output, entry.getName())); + try (FileOutputStream fos = new FileOutputStream(new File(output, entry.getName()))) { IOUtils.copy(in, fos); - fos.close(); } - finally { - IOUtils.closeQuietly(fos); - } } } @@ -328,17 +322,12 @@ File packed = null; try { packed = File.createTempFile("VASSALhelp", ".zip"); //$NON-NLS-1$ //$NON-NLS-2$ - ZipOutputStream out = null; - try { - out = new ZipOutputStream(new FileOutputStream(packed)); + try (FileOutputStream fout = new FileOutputStream(packed); + ZipOutputStream out = new ZipOutputStream(fout)) { for (File f : dir.listFiles()) { packFile(f, "", out); //$NON-NLS-1$ } - out.close(); } - finally { - IOUtils.closeQuietly(out); - } GameModule.getGameModule().getArchiveWriter().addFile( packed.getPath(), @@ -360,15 +349,9 @@ final ZipEntry entry = new ZipEntry(prefix + packed.getName()); out.putNextEntry(entry); - FileInputStream in = null; - try { - in = new FileInputStream(packed); + try (FileInputStream in = new FileInputStream(packed)) { IOUtils.copy(in, out); - in.close(); } - finally { - IOUtils.closeQuietly(in); - } } } Modified: VASSAL-src/trunk/src/VASSAL/build/module/metadata/AbstractMetaData.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/module/metadata/AbstractMetaData.java 2020-05-25 21:48:32 UTC (rev 9429) +++ VASSAL-src/trunk/src/VASSAL/build/module/metadata/AbstractMetaData.java 2020-05-25 21:48:45 UTC (rev 9430) @@ -19,6 +19,7 @@ import java.io.BufferedInputStream; import java.io.FileNotFoundException; +import java.io.InputStream; import java.io.IOException; import java.io.OutputStream; import java.util.HashMap; @@ -52,10 +53,10 @@ import VASSAL.build.GameModule; import VASSAL.i18n.Translation; import VASSAL.tools.ArchiveWriter; +import VASSAL.tools.DataArchive; import VASSAL.tools.ErrorDialog; import VASSAL.tools.io.FastByteArrayOutputStream; import VASSAL.tools.io.FileArchive; -import VASSAL.tools.io.IOUtils; /** * @@ -135,15 +136,9 @@ } public void save(FileArchive archive) throws IOException { - OutputStream out = null; - try { - out = archive.getOutputStream(getZipEntryName()); + try (OutputStream out = archive.getOutputStream(getZipEntryName())) { save(out); - out.close(); } - finally { - IOUtils.closeQuietly(out); - } } protected void save(OutputStream out) throws IOException { @@ -230,22 +225,15 @@ } public void copyModuleMetadata(FileArchive archive) throws IOException { - BufferedInputStream in = null; - try { - in = new BufferedInputStream( - GameModule.getGameModule() - .getDataArchive() - .getInputStream(ModuleMetaData.ZIP_ENTRY_NAME)); + final DataArchive mda = GameModule.getGameModule().getDataArchive(); + try (InputStream inner = mda.getInputStream(ModuleMetaData.ZIP_ENTRY_NAME); + BufferedInputStream in = new BufferedInputStream(inner)) { archive.add(ModuleMetaData.ZIP_ENTRY_NAME, in); - in.close(); } catch (FileNotFoundException e) { // No Metatdata in source module, create a fresh copy new ModuleMetaData(GameModule.getGameModule()).save(archive); } - finally { - IOUtils.closeQuietly(in); - } } /** Modified: VASSAL-src/trunk/src/VASSAL/build/module/metadata/ExtensionMetaData.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/module/metadata/ExtensionMetaData.java 2020-05-25 21:48:32 UTC (rev 9429) +++ VASSAL-src/trunk/src/VASSAL/build/module/metadata/ExtensionMetaData.java 2020-05-25 21:48:45 UTC (rev 9430) @@ -18,6 +18,7 @@ package VASSAL.build.module.metadata; import java.io.BufferedInputStream; +import java.io.InputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -142,10 +143,8 @@ } // parse! parse! - BufferedInputStream in = null; - try { - in = new BufferedInputStream(zip.getInputStream(data)); - + try (InputStream zin = zip.getInputStream(data); + BufferedInputStream in = new BufferedInputStream(zin)) { synchronized (parser) { parser.setContentHandler(handler); parser.setDTDHandler(handler); @@ -153,12 +152,7 @@ parser.setErrorHandler(handler); parser.parse(new InputSource(in)); } - - in.close(); } - finally { - IOUtils.closeQuietly(in); - } // read the matching Module data. A basic moduledata may have been // built when reading the buildFile, overwrite if we find a real Modified: VASSAL-src/trunk/src/VASSAL/chat/AddressBookServerConfigurer.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/chat/AddressBookServerConfigurer.java 2020-05-25 21:48:32 UTC (rev 9429) +++ VASSAL-src/trunk/src/VASSAL/chat/AddressBookServerConfigurer.java 2020-05-25 21:48:45 UTC (rev 9430) @@ -33,7 +33,6 @@ import net.miginfocom.swing.MigLayout; import VASSAL.configure.Configurer; import VASSAL.i18n.Resources; -import VASSAL.tools.io.IOUtils; /** * Improved version of ServerConfigurer that includes an Address Book of @@ -114,8 +113,7 @@ @Override public String getValueString() { String s = ""; //$NON-NLS-1$ - ByteArrayOutputStream out = new ByteArrayOutputStream(); - try { + try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { Properties p = (Properties) getValue(); if (p != null) { p.store(out, null); @@ -126,9 +124,6 @@ catch (IOException e) { e.printStackTrace(); } - finally { - IOUtils.closeQuietly(out); - } return s; } Modified: VASSAL-src/trunk/src/VASSAL/launch/ModuleManager.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/launch/ModuleManager.java 2020-05-25 21:48:32 UTC (rev 9429) +++ VASSAL-src/trunk/src/VASSAL/launch/ModuleManager.java 2020-05-25 21:48:45 UTC (rev 9430) @@ -296,38 +296,18 @@ final byte[] buf = new byte[4096]; try { - final ZipArchive za = new ZipArchive(pzip); - try { + try (ZipArchive za = new ZipArchive(pzip)) { for (String f : za.getFiles()) { final File ofile = new File( pdir, "VASSAL".equals(f) ? "V_Global" : Prefs.sanitize(f) ); - InputStream in = null; - try { - in = za.getInputStream(f); - - OutputStream out = null; - try { - out = new FileOutputStream(ofile); - IOUtils.copy(in, out, buf); - out.close(); - } - finally { - IOUtils.closeQuietly(out); - } - - in.close(); + try (InputStream in = za.getInputStream(f); + OutputStream out = new FileOutputStream(ofile)) { + IOUtils.copy(in, out, buf); } - finally { - IOUtils.closeQuietly(in); - } } - za.close(); } - finally { - IOUtils.closeQuietly(za); - } } catch (IOException e) { logger.error("Failed to convert legacy preferences file.", e); Modified: VASSAL-src/trunk/src/VASSAL/launch/TilingHandler.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/launch/TilingHandler.java 2020-05-25 21:48:32 UTC (rev 9429) +++ VASSAL-src/trunk/src/VASSAL/launch/TilingHandler.java 2020-05-25 21:48:45 UTC (rev 9430) @@ -110,16 +110,10 @@ protected Dimension getImageSize(DataArchive archive, String ipath) throws IOException { - InputStream in = null; - try { - in = archive.getInputStream(ipath); + try (InputStream in = archive.getInputStream(ipath)) { final Dimension id = ImageUtils.getImageSize(ipath, in); - in.close(); return id; } - finally { - IOUtils.closeQuietly(in); - } } protected Pair<Integer,Integer> findImages( Modified: VASSAL-src/trunk/src/VASSAL/tools/ArchiveWriter.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/ArchiveWriter.java 2020-05-25 21:48:32 UTC (rev 9429) +++ VASSAL-src/trunk/src/VASSAL/tools/ArchiveWriter.java 2020-05-25 21:48:45 UTC (rev 9430) @@ -199,18 +199,12 @@ * @param in the stream to copy */ public void addFile(String fileName, InputStream in) { - OutputStream out = null; - try { - out = archive.getOutputStream(fileName); + try (OutputStream out = archive.getOutputStream(fileName)) { IOUtils.copy(in, out); - out.close(); } catch (IOException e) { WriteErrorDialog.error(e, archive.getName()); } - finally { - IOUtils.closeQuietly(out); - } } public void addFile(String fileName, byte[] content) { Modified: VASSAL-src/trunk/src/VASSAL/tools/CRCUtils.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/CRCUtils.java 2020-05-25 21:48:32 UTC (rev 9429) +++ VASSAL-src/trunk/src/VASSAL/tools/CRCUtils.java 2020-05-25 21:48:45 UTC (rev 9430) @@ -25,8 +25,6 @@ import java.util.List; import java.util.zip.CRC32; -import VASSAL.tools.io.IOUtils; - /** * Some general purpose CRC utilities. * @@ -66,13 +64,9 @@ * @throws IOException */ private static void buildCRC(File file, CRC32 crc, byte[] buffer) throws IOException { - InputStream in = new FileInputStream(file); - try { + try (InputStream in = new FileInputStream(file)) { buildCRC(in, crc, buffer); } - finally { - IOUtils.closeQuietly(in); - } } /** Modified: VASSAL-src/trunk/src/VASSAL/tools/DataArchive.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/DataArchive.java 2020-05-25 21:48:32 UTC (rev 9429) +++ VASSAL-src/trunk/src/VASSAL/tools/DataArchive.java 2020-05-25 21:48:45 UTC (rev 9430) @@ -122,14 +122,9 @@ clip = new Mp3AudioClip(path); } else { - InputStream stream = null; - try { - stream = getInputStream(path); + try (InputStream stream = getInputStream(path)) { clip = new AudioSystemClip(stream); } - finally { - IOUtils.closeQuietly(stream); - } } soundCache.put(path, clip); @@ -445,17 +440,12 @@ final String slashname = name.replace('.', '/'); byte[] data = null; - InputStream stream = null; - try { - stream = getInputStream(slashname + ".class"); + try (InputStream stream = getInputStream(slashname + ".class")) { data = IOUtils.toByteArray(stream); } catch (IOException e) { throw new ClassNotFoundException("Unable to load class " + name, e); } - finally { - IOUtils.closeQuietly(stream); - } final int minor = (data[4] << 8) | data[5]; final int major = (data[6] << 8) | data[7]; Modified: VASSAL-src/trunk/src/VASSAL/tools/HTTPPostBuilder.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/HTTPPostBuilder.java 2020-05-25 21:48:32 UTC (rev 9429) +++ VASSAL-src/trunk/src/VASSAL/tools/HTTPPostBuilder.java 2020-05-25 21:48:45 UTC (rev 9430) @@ -81,15 +81,9 @@ * @throws IOException in case of failure */ public void setParameter(String name, File file) throws IOException { - FileInputStream in = null; - try { - in = new FileInputStream(file); + try (FileInputStream in = new FileInputStream(file)) { setParameter(name, file.getPath(), in); - in.close(); } - finally { - IOUtils.closeQuietly(in); - } } /** @@ -181,28 +175,22 @@ public InputStream post(URL url) throws IOException { writeEnd(); - OutputStream out = null; - try { - final HttpURLConnection http = (HttpURLConnection) url.openConnection(); + final HttpURLConnection http = (HttpURLConnection) url.openConnection(); - http.setRequestMethod("POST"); - http.setDoInput(true); - http.setDoOutput(true); - http.setUseCaches(false); - http.setAllowUserInteraction(false); + http.setRequestMethod("POST"); + http.setDoInput(true); + http.setDoOutput(true); + http.setUseCaches(false); + http.setAllowUserInteraction(false); - http.setRequestProperty("Content-Type", - "multipart/form-data; boundary=" + boundary); - http.setRequestProperty("Content-Length", String.valueOf(bytes.size())); + http.setRequestProperty("Content-Type", + "multipart/form-data; boundary=" + boundary); + http.setRequestProperty("Content-Length", String.valueOf(bytes.size())); - out = http.getOutputStream(); + try (OutputStream out = http.getOutputStream()) { bytes.writeTo(out); - out.close(); + } - return http.getInputStream(); - } - finally { - IOUtils.closeQuietly(out); - } + return http.getInputStream(); } } Modified: VASSAL-src/trunk/src/VASSAL/tools/Mp3AudioClip.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/Mp3AudioClip.java 2020-05-25 21:48:32 UTC (rev 9429) +++ VASSAL-src/trunk/src/VASSAL/tools/Mp3AudioClip.java 2020-05-25 21:48:45 UTC (rev 9430) @@ -103,17 +103,14 @@ new Thread() { @Override public void run() { - try { + try (stream) { player.play(); } - catch (JavaLayerException e) { + catch (JavaLayerException | IOException e) { ErrorDialog.dataError(new BadDataReport( "Error reading sound file", name, e )); } - finally { - IOUtils.closeQuietly(stream); - } } }.start(); } Modified: VASSAL-src/trunk/src/VASSAL/tools/image/ImageIOImageLoader.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/image/ImageIOImageLoader.java 2020-05-25 21:48:32 UTC (rev 9429) +++ VASSAL-src/trunk/src/VASSAL/tools/image/ImageIOImageLoader.java 2020-05-25 21:48:45 UTC (rev 9430) @@ -35,7 +35,6 @@ import sun.java2d.cmm.ProfileDeferralMgr; -import VASSAL.tools.io.IOUtils; import VASSAL.tools.io.RereadableInputStream; import VASSAL.tools.lang.Reference; @@ -70,21 +69,15 @@ static { BufferedImage img = null; - InputStream in = null; - try { + try (InputStream in = ImageIOImageLoader.class.getResourceAsStream("/images/black.jpg")) { // We intentionally bypass the normal image loading system // in order to see how ImageIO loads the test image. - in = ImageIOImageLoader.class.getResourceAsStream("/images/black.jpg"); img = ImageIO.read(new MemoryCacheImageInputStream(in)); - in.close(); } catch (IOException e) { // this should not happen throw new IllegalStateException(); } - finally { - IOUtils.closeQuietly(in); - } if (img == null) { // this should not happen @@ -179,9 +172,7 @@ boolean fix_YCbCr = false; BufferedImage img = null; - RereadableInputStream rin = null; - try { - rin = new RereadableInputStream(in); + try (RereadableInputStream rin = new RereadableInputStream(in)) { rin.mark(512); DataInputStream din = new DataInputStream(rin); @@ -349,7 +340,6 @@ // Load the image rin.reset(); img = wrapImageIO(name, rin, readImage); - rin.close(); } catch (ImageIOException e) { // Don't wrap ImageIOExceptions. @@ -358,9 +348,6 @@ catch (IOException e) { throw new ImageIOException(name, e); } - finally { - IOUtils.closeQuietly(rin); - } final int type = img.getTransparency() == BufferedImage.OPAQUE && !fix_tRNS Modified: VASSAL-src/trunk/src/VASSAL/tools/image/svg/SVGImageUtils.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/image/svg/SVGImageUtils.java 2020-05-25 21:48:32 UTC (rev 9429) +++ VASSAL-src/trunk/src/VASSAL/tools/image/svg/SVGImageUtils.java 2020-05-25 21:48:45 UTC (rev 9430) @@ -47,7 +47,6 @@ import VASSAL.tools.image.ImageIOException; import VASSAL.tools.image.ImageNotFoundException; -import VASSAL.tools.io.IOUtils; /** * Utility methods for manipulating SVG images. @@ -75,6 +74,8 @@ /** * Returns the default dimensions of the SVG image. * + * Closes the {@link InputStream}. + * * @return the image dimensions * @throws IOException if the image cannot be read */ @@ -82,11 +83,10 @@ throws IOException { // get the SVG final Document doc; - try { + try (in) { synchronized (factory) { doc = factory.createDocument(null, in); } - in.close(); } catch (FileNotFoundException e) { throw new ImageNotFoundException(name, e); @@ -94,9 +94,6 @@ catch (DOMException | IOException e) { throw new ImageIOException(name, e); } - finally { - IOUtils.closeQuietly(in); - } // get the default image width and height final Element root = doc.getDocumentElement(); Modified: VASSAL-src/trunk/src/VASSAL/tools/image/tilecache/FileArchiveImageTiler.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/image/tilecache/FileArchiveImageTiler.java 2020-05-25 21:48:32 UTC (rev 9429) +++ VASSAL-src/trunk/src/VASSAL/tools/image/tilecache/FileArchiveImageTiler.java 2020-05-25 21:48:45 UTC (rev 9430) @@ -29,7 +29,6 @@ import VASSAL.tools.image.ImageLoader; import VASSAL.tools.io.FileArchive; -import VASSAL.tools.io.IOUtils; import VASSAL.tools.lang.Callback; /** @@ -70,22 +69,16 @@ imageListener.receive(ipath); BufferedImage src = null; - InputStream in = null; - try { - in = fa.getInputStream(ipath); + try (InputStream in = fa.getInputStream(ipath)) { src = loader.load( ipath, in, BufferedImage.TYPE_INT_RGB, BufferedImage.TYPE_INT_ARGB_PRE, false ); - in.close(); } catch (IOException e) { logger.error("", e); continue; } - finally { - IOUtils.closeQuietly(in); - } slicer.slice(src, ipath, tpath, tw, th, exec, tileListener); } Modified: VASSAL-src/trunk/src/VASSAL/tools/image/tilecache/ImageToTiles.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/image/tilecache/ImageToTiles.java 2020-05-25 21:48:32 UTC (rev 9429) +++ VASSAL-src/trunk/src/VASSAL/tools/image/tilecache/ImageToTiles.java 2020-05-25 21:48:45 UTC (rev 9430) @@ -34,7 +34,6 @@ import VASSAL.tools.image.ImageIOImageLoader; import VASSAL.tools.image.ImageLoader; import VASSAL.tools.image.ImageTypeConverter; -import VASSAL.tools.io.IOUtils; import VASSAL.tools.io.TemporaryFileFactory; import VASSAL.tools.lang.Callback; @@ -84,18 +83,12 @@ final ImageLoader loader = new ImageIOImageLoader(itc); BufferedImage src = null; - InputStream in = null; - try { - in = new FileInputStream(ipath); + try (InputStream in = new FileInputStream(ipath)) { src = loader.load( ipath, in, BufferedImage.TYPE_INT_RGB, BufferedImage.TYPE_INT_ARGB_PRE, false ); - in.close(); } - finally { - IOUtils.closeQuietly(in); - } final String iname = new File(ipath).getName(); final Callback<Void> dotter = new Callback<>() { Modified: VASSAL-src/trunk/src/VASSAL/tools/version/VersionUtils.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/tools/version/VersionUtils.java 2020-05-25 21:48:32 UTC (rev 9429) +++ VASSAL-src/trunk/src/VASSAL/tools/version/VersionUtils.java 2020-05-25 21:48:45 UTC (rev 9430) @@ -32,17 +32,11 @@ } private static VassalVersion getVersion(String url) throws IOException { - InputStream in = null; - try { - in = new URL(url).openStream(); + try (InputStream in = new URL(url).openStream()) { final VassalVersion version = new VassalVersion(IOUtils.toString(in).trim()); - in.close(); return version; } - finally { - IOUtils.closeQuietly(in); - } } /* Modified: VASSAL-src/trunk/test/VASSAL/tools/image/ImageIOImageLoaderTest.java =================================================================== --- VASSAL-src/trunk/test/VASSAL/tools/image/ImageIOImageLoaderTest.java 2020-05-25 21:48:32 UTC (rev 9429) +++ VASSAL-src/trunk/test/VASSAL/tools/image/ImageIOImageLoaderTest.java 2020-05-25 21:48:45 UTC (rev 9430) @@ -47,19 +47,13 @@ protected BufferedImage read(ImageLoader loader, String file) throws IOException { - FileInputStream in = null; - try { - in = new FileInputStream(file); + try (FileInputStream in = new FileInputStream(file)) { final BufferedImage img = loader.load( file, in, BufferedImage.TYPE_INT_RGB, BufferedImage.TYPE_INT_ARGB, false ); - in.close(); return img; } - finally { - IOUtils.closeQuietly(in); - } } @Test @@ -107,16 +101,10 @@ } protected Dimension size(ImageLoader loader, String file) throws IOException { - FileInputStream in = null; - try { - in = new FileInputStream(file); + try (FileInputStream in = new FileInputStream(file)) { final Dimension d = loader.size(file, in); - in.close(); return d; } - finally { - IOUtils.closeQuietly(in); - } } @Test Modified: VASSAL-src/trunk/test/VASSAL/tools/io/TailerTest.java =================================================================== --- VASSAL-src/trunk/test/VASSAL/tools/io/TailerTest.java 2020-05-25 21:48:32 UTC (rev 9429) +++ VASSAL-src/trunk/test/VASSAL/tools/io/TailerTest.java 2020-05-25 21:48:45 UTC (rev 9430) @@ -93,14 +93,9 @@ final String actual = sb_tailer.toString(); String expected = null; - FileInputStream in = null; - try { - in = new FileInputStream(file); + try (FileInputStream in = new FileInputStream(file)) { expected = IOUtils.toString(in).substring(0, actual.length()); } - finally { - IOUtils.closeQuietly(in); - } // compare whatever the Tailer had time to read assertEquals(expected, actual); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |