XmppInputOutputFilter.java

  1. /**
  2.  *
  3.  * Copyright 2018-2020 Florian Schmaus
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smack;

  18. import java.io.IOException;
  19. import java.nio.ByteBuffer;
  20. import java.security.cert.CertificateException;

  21. import org.jivesoftware.smack.SmackException.NoResponseException;

  22. public interface XmppInputOutputFilter {

  23.     /**
  24.      * The {@code outputData} argument may be a direct {@link ByteBuffer}. The filter has consume the data of the buffer
  25.      * completely.
  26.      *
  27.      * This method must return a {@link OutputResult}. Use {@link OutputResult#NO_OUTPUT} if there is no output.
  28.      *
  29.      * @param outputData the data this method needs to process.
  30.      * @param isFinalDataOfElement if this is the final data of the element.
  31.      * @param destinationAddressChanged if the destination address has changed.
  32.      * @param moreDataAvailable if more data is available.
  33.      * @return a output result.
  34.      * @throws IOException in case an I/O exception occurs.
  35.      */
  36.     OutputResult output(ByteBuffer outputData, boolean isFinalDataOfElement, boolean destinationAddressChanged,
  37.                     boolean moreDataAvailable) throws IOException;

  38.     class OutputResult {
  39.         public static final OutputResult NO_OUTPUT = new OutputResult(false, null);

  40.         public final boolean pendingFilterData;
  41.         public final ByteBuffer filteredOutputData;

  42.         public OutputResult(ByteBuffer filteredOutputData) {
  43.             this(false, filteredOutputData);
  44.         }

  45.         public OutputResult(boolean pendingFilterData, ByteBuffer filteredOutputData) {
  46.             this.pendingFilterData = pendingFilterData;
  47.             this.filteredOutputData = filteredOutputData;
  48.         }
  49.     }

  50.     /**
  51.      * The returned {@link ByteBuffer} is going to get flipped by the caller. The callee must not flip the buffer.
  52.      * @param inputData the data this method needs to process.
  53.      * @return a {@link ByteBuffer} or {@code null} if no data could be produced.
  54.      * @throws IOException in case an I/O exception occurs.
  55.      */
  56.     ByteBuffer input(ByteBuffer inputData) throws IOException;

  57.     default void closeInputOutput() {
  58.     }

  59.     default void waitUntilInputOutputClosed() throws IOException, NoResponseException, CertificateException,
  60.                     InterruptedException, SmackException, XMPPException {
  61.     }

  62.     Object getStats();

  63.     String getFilterName();
  64. }