Class ByteOrderMarkSkippingInputStream

All Implemented Interfaces:
Closeable, AutoCloseable

public final class ByteOrderMarkSkippingInputStream extends PushbackInputStream
THE stdin of every long-running EK9 protocol server (ek9 -mcp, ek9 -ls, ek9 -dap): the stream it is given, with a UTF-8 byte order mark (EF BB BF) at its very START consumed and discarded. Use it - never a private BOM check in one server.

Why: Windows PowerShell 5.1's .NET writes a byte order mark into a child's stdin the moment the child starts when the console's input encoding is UTF-8 (measured 2026-11-15: ek9 -mcp then logged "malformed JSON: Unexpected character (code 65279)" and never answered initialize). JSON-RPC has no byte order mark, so one ahead of the first message can only be that, and skipping it makes the server answer the same from PowerShell, a normal terminal, macOS and Linux.

The check is made once, lazily, on the first read - so constructing this never blocks - and only the first three bytes are looked at: a stream that does not start with the whole mark is returned unchanged, byte for byte (a partial EF or EF BB is pushed back). A byte order mark anywhere later is data and is left alone.