@Test public void testFilter() throws Exception { StringWriter stringWriter = new StringWriter(); GuacamoleWriter writer = new FilteredGuacamoleWriter(new WriterGuacamoleWriter(stringWriter), new TestFilter()); writer.write("3.yes,1.A;2.no,1.B;3.yes,1.C;3.yes,1.D;4.nope,1.E;".toCharArray()); writer.write("1.n,3.abc;3.yes,5.hello;2.no,4.test;3.yes,5.world;".toCharArray()); assertEquals("3.yes,1.A;3.yes,1.C;3.yes,1.D;3.yes,5.hello;3.yes,5.world;", stringWriter.toString()); }
@Override public void write(char[] chunk, int offset, int length) throws GuacamoleException { while (length > 0) { int parsed; while ((parsed = parser.append(chunk, offset, length)) != 0) { offset += parsed; length -= parsed; } if (!parser.hasNext()) throw new GuacamoleServerException("Filtered write() contained an incomplete instruction."); writeInstruction(parser.next()); } }
FilteredGuacamoleWriter implements GuacamoleWriter { @Override public void write(char[] chunk, int offset, int length) throws GuacamoleException { while (length > 0) { int parsed; while ((parsed = parser.append(chunk, offset, length)) != 0) { offset += parsed; length -= parsed; } if (!parser.hasNext()) throw new GuacamoleServerException("Filtered write() contained an incomplete instruction."); writeInstruction(parser.next()); } } }
FilteredGuacamoleWriter implements GuacamoleWriter { @Override public void write(char[] chunk, int offset, int length) throws GuacamoleException { while (length > 0) { int parsed; while ((parsed = parser.append(chunk, offset, length)) != 0) { offset += parsed; length -= parsed; } if (!parser.hasNext()) throw new GuacamoleServerException("Filtered write() contained an incomplete instruction."); writeInstruction(parser.next()); } } FilteredGuacamoleWriter(GuacamoleWriter writer, GuacamoleFilter filter); }
FilteredGuacamoleWriter implements GuacamoleWriter { @Override public void write(char[] chunk, int offset, int length) throws GuacamoleException { while (length > 0) { int parsed; while ((parsed = parser.append(chunk, offset, length)) != 0) { offset += parsed; length -= parsed; } if (!parser.hasNext()) throw new GuacamoleServerException("Filtered write() contained an incomplete instruction."); writeInstruction(parser.next()); } } FilteredGuacamoleWriter(GuacamoleWriter writer, GuacamoleFilter filter); @Override void write(char[] chunk, int offset, int length); @Override void write(char[] chunk); @Override void writeInstruction(GuacamoleInstruction instruction); }
FilteredGuacamoleWriter implements GuacamoleWriter { @Override public void write(char[] chunk, int offset, int length) throws GuacamoleException { while (length > 0) { int parsed; while ((parsed = parser.append(chunk, offset, length)) != 0) { offset += parsed; length -= parsed; } if (!parser.hasNext()) throw new GuacamoleServerException("Filtered write() contained an incomplete instruction."); writeInstruction(parser.next()); } } FilteredGuacamoleWriter(GuacamoleWriter writer, GuacamoleFilter filter); @Override void write(char[] chunk, int offset, int length); @Override void write(char[] chunk); @Override void writeInstruction(GuacamoleInstruction instruction);  }