Skip to content

Cl binary nio channel#3919

Draft
clementleclercRTE wants to merge 16 commits into
cl-binary-named-attributesfrom
cl-binary-nio-channel
Draft

Cl binary nio channel#3919
clementleclercRTE wants to merge 16 commits into
cl-binary-named-attributesfrom
cl-binary-nio-channel

Conversation

@clementleclercRTE
Copy link
Copy Markdown
Contributor

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • A PR or issue has been opened in all impacted repositories (if any)

Does this PR already have an issue describing the problem?

Fixes #3881

What kind of change does this PR introduce?

Migrates the binary reader and writer from DataInputStream/DataOutputStream over
BufferedInputStream/BufferedOutputStream to direct ByteBuffer + java.nio.channels.ReadableByteChannel/WritableByteChannel.

What is the current behavior?

  • BinReader wraps the caller's InputStream into a BufferedInputStream + DataInputStream.
  • BinWriter wraps the caller's OutputStream into a BufferedOutputStream + DataOutputStream.
  • NetworkSerDe.copy() uses PipedInputStream/PipedOutputStream.
  • When the underlying source is a Files.newInputStream(path) / Files.newOutputStream(path) (themselves wrapping a FileChannel), the data path goes Channel → Stream → DataStream, with
    redundant adapters.

What is the new behavior (if this is a feature change)?

  • BinReader now reads through a BufferedChannelReader backed by a direct ByteBuffer and a ReadableByteChannel.
    • BinWriter now stages body bytes in a direct ByteBuffer (GrowingByteBuffer) and drains them straight to a WritableByteChannel on close.
    • New public constructors BinReader(ReadableByteChannel, byte[]) / BinReader(Path, byte[]) and BinWriter(WritableByteChannel, byte[], String) / BinWriter(Path, byte[], String) avoid the
      Channel → Stream → Channel double-wrapping when the caller already has a channel (or a Path).
    • NetworkSerDe.read(Path, …) and NetworkSerDe.write(Network, ExportOptions, Path) now dispatch on format: for BIN, they open a Files.newByteChannel(path) directly and feed the channel
      constructors — no OutputStream/InputStream adapter.
    • NetworkSerDe.copy() now uses Pipe.SinkChannel/Pipe.SourceChannel. For BIN, the pipe channels are passed directly to BinWriter/BinReader — no Channels.newOutputStream/newInputStream
      adapter.

Does this PR introduce a breaking change or deprecate an API?

  • Yes
  • No

If yes, please check if the following requirements are fulfilled

  • The Breaking Change or Deprecated label has been added
  • The migration steps are described in the following section

What changes might users need to make in their application due to this PR? (migration steps)

Other information:

…wingByteBuffer` for efficient binary I/O, refactored `BinWriter` to adopt buffer-based writing, and updated tests to validate new implementations.

Signed-off-by: Leclerc Clement <clement.leclerc@rte-france.com>
…ader`

Refactored `BinWriter` to directly manage headers and buffers without intermediate wrapping.

Signed-off-by: Leclerc Clement <clement.leclerc@rte-france.com>
@clementleclercRTE clementleclercRTE marked this pull request as draft May 18, 2026 14:24
clementleclercRTE and others added 12 commits May 18, 2026 16:48
Signed-off-by: Leclerc Clement <clement.leclerc@rte-france.com>
# Conflicts:
#	commons/src/main/java/com/powsybl/commons/binary/BinReader.java
#	commons/src/test/java/com/powsybl/commons/binary/BinWriterReaderTest.java
Signed-off-by: Leclerc Clement <clement.leclerc@rte-france.com>
Signed-off-by: Leclerc Clement <clement.leclerc@rte-france.com>
…f direct allocation for improved performance in small-element writes.

Signed-off-by: Leclerc Clement <clement.leclerc@rte-france.com>
…ed `BinWriter` drain logic for improved memory management and performance.

Signed-off-by: Leclerc Clement <clement.leclerc@rte-france.com>
Signed-off-by: Leclerc Clement <clement.leclerc@rte-france.com>
Signed-off-by: Damien Jeandemange <damien.jeandemange@artelys.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 1, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants