XMPPInputOutputStream.java

  1. /**
  2.  *
  3.  * Copyright 2013 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.compression;

  18. import java.io.IOException;
  19. import java.io.InputStream;
  20. import java.io.OutputStream;

  21. public abstract class XMPPInputOutputStream {

  22.     protected static FlushMethod flushMethod;

  23.     /**
  24.      * Set the used flushed method when compressing data. The default is full flush which may not
  25.      * achieve the best compression ratio, but provides better security against certain attacks.
  26.      * Only use sync flush if you fully understand the implications.
  27.      *
  28.      * @see <a href="https://blog.thijsalkema.de/blog/2014/08/07/https-attacks-and-xmpp-2-crime-and-breach/">Attacks against XMPP when using compression</a>
  29.      * @param flushMethod
  30.      */
  31.     public static void setFlushMethod(FlushMethod flushMethod) {
  32.         XMPPInputOutputStream.flushMethod = flushMethod;
  33.     }

  34.     protected final String compressionMethod;

  35.     protected XMPPInputOutputStream(String compressionMethod) {
  36.         this.compressionMethod = compressionMethod;
  37.     }

  38.     public String getCompressionMethod() {
  39.         return compressionMethod;
  40.     }

  41.     public abstract boolean isSupported();

  42.     public abstract InputStream getInputStream(InputStream inputStream) throws IOException;

  43.     public abstract OutputStream getOutputStream(OutputStream outputStream) throws IOException;

  44.     public enum FlushMethod {
  45.         FULL_FLUSH,
  46.         SYNC_FLUSH,
  47.     }
  48. }