Source:
<code>public FilestoreModel.Status uploadBlob(String oid, long size, UserModel user, RepositoryModel repo, InputStream streamIn) { Status state = addObject(oid, size, user, repo); if (state != Status.Upload_Pending) { return state; } FilestoreModel model = fileCache.get(oid); if (!model.actionUpload(user)) { return Status.Upload_In_Progress; } else { long actualSize = 0; File file = getStoragePath(oid); try { file.getParentFile().mkdirs(); file.createNewFile(); <START> FileOutputStream streamOut = new FileOutputStream(file); <END> actualSize = IOUtils.copyLarge(streamIn, streamOut); streamOut.flush(); streamOut.close(); if (model.getSize() != actualSize) { model.setStatus(Status.Error_Size_Mismatch, user); logger.warn(MessageFormat.format("Failed to upload blob {0} due to size mismatch, expected {1} got {2}", oid, model.getSize(), actualSize)); } else { FileInputStream fileForHash = new FileInputStream(file); String actualOid = DigestUtils.sha256Hex(fileForHash); fileForHash.close(); if (oid.equalsIgnoreCase(actualOid)) { model.setStatus(Status.Available, user); } else { model.setStatus(Status.Error_Hash_Mismatch, user); logger.warn(MessageFormat.format("Failed to upload blob {0} due to hash mismatch, got {1}", oid, actualOid)); } } } catch (Exception e) { model.setStatus(Status.Error_Unknown, user); logger.warn(MessageFormat.format("Failed to upload blob {0}", oid), e); } finally { saveFilestoreModel(model); } if (model.isInErrorState()) { file.delete(); model.removeRepository(repo.name); } } return model.getStatus(); }</code><technical_language>try (FileOutputStream streamOut = new FileOutputStream(file))</technical_language>

Target:
public FilestoreModel.Status uploadBlob(String oid, long size, UserModel user, RepositoryModel repo, InputStream streamIn) { Status state = addObject(oid, size, user, repo); if (state != Status.Upload_Pending) { return state; } FilestoreModel model = fileCache.get(oid); if (!model.actionUpload(user)) { return Status.Upload_In_Progress; } else { long actualSize = 0; File file = getStoragePath(oid); try { file.getParentFile().mkdirs(); file.createNewFile(); try (FileOutputStream streamOut = new FileOutputStream(file)) { actualSize = IOUtils.copyLarge(streamIn, streamOut); streamOut.flush(); streamOut.close(); if (model.getSize() != actualSize) { model.setStatus(Status.Error_Size_Mismatch, user); logger.warn(MessageFormat.format("Failed to upload blob {0} due to size mismatch, expected {1} got {2}", oid, model.getSize(), actualSize)); } else { String actualOid = ""; try (FileInputStream fileForHash = new FileInputStream(file)) { actualOid = DigestUtils.sha256Hex(fileForHash); fileForHash.close(); } if (oid.equalsIgnoreCase(actualOid)) { model.setStatus(Status.Available, user); } else { model.setStatus(Status.Error_Hash_Mismatch, user); logger.warn(MessageFormat.format("Failed to upload blob {0} due to hash mismatch, got {1}", oid, actualOid)); } } } } catch (Exception e) { model.setStatus(Status.Error_Unknown, user); logger.warn(MessageFormat.format("Failed to upload blob {0}", oid), e); } finally { saveFilestoreModel(model); } if (model.isInErrorState()) { file.delete(); model.removeRepository(repo.name); } } return model.getStatus(); }