Skip to content

Commit c7842b0

Browse files
ctruedenclaude
andcommitted
scijava-io3: port data handles
Ports org.scijava.io.handle as org.scijava.io3.handle, plus Bytes, which the handles need. Same standalone approach as the locations: plain ServiceLoader, no container, scijava-collections the only dependency. DataHandle no longer extends WrapperPlugin. That contract was small -- getType() plus set/get -- so it is inlined as locationType(), supports(), set(), get() and priority(). Nothing else among the fifteen handle classes needed the plugin framework. DataHandleService becomes DataHandles, which also absorbs the static helpers from SciJava Common's DataHandles utility class. Two things the port made explicit: - Discovered handles are prototypes. A handle carries the position and buffers of one open stream, so create() must instantiate a fresh one per call rather than hand out the discovered instance. SciJava Common got this from WrapperService.create(); here it is explicit, with a test asserting that two handles on one file have independent offsets. - DataHandles.copy reported progress to a Task, which also carried cancellation. Progress is now a plain LongConsumer of the running byte count, so callers wanting org.scijava.progress can adapt it in a lambda. Cancellation is therefore no longer supported by copy; if it is wanted it should be a deliberate mechanism, not a side effect of the progress type. Recorded as an open question in the plan. Still to port in this component: io.nio. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013gJpzGd3ksbME4CN6Tu2ni
1 parent 790ec74 commit c7842b0

21 files changed

Lines changed: 4058 additions & 2 deletions

‎docs/migration-plan.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,19 @@ No application context required by anything in this phase.
307307
rather than depending on `scijava-priority`; the `Priority` constants are
308308
compatible with it. `Locations` can also be constructed with an explicit
309309
resolver list, for embedding and testing.
310+
- Handles are **done** too, on the same pattern: `DataHandle` absorbs the
311+
tiny `WrapperPlugin` contract (`locationType`, `supports`, `set`, `get`,
312+
`priority`) instead of extending the plugin framework, and
313+
`DataHandleService` becomes `DataHandles`.
314+
- Note that discovered handles are **prototypes**: a handle carries the
315+
position and buffers of one open stream, so `create()` instantiates a
316+
fresh one per call. SciJava Common got this from `WrapperService`; here
317+
it is explicit, and tested.
318+
- **Open question:** `DataHandles.copy` took a `Task`, which carried both
319+
progress *and cancellation*; its replacement `LongConsumer` carries only
320+
progress. If cancellable copies are wanted, that needs a deliberate
321+
mechanism rather than falling out of the progress type.
322+
- Still to port: `io.nio`.
310323
- **`scijava-events`** (new, `org.scijava.events`): a clean-room event bus,
311324
no context, designed for typed topics and weak-reference subscribers. Not a
312325
port of the bushe fork — rewriting removes the attribution obligation. The

‎docs/migration.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ A **dropped** row is a successful outcome, not a gap.
2323
| `AppUtils` | `org.scijava.common3.Apps` | ported |
2424
| `ArrayUtils` | mostly dropped: `contains`/`indexOf` → `Arrays.asList(a).contains(v)` for object arrays, a loop or stream for primitives; `array` → an array literal; `toCollection` → no replacement. `safeMultiply32`/`safeMultiply64` → `common3.Numbers` (they wrap `Math.multiplyExact`) | ported |
2525
| `BoolArray`, `ByteArray`, `CharArray`, `DoubleArray`, `FloatArray`, `IntArray`, `LongArray`, `ObjectArray`, `ShortArray`, `PrimitiveArray` | `org.scijava.collections.*` | ported |
26-
| `Bytes` | `scijava-io3`, alongside the handles that need it (Phase 1, in progress) | planned |
26+
| `Bytes` | `org.scijava.io3.Bytes` | ported |
2727
| `CheckSezpoz` | none | dropped |
2828
| `ClassUtils` | `org.scijava.common3.Classes` (mostly already deprecated in SJC) | ported |
2929
| `ColorRGB`, `ColorRGBA`, `Colors` | UI layer (Phase 4) | open |
@@ -99,7 +99,8 @@ A **dropped** row is a successful outcome, not a gap.
9999
| `annotations.legacy` | none — reads the pre-2013 `META-INF/annotations/` format | dropped |
100100
| `io.location` | `org.scijava.io3.location`. `LocationService`/`DefaultLocationService` become `Locations`, backed by plain `ServiceLoader`; `LocationResolver` no longer extends `HandlerPlugin` and carries its own `priority()`. `URILocation`'s injected `LogService` was dead code and is gone | ported |
101101
| `ByteBank`, `ByteArrayByteBank` | `org.scijava.io3` | ported |
102-
| `io.handle`, `io.nio` | `org.scijava.io3.handle` (Phase 1, in progress) | planned |
102+
| `io.handle` | `org.scijava.io3.handle`. `DataHandle` no longer extends `WrapperPlugin`: the contract was `getType()` plus `set`/`get`, now inlined as `locationType()`, `supports`, `set`, `get` and `priority()`. `DataHandleService` becomes `DataHandles`, backed by plain `ServiceLoader`. `DataHandles.copy` reports progress to a `LongConsumer` rather than a `Task`, and so no longer supports cancellation | ported |
103+
| `io.nio` | not yet ported — `ByteBuffer`-backed byte banks | planned |
103104
| `io` (`IOPlugin`, `IOService`, `RecentFileService`) | `scijava-io3` (Phase 1), pending review of what is still used | open |
104105
| `event`, `event.bushe` | `org.scijava.events` — clean-room rewrite, not a port (Phase 1) | planned |
105106
| `parse` | Parsington (`org.scijava.parsington`) | planned |

‎scijava-io3/src/main/java/module-info.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,19 @@
3030
module org.scijava.io3 {
3131

3232
exports org.scijava.io3;
33+
exports org.scijava.io3.handle;
3334
exports org.scijava.io3.location;
3435

3536
requires org.scijava.collections;
3637

38+
uses org.scijava.io3.handle.DataHandle;
3739
uses org.scijava.io3.location.LocationResolver;
3840

41+
provides org.scijava.io3.handle.DataHandle with
42+
org.scijava.io3.handle.FileHandle,
43+
org.scijava.io3.handle.BytesHandle,
44+
org.scijava.io3.handle.DummyHandle;
45+
3946
provides org.scijava.io3.location.LocationResolver with
4047
org.scijava.io3.location.FileLocationResolver;
4148

0 commit comments

Comments
 (0)