Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 2, 2025

This PR adds a new IO.copy(InputStream, OutputStream) method to the airframe-control module for copying data between streams on JVM and Native platforms.

Changes

  • Added IO.copy(in: InputStream, out: OutputStream): Unit method to the shared IO object
  • Method uses 8192-byte buffer (consistent with existing readFully method)
  • Properly handles null inputs without throwing exceptions
  • Uses withResource for automatic resource management of InputStream
  • Calls flush() on OutputStream to ensure buffered data is written
  • Added comprehensive tests covering normal operation, edge cases, and large data transfers

Usage

import wvlet.airframe.control.IO
import java.io.{FileInputStream, FileOutputStream}

val input = new FileInputStream("source.txt")
val output = new FileOutputStream("destination.txt")
IO.copy(input, output)

Platform Support

  • JVM: Fully supported
  • Native: Fully supported
  • ⚠️ JS: Compiles but InputStream/OutputStream are not practically usable on JavaScript

The method is available on all platforms that support Java IO classes (JVM and Native), while JS compilation succeeds but the classes themselves are not meaningful in a JavaScript context.

Testing

Added comprehensive test suite (IOTest) that verifies:

  • Basic copy functionality with various data sizes
  • Null input/output stream handling
  • Empty stream handling
  • Large data transfers (>8KB to test buffer logic)

All tests pass on JVM and Native platforms.

Fixes #396.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: xerial <57538+xerial@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Add IO.copy(InputStream, OutputStream) to airframe-control (only for JVM/Native) Add IO.copy(InputStream, OutputStream) method to airframe-control Jun 2, 2025
@Copilot Copilot AI requested a review from xerial June 2, 2025 17:43
Copilot finished work on behalf of xerial June 2, 2025 17:44
@xerial
Copy link
Member

xerial commented Jun 2, 2025

The code needs to be reformatted with ./sbt scalafmtAll

…of silently consuming errors

Co-authored-by: xerial <57538+xerial@users.noreply.github.com>
Copilot finished work on behalf of xerial June 2, 2025 17:56
Copy link
Contributor Author

Copilot AI commented Jun 2, 2025

The code needs to be reformatted with ./sbt scalafmtAll

Code formatting has been verified with ./sbt scalafmtAll - no changes were needed as the code was already properly formatted.

Copilot finished work on behalf of xerial June 2, 2025 18:00
@xerial xerial marked this pull request as ready for review June 2, 2025 19:08
@xerial xerial merged commit ef5c66b into main Jun 2, 2025
29 of 30 checks passed
@xerial xerial deleted the copilot/fix-396-2 branch June 2, 2025 19:25
@xerial xerial added the feature label Jun 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add IO.copy(InputStream, OutputStream) to airframe-control (only for JVM/Native)
2 participants