@@ -573,13 +573,16 @@ public FlagUsageException(String message) {
573
573
574
574
public List <JsonFileSpec > parseJsonFilesFromInputStream () throws IOException {
575
575
List <JsonFileSpec > jsonFiles = new ArrayList <JsonFileSpec >();
576
- try (JsonReader reader = new JsonReader (new InputStreamReader (this .in , inputCharset ))) {
576
+ JsonReader reader = new JsonReader (new InputStreamReader (this .in , inputCharset ));
577
+ try {
577
578
reader .beginArray ();
578
579
while (reader .hasNext ()) {
579
580
JsonFileSpec jsonFile = gson .fromJson (reader , JsonFileSpec .class );
580
581
jsonFiles .add (jsonFile );
581
582
}
582
583
reader .endArray ();
584
+ } finally {
585
+ reader .close ();
583
586
}
584
587
return jsonFiles ;
585
588
}
@@ -1216,8 +1219,11 @@ int processResults(Result result, List<JSModule> modules, B options) throws IOEx
1216
1219
1217
1220
// Output the externs if required.
1218
1221
if (options .externExportsPath != null ) {
1219
- try (Writer eeOut = openExternExportsStream (options , config .jsOutputFile )) {
1222
+ Writer eeOut = openExternExportsStream (options , config .jsOutputFile );
1223
+ try {
1220
1224
eeOut .append (result .externExport );
1225
+ } finally {
1226
+ eeOut .close ();
1221
1227
}
1222
1228
}
1223
1229
@@ -1289,8 +1295,9 @@ JsonFileSpec createJsonFile(B options, String outputMarker,
1289
1295
}
1290
1296
1291
1297
void outputJsonStream () throws IOException {
1292
- try (JsonWriter jsonWriter =
1293
- new JsonWriter (new BufferedWriter (new OutputStreamWriter (defaultJsOutput , "UTF-8" )))) {
1298
+ JsonWriter jsonWriter =
1299
+ new JsonWriter (new BufferedWriter (new OutputStreamWriter (defaultJsOutput , "UTF-8" )));
1300
+ try {
1294
1301
jsonWriter .beginArray ();
1295
1302
for (JsonFileSpec jsonFile : this .filesToStreamOut ) {
1296
1303
jsonWriter .beginObject ();
@@ -1302,6 +1309,8 @@ void outputJsonStream() throws IOException {
1302
1309
jsonWriter .endObject ();
1303
1310
}
1304
1311
jsonWriter .endArray ();
1312
+ } finally {
1313
+ jsonWriter .close ();
1305
1314
}
1306
1315
}
1307
1316
@@ -1335,14 +1344,17 @@ private DiagnosticType outputModuleBinaryAndSourceMaps(List<JSModule> modules, B
1335
1344
}
1336
1345
1337
1346
String moduleFilename = getModuleOutputFileName (m );
1338
- try (Writer writer = fileNameToLegacyOutputWriter (moduleFilename )) {
1347
+ Writer writer = fileNameToLegacyOutputWriter (moduleFilename );
1348
+ try {
1339
1349
if (options .sourceMapOutputPath != null ) {
1340
1350
compiler .getSourceMap ().reset ();
1341
1351
}
1342
1352
writeModuleOutput (writer , m );
1343
1353
if (options .sourceMapOutputPath != null ) {
1344
1354
compiler .getSourceMap ().appendTo (mapFileOut , moduleFilename );
1345
1355
}
1356
+ } finally {
1357
+ writer .close ();
1346
1358
}
1347
1359
1348
1360
if (shouldGenerateMapPerModule (options ) && mapFileOut != null ) {
@@ -1595,8 +1607,11 @@ private void outputSourceMap(B options, String associatedName)
1595
1607
1596
1608
String outName = expandSourceMapPath (options , null );
1597
1609
maybeCreateDirsForPath (outName );
1598
- try (Writer out = fileNameToOutputWriter2 (outName )) {
1610
+ Writer out = fileNameToOutputWriter2 (outName );
1611
+ try {
1599
1612
compiler .getSourceMap ().appendTo (out , associatedName );
1613
+ } finally {
1614
+ out .close ();
1600
1615
}
1601
1616
}
1602
1617
@@ -1689,10 +1704,13 @@ private void outputNameMaps() throws IOException {
1689
1704
1690
1705
if (functionInformationMapOutputPath != null
1691
1706
&& compiler .getFunctionalInformationMap () != null ) {
1692
- try (final OutputStream file = filenameToOutputStream (functionInformationMapOutputPath )) {
1707
+ final OutputStream file = filenameToOutputStream (functionInformationMapOutputPath );
1708
+ try {
1693
1709
CodedOutputStream outputStream = CodedOutputStream .newInstance (file );
1694
1710
compiler .getFunctionalInformationMap ().writeTo (outputStream );
1695
1711
outputStream .flush ();
1712
+ } finally {
1713
+ file .close ();
1696
1714
}
1697
1715
}
1698
1716
}
@@ -1803,17 +1821,21 @@ private void outputManifestOrBundle(List<String> outputFiles,
1803
1821
JSModuleGraph graph = compiler .getDegenerateModuleGraph ();
1804
1822
Iterable <JSModule > modules = graph .getAllModules ();
1805
1823
for (JSModule module : modules ) {
1806
- try (Writer out = fileNameToOutputWriter2 (expandCommandLinePath (output , module ))) {
1824
+ Writer out = fileNameToOutputWriter2 (expandCommandLinePath (output , module ));
1825
+ try {
1807
1826
if (isManifest ) {
1808
1827
printManifestTo (module .getInputs (), out );
1809
1828
} else {
1810
1829
printBundleTo (module .getInputs (), out );
1811
1830
}
1831
+ } finally {
1832
+ out .close ();
1812
1833
}
1813
1834
}
1814
1835
} else {
1815
1836
// Generate a single file manifest or bundle.
1816
- try (Writer out = fileNameToOutputWriter2 (expandCommandLinePath (output , null ))) {
1837
+ Writer out = fileNameToOutputWriter2 (expandCommandLinePath (output , null ));
1838
+ try {
1817
1839
if (config .module .isEmpty ()) {
1818
1840
if (isManifest ) {
1819
1841
printManifestTo (compiler .getInputsInOrder (), out );
@@ -1824,6 +1846,8 @@ private void outputManifestOrBundle(List<String> outputFiles,
1824
1846
printModuleGraphManifestOrBundleTo (
1825
1847
compiler .getDegenerateModuleGraph (), out , isManifest );
1826
1848
}
1849
+ } finally {
1850
+ out .close ();
1827
1851
}
1828
1852
}
1829
1853
}
@@ -1835,8 +1859,11 @@ private void outputManifestOrBundle(List<String> outputFiles,
1835
1859
private void outputModuleGraphJson () throws IOException {
1836
1860
if (config .outputModuleDependencies != null &&
1837
1861
config .outputModuleDependencies .length () != 0 ) {
1838
- try (Writer out = fileNameToOutputWriter2 (config .outputModuleDependencies )) {
1862
+ Writer out = fileNameToOutputWriter2 (config .outputModuleDependencies );
1863
+ try {
1839
1864
printModuleGraphJsonTo (out );
1865
+ } finally {
1866
+ out .close ();
1840
1867
}
1841
1868
}
1842
1869
}
0 commit comments