feat: Add appendFile method to FileClient#226
Conversation
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
appendFile method to FileClient
|
Warning Review limit reached
More reviews will be available in 38 minutes and 4 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses rolling per-developer review limits. Reviews become available again as older review attempts age out of the rolling limit window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
Note
|
| Layer / File(s) | Summary |
|---|---|
FileClient interface: appendFile overloads hiero-enterprise-base/src/main/java/org/hiero/base/FileClient.java |
Adds StandardCharsets import and three default appendFile overloads accepting String fileId and/or String content, enforcing non-null validation and delegating to the byte-array abstract method via UTF-8 conversion. |
FileClientImpl: appendFile and appendRemainingChunks hiero-enterprise-base/src/main/java/org/hiero/base/implementation/FileClientImpl.java, hiero-enterprise-base/src/main/java/org/hiero/base/protocol/data/FileAppendRequest.java |
Introduces the public appendFile method with getSize-based size validation and chunked dispatch logic, and extracts appendRemainingChunks as a shared private helper for iterating large payloads in FILE_CREATE_MAX_SIZE chunks. Also inserts a blank line in FileAppendRequest's compact constructor. |
FileClientImpl: Refactoring existing chunk loops hiero-enterprise-base/src/main/java/org/hiero/base/implementation/FileClientImpl.java |
Refactors the inline chunk-append loops in createFileImpl and updateFile to delegate to the new appendRemainingChunks helper instead of duplicating the chunking logic. |
FileClientImplTest: appendFile unit tests hiero-enterprise-base/src/test/java/org/hiero/base/test/FileClientImplTest.java |
Adds unit tests covering the normal append flow, content-exceeds-max exception, combined-size-exceeds-max exception, and large-content multi-chunk scenarios; updates Mockito imports with never and verifyNoInteractions. |
Microprofile and Spring integration tests hiero-enterprise-microprofile/src/test/java/org/hiero/microprofile/test/FileClientTests.java, hiero-enterprise-spring/src/test/java/org/hiero/spring/test/FileClientTests.java |
Adds integration tests in both modules covering basic append with content verification, size-exceeded exception, and chunked append for large payloads; imports HieroException for exception assertions. |
Sequence Diagram(s)
sequenceDiagram
participant Caller
participant FileClientImpl
participant getSize
participant executeFileAppendRequestTransaction
Caller->>FileClientImpl: appendFile(fileId, content)
FileClientImpl->>getSize: getSize(fileId)
getSize-->>FileClientImpl: currentSize
alt currentSize + content.length > FILE_MAX_SIZE
FileClientImpl-->>Caller: throws HieroException
else content.length <= FILE_CREATE_MAX_SIZE
FileClientImpl->>executeFileAppendRequestTransaction: append full content
executeFileAppendRequestTransaction-->>FileClientImpl: success
else content.length > FILE_CREATE_MAX_SIZE
FileClientImpl->>executeFileAppendRequestTransaction: append first chunk
loop remaining.length > 0
FileClientImpl->>executeFileAppendRequestTransaction: append next chunk
end
executeFileAppendRequestTransaction-->>FileClientImpl: success
end
FileClientImpl-->>Caller: void
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The PR title 'feat: Add appendFile method to FileClient' clearly and concisely summarizes the main change: adding a new appendFile method to the FileClient interface and implementation. |
| Description check | ✅ Passed | The PR description is related to the changeset, explaining the addition of appendFile() method, the private helper method appendRemainingChunks(), and testing coverage. |
| Linked Issues check | ✅ Passed | The PR fulfills the requirement from issue #225 by adding appendFile() method overloads to FileClient, enabling appending content to existing files instead of only replacing it via updateFile(). |
| Out of Scope Changes check | ✅ Passed | All changes are in-scope: FileClient interface additions, FileClientImpl implementation, supporting helper methods, file append request formatting, and comprehensive unit/integration tests for the new appendFile functionality. |
| Docstring Coverage | ✅ Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
There was a problem hiding this comment.
Actionable comments posted: 4
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 7d631462-b340-46a6-8f66-702d062c509b
📒 Files selected for processing (6)
hiero-enterprise-base/src/main/java/org/hiero/base/FileClient.javahiero-enterprise-base/src/main/java/org/hiero/base/implementation/FileClientImpl.javahiero-enterprise-base/src/main/java/org/hiero/base/protocol/data/FileAppendRequest.javahiero-enterprise-base/src/test/java/org/hiero/base/test/FileClientImplTest.javahiero-enterprise-microprofile/src/test/java/org/hiero/microprofile/test/FileClientTests.javahiero-enterprise-spring/src/test/java/org/hiero/spring/test/FileClientTests.java
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
hiero-enterprise-base/src/main/java/org/hiero/base/implementation/FileClientImpl.java (1)
214-222: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winAvoid repeated tail-copying in chunk append loop.
appendRemainingChunks(...)repeatedly rebuildsremainingwithArrays.copyOfRange(...), adding avoidable copy/allocation overhead for large payloads across create/update/append flows.♻️ Suggested refactor
- private void appendRemainingChunks(`@NonNull` FileId fileId, byte[] remaining) + private void appendRemainingChunks(`@NonNull` final FileId fileId, `@NonNull` final byte[] remaining) throws HieroException { - while (remaining.length > 0) { - final int length = Math.min(remaining.length, FileCreateRequest.FILE_CREATE_MAX_SIZE); - final byte[] next = Arrays.copyOf(remaining, length); + int offset = 0; + while (offset < remaining.length) { + final int length = + Math.min(remaining.length - offset, FileCreateRequest.FILE_CREATE_MAX_SIZE); + final byte[] next = Arrays.copyOfRange(remaining, offset, offset + length); final FileAppendRequest appendRequest = FileAppendRequest.of(fileId, next); protocolLayerClient.executeFileAppendRequestTransaction(appendRequest); - remaining = Arrays.copyOfRange(remaining, length, remaining.length); + offset += length; } }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: ASSERTIVE
Plan: Pro
Run ID: aaf8185e-1cc6-4498-b3c0-8099845a99a1
📒 Files selected for processing (2)
hiero-enterprise-base/src/main/java/org/hiero/base/implementation/FileClientImpl.javahiero-enterprise-base/src/test/java/org/hiero/base/test/FileClientImplTest.java
542237f to
933a8db
Compare
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
933a8db to
1bc8728
Compare
Description:
This PR introduce
appendFile()method to FileClientChanges Made
appendFile()method to the file client.appendRemainingChunk()for the common append logicRelated issue(s):
Fixes #225
Notes for reviewer:
Checklist