@Test public void shouldFormat5TextBytesAsText() throws Exception { Mockery context = new Mockery(); final Emitter emitter = context.mock(Emitter.class); ByteArrayWriter writer = new ByteArrayWriter(Type.READ, emitter); context.checking(new Expectations() { { oneOf(emitter).add("read \""); oneOf(emitter).add("abcde"); oneOf(emitter).add("\""); oneOf(emitter).add("\n"); } }); writer.write("abcde".getBytes(UTF8)); context.assertIsSatisfied(); }
public void write(byte[] bytes) { this.bytes = bytes; start = 0; state = State.BINARY; for (position=0; position < bytes.length; position++) { int codePoint = bytes[position] & 0xFF; if (shouldTreatAsText(codePoint)) { switch(state) { case BINARY: transitionBinaryToCandidateText(); break; case CANDIDATE_TEXT: if (position + 1 - startCandidateText == ASSUME_TEXT_AFTER) { transitionCandidateTextToText(); } break; default: break; } } else { switch(state) { case CANDIDATE_TEXT: transitionCandidateTextToBinary(); break; case TEXT: transitionTextToBinary(); break; default: break; } } } transitionToEnd(); }
ByteArrayWriter { public void write(byte[] bytes) { this.bytes = bytes; start = 0; state = State.BINARY; for (position=0; position < bytes.length; position++) { int codePoint = bytes[position] & 0xFF; if (shouldTreatAsText(codePoint)) { switch(state) { case BINARY: transitionBinaryToCandidateText(); break; case CANDIDATE_TEXT: if (position + 1 - startCandidateText == ASSUME_TEXT_AFTER) { transitionCandidateTextToText(); } break; default: break; } } else { switch(state) { case CANDIDATE_TEXT: transitionCandidateTextToBinary(); break; case TEXT: transitionTextToBinary(); break; default: break; } } } transitionToEnd(); } }
ByteArrayWriter { public void write(byte[] bytes) { this.bytes = bytes; start = 0; state = State.BINARY; for (position=0; position < bytes.length; position++) { int codePoint = bytes[position] & 0xFF; if (shouldTreatAsText(codePoint)) { switch(state) { case BINARY: transitionBinaryToCandidateText(); break; case CANDIDATE_TEXT: if (position + 1 - startCandidateText == ASSUME_TEXT_AFTER) { transitionCandidateTextToText(); } break; default: break; } } else { switch(state) { case CANDIDATE_TEXT: transitionCandidateTextToBinary(); break; case TEXT: transitionTextToBinary(); break; default: break; } } } transitionToEnd(); } ByteArrayWriter(Type type, Emitter emitter); private  ByteArrayWriter(Emitter emitter, String textStart, String textEnd, String hexStart, String hexEnd); }
ByteArrayWriter { public void write(byte[] bytes) { this.bytes = bytes; start = 0; state = State.BINARY; for (position=0; position < bytes.length; position++) { int codePoint = bytes[position] & 0xFF; if (shouldTreatAsText(codePoint)) { switch(state) { case BINARY: transitionBinaryToCandidateText(); break; case CANDIDATE_TEXT: if (position + 1 - startCandidateText == ASSUME_TEXT_AFTER) { transitionCandidateTextToText(); } break; default: break; } } else { switch(state) { case CANDIDATE_TEXT: transitionCandidateTextToBinary(); break; case TEXT: transitionTextToBinary(); break; default: break; } } } transitionToEnd(); } ByteArrayWriter(Type type, Emitter emitter); private  ByteArrayWriter(Emitter emitter, String textStart, String textEnd, String hexStart, String hexEnd); void write(byte[] bytes); }
ByteArrayWriter { public void write(byte[] bytes) { this.bytes = bytes; start = 0; state = State.BINARY; for (position=0; position < bytes.length; position++) { int codePoint = bytes[position] & 0xFF; if (shouldTreatAsText(codePoint)) { switch(state) { case BINARY: transitionBinaryToCandidateText(); break; case CANDIDATE_TEXT: if (position + 1 - startCandidateText == ASSUME_TEXT_AFTER) { transitionCandidateTextToText(); } break; default: break; } } else { switch(state) { case CANDIDATE_TEXT: transitionCandidateTextToBinary(); break; case TEXT: transitionTextToBinary(); break; default: break; } } } transitionToEnd(); } ByteArrayWriter(Type type, Emitter emitter); private  ByteArrayWriter(Emitter emitter, String textStart, String textEnd, String hexStart, String hexEnd); void write(byte[] bytes); static final int MAX_TEXT_LINE_SIZE; }