@Override
    public void write(char[] chunk, int offset, int length) throws GuacamoleException {

        // Write all data in chunk
        while (length > 0) {

            // Pass as much data through the parser as possible
            int parsed;
            while ((parsed = parser.append(chunk, offset, length)) != 0) {
                offset += parsed;
                length -= parsed;
            }

            // If no instruction is available, it must be incomplete
            if (!parser.hasNext())
                throw new GuacamoleServerException("Filtered write() contained an incomplete instruction.");

            // Write single instruction through filter
            writeInstruction(parser.next());

        }
        
    }
Wraps the given GuacamoleWriter, applying the given filter to all written 
instructions. Future writes will only write instructions which pass
the filter.

@param writer The GuacamoleWriter to wrap.
@param filter The filter which dictates which instructions are written,
              and how.
guacamole-common/src/main/java/org/apache/guacamole/protocol/FilteredGuacamoleWriter.java