BindingReader { public String readStringUntil(String sequence) { StringBuilder sb = new StringBuilder(); if (!pushBackChar.isEmpty()) { pushBackChar.forEach(sb::appendCodePoint); } try { char[] buf = new char[64]; while (true) { int idx = sb.indexOf(sequence, Math.max(0, sb.length() - buf.length - sequence.length())); if (idx >= 0) { String rem = sb.substring(idx + sequence.length()); runMacro(rem); return sb.substring(0, idx); } int l = reader.readBuffered(buf); if (l < 0) { throw new ClosedException(); } sb.append(buf, 0, l); } } catch (ClosedException e) { throw new EndOfFileException(e); } catch (IOException e) { throw new IOError(e); } } BindingReader(NonBlockingReader reader); T readBinding(KeyMap<T> keys); T readBinding(KeyMap<T> keys, KeyMap<T> local); T readBinding(KeyMap<T> keys, KeyMap<T> local, boolean block); String readStringUntil(String sequence); int readCharacter(); int readCharacterBuffered(); int peekCharacter(long timeout); void runMacro(String macro); String getCurrentBuffer(); String getLastBinding();  }
@Test public void testBindingReaderReadString() { in.setIn(new ByteArrayInputStream("\uD834\uDD21abc0123456789defg".getBytes(StandardCharsets.UTF_8))); BindingReader reader = new BindingReader(terminal.reader()); String str = reader.readStringUntil("fg"); assertEquals("\uD834\uDD21abc0123456789de", str); }