Skip to content

feat: Add appendFile method to FileClient#226

Open
manishdait wants to merge 7 commits into
hiero-ledger:mainfrom
manishdait:feat/append_file
Open

feat: Add appendFile method to FileClient#226
manishdait wants to merge 7 commits into
hiero-ledger:mainfrom
manishdait:feat/append_file

Conversation

@manishdait

Copy link
Copy Markdown
Contributor

Description:
This PR introduce appendFile() method to FileClient

Changes Made

  • Added appendFile() method to the file client.
  • Created a private method appendRemainingChunk() for the common append logic
  • Added test to verify the append chunk method

Related issue(s):

Fixes #225

Notes for reviewer:

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

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>
@manishdait manishdait changed the title Feat/append file feat: Add appendFile method to FileClient Jun 22, 2026
@manishdait manishdait marked this pull request as ready for review June 22, 2026 15:00
@manishdait manishdait requested review from a team as code owners June 22, 2026 15:00
@manishdait manishdait self-assigned this Jun 22, 2026
@manishdait manishdait added the status: ready-for-review PR is ready to be reviewed by team member label Jun 22, 2026
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@manishdait, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 33dd5295-34dd-472e-b8c0-a1d741424a70

📥 Commits

Reviewing files that changed from the base of the PR and between 542237f and 1bc8728.

📒 Files selected for processing (2)
  • hiero-enterprise-base/src/main/java/org/hiero/base/implementation/FileClientImpl.java
  • hiero-enterprise-base/src/test/java/org/hiero/base/test/FileClientImplTest.java

Note

.coderabbit.yml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key: "path_instructions"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Walkthrough

Adds appendFile to the FileClient interface as three new default overloads (accepting String IDs and/or String content with UTF-8 conversion) and implements the method in FileClientImpl with size validation, single-chunk and multi-chunk logic, and a shared appendRemainingChunks helper. Existing chunked-append loops in createFileImpl and updateFile are refactored to use the new helper. Unit and integration tests are added across base, microprofile, and Spring modules.

Changes

appendFile feature

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
Loading

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3045510 and 38ea11c.

📒 Files selected for processing (6)
  • hiero-enterprise-base/src/main/java/org/hiero/base/FileClient.java
  • 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
  • hiero-enterprise-base/src/test/java/org/hiero/base/test/FileClientImplTest.java
  • hiero-enterprise-microprofile/src/test/java/org/hiero/microprofile/test/FileClientTests.java
  • hiero-enterprise-spring/src/test/java/org/hiero/spring/test/FileClientTests.java

Comment thread hiero-enterprise-base/src/main/java/org/hiero/base/FileClient.java
@aceppaluni aceppaluni added the status: needs developer revision author needs to implement changes label Jun 22, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Avoid repeated tail-copying in chunk append loop.

appendRemainingChunks(...) repeatedly rebuilds remaining with Arrays.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

📥 Commits

Reviewing files that changed from the base of the PR and between 38ea11c and 542237f.

📒 Files selected for processing (2)
  • hiero-enterprise-base/src/main/java/org/hiero/base/implementation/FileClientImpl.java
  • hiero-enterprise-base/src/test/java/org/hiero/base/test/FileClientImplTest.java

Signed-off-by: Manish Dait <daitmanish88@gmail.com>
@manishdait manishdait removed the status: needs developer revision author needs to implement changes label Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: ready-for-review PR is ready to be reviewed by team member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create appendFile method in file client

2 participants