@@ -0,0 +1,3445 @@
+/*%0A * Copyright (C) 2014 Glyptodon LLC%0A *%0A * Permission is hereby granted, free of charge, to any person obtaining a copy%0A * of this software and associated documentation files (the %22Software%22), to deal%0A * in the Software without restriction, including without limitation the rights%0A * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell%0A * copies of the Software, and to permit persons to whom the Software is%0A * furnished to do so, subject to the following conditions:%0A *%0A * The above copyright notice and this permission notice shall be included in%0A * all copies or substantial portions of the Software.%0A *%0A * THE SOFTWARE IS PROVIDED %22AS IS%22, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR%0A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,%0A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE%0A * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER%0A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,%0A * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN%0A * THE SOFTWARE.%0A */%0A%0Apackage org.glyptodon.guacamole.protocol;%0A%0Aimport org.glyptodon.guacamole.GuacamoleException;%0Aimport org.glyptodon.guacamole.io.GuacamoleReader;%0Aimport org.glyptodon.guacamole.io.GuacamoleWriter;%0Aimport org.glyptodon.guacamole.net.GuacamoleSocket;%0A%0A/**%0A * Implementation of GuacamoleSocket which allows individual instructions to be%0A * intercepted, overridden, etc.%0A *%0A * @author Michael Jumper%0A */%0Apublic class FilteredGuacamoleSocket implements GuacamoleSocket %7B%0A%0A    /**%0A     * Wrapped GuacamoleSocket.%0A     */%0A    private final GuacamoleSocket socket;%0A%0A    /**%0A     * A reader for the wrapped GuacamoleSocket which may be filtered.%0A     */%0A    private final GuacamoleReader reader;%0A    %0A    /**%0A     * A writer for the wrapped GuacamoleSocket which may be filtered.%0A     */%0A    private final GuacamoleWriter writer;%0A    %0A    /**%0A     * Creates a new FilteredGuacamoleSocket which uses the given filters to%0A     * determine whether instructions read/written are allowed through,%0A     * modified, etc. If reads or writes should be unfiltered, simply specify%0A     * null rather than a particular filter.%0A     *%0A     * @param socket The GuacamoleSocket to wrap.%0A     * @param readFilter The GuacamoleFilter to apply to all read instructions,%0A     *                   if any.%0A     * @param writeFilter The GuacamoleFilter to apply to all written %0A     *                    instructions, if any.%0A     */%0A    public FilteredGuacamoleSocket(GuacamoleSocket socket, GuacamoleFilter readFilter, GuacamoleFilter writeFilter) %7B%0A        this.socket = socket;%0A%0A        // Apply filter to reader%0A        if (readFilter != null)%0A            reader = new FilteredGuacamoleReader(socket.getReader(), readFilter);%0A        else%0A            reader = socket.getReader();%0A%0A        // Apply filter to writer%0A        if (writeFilter != null)%0A            writer = new FilteredGuacamoleWriter(socket.getWriter(), writeFilter);%0A        else%0A            writer = socket.getWriter();%0A%0A    %7D%0A    %0A    @Override%0A    public GuacamoleReader getReader() %7B%0A        return reader;%0A    %7D%0A%0A    @Override%0A    public GuacamoleWriter getWriter() %7B%0A        return writer;%0A    %7D%0A%0A    @Override%0A    public void close() throws GuacamoleException %7B%0A        socket.close();%0A    %7D%0A%0A    @Override%0A    public boolean isOpen() %7B%0A        return socket.isOpen();%0A    %7D%0A    %0A%7D%0A

Implement FilteredGuacamoleSocket, to make it easy to send all socket I/O through filters.