001/** 002 * 003 * Copyright 2018 Florian Schmaus 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smack; 018 019import java.io.IOException; 020import java.nio.ByteBuffer; 021 022public interface XmppInputOutputFilter { 023 024 /** 025 * The {@code outputData} argument may be a direct {@link ByteBuffer}. The filter has consume the data of the buffer 026 * completely. 027 * 028 * This method must return a {@link OutputResult}. Use {@link OutputResult#NO_OUTPUT} if there is no output. 029 * 030 * @param outputData the data this method needs to process. 031 * @param isFinalDataOfElement if this is the final data of the element. 032 * @param destinationAddressChanged if the destination address has changed. 033 * @param moreDataAvailable if more data is available. 034 * @return a output result. 035 * @throws IOException in case an I/O exception occurs. 036 */ 037 OutputResult output(ByteBuffer outputData, boolean isFinalDataOfElement, boolean destinationAddressChanged, 038 boolean moreDataAvailable) throws IOException; 039 040 /** 041 * The returned {@link ByteBuffer} is going to get fliped by the caller. The callee must not flip the buffer. 042 * @param inputData the data this methods needs to process. 043 * @return a {@link ByteBuffer} or {@code null} if no data could be produced. 044 * @throws IOException in case an I/O exception occurs. 045 */ 046 ByteBuffer input(ByteBuffer inputData) throws IOException; 047 048 class OutputResult { 049 public static final OutputResult NO_OUTPUT = new OutputResult(false, null); 050 051 public final boolean pendingFilterData; 052 public final ByteBuffer filteredOutputData; 053 054 public OutputResult(ByteBuffer filteredOutputData) { 055 this(false, filteredOutputData); 056 } 057 058 public OutputResult(boolean pendingFilterData, ByteBuffer filteredOutputData) { 059 this.pendingFilterData = pendingFilterData; 060 this.filteredOutputData = filteredOutputData; 061 } 062 } 063}