diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index de7d52f6625dc6fb7fcadc237162403aa7dbcc1d..3eaed869062fe94cef2bd0ebf58d2364f966bc65 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -697,10 +697,8 @@ public class Compressor { LOG.error(PackingToolErrMsg.SET_GENERATE_BUILD_HASH.toString(errMsg)); throw new BundleException("Set generate build hash failed for --json-path file does not exist."); } - InputStream json = null; - BufferedWriter bw = null; - try { - json = new FileInputStream(file); + try (InputStream json = new FileInputStream(file); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter( + new FileOutputStream(utility.getJsonPath()), StandardCharsets.UTF_8))) { JSONObject jsonObject = JSON.parseObject(json, JSONObject.class); if (!jsonObject.containsKey(APP) || !jsonObject.containsKey(MODULE)) { LOG.error(PackingToolErrMsg.SET_GENERATE_BUILD_HASH.toString("Parse --json-path file is invalid.")); @@ -720,8 +718,6 @@ public class Compressor { String pretty = JSON.toJSONString(jsonObject, new SerializerFeature[]{ SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat}); - bw = new BufferedWriter(new OutputStreamWriter( - new FileOutputStream(utility.getJsonPath()), StandardCharsets.UTF_8)); bw.write(pretty); } catch (BundleException exception) { LOG.error(PackingToolErrMsg.SET_GENERATE_BUILD_HASH.toString( @@ -732,18 +728,6 @@ public class Compressor { "The json data err, exist Exception (NullPointerException | IOException | JSONException): " + e.getMessage())); throw new BundleException("Set generate build hash failed, json data err."); - } finally { - FileUtils.closeStream(json); - if (bw != null) { - try { - bw.flush(); - bw.close(); - } catch (IOException e) { - LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString( - "Set generate build hash exist IOException: " + e.getMessage())); - throw new BundleException("Set generate build hash failed."); - } - } } } diff --git a/adapter/ohos/ModuleJsonUtil.java b/adapter/ohos/ModuleJsonUtil.java index b2cf57abf9b359d4d69d9eb1418c9c74e61a7918..9de3cc14ae8ecb5c7bb0b9092344395274c6b365 100644 --- a/adapter/ohos/ModuleJsonUtil.java +++ b/adapter/ohos/ModuleJsonUtil.java @@ -1995,7 +1995,8 @@ class ModuleJsonUtil { boolean installationFree = getJsonBooleanValue(moduleObj, INSTALLATION_FREE, false); if (!appObj.containsKey(BUNDLE_TYPE)) { if (installationFree) { - String errMsg = "The app.json5 file configuration does not match the 'installationFree' setting of true."; + String errMsg = "The app.json5 file configuration" + + "does not match the 'installationFree' setting of true."; String solution = "Add the 'bundleType' field to the app.json5 file and set it atomicService."; LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED.toString(errMsg, solution)); return false;