Make use of try with-resources to auto close file.

PiperOrigin-RevId: 412901581
This commit is contained in:
samrobinson 2021-11-29 16:58:35 +00:00 committed by tonihei
parent dd9d87549d
commit d55f9876ac

View File

@ -117,22 +117,19 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
throws IOException { throws IOException {
File analysisFile = File analysisFile =
createExternalCacheFile(context, /* fileName= */ result.testId + "-result.txt"); createExternalCacheFile(context, /* fileName= */ result.testId + "-result.txt");
FileWriter fileWriter = new FileWriter(analysisFile); try (FileWriter fileWriter = new FileWriter(analysisFile)) {
String fileContents = String fileContents =
"test=" "test="
+ result.testId + result.testId
+ ", deviceBrand=" + ", deviceBrand="
+ Build.MANUFACTURER + Build.MANUFACTURER
+ ", deviceModel=" + ", deviceModel="
+ Build.MODEL + Build.MODEL
+ ", sdkVersion=" + ", sdkVersion="
+ Build.VERSION.SDK_INT + Build.VERSION.SDK_INT
+ ", outputSizeBytes=" + ", outputSizeBytes="
+ result.outputSizeBytes; + result.outputSizeBytes;
try {
fileWriter.write(fileContents); fileWriter.write(fileContents);
} finally {
fileWriter.close();
} }
} }