2013-02-26 10:26:41 +01:00
|
|
|
/**
|
2014-02-17 18:57:38 +01:00
|
|
|
*
|
2020-05-21 12:47:55 +02:00
|
|
|
* Copyright 2013-2020 Florian Schmaus
|
2013-02-26 10:26:41 +01:00
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2013-02-26 10:26:41 +01:00
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
package org.jivesoftware.smack.compression;
|
|
|
|
|
2015-01-25 00:21:19 +01:00
|
|
|
import java.io.IOException;
|
2013-02-26 10:26:41 +01:00
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
2020-05-21 12:47:55 +02:00
|
|
|
import org.jivesoftware.smack.util.Objects;
|
|
|
|
|
2013-02-26 10:26:41 +01:00
|
|
|
public abstract class XMPPInputOutputStream {
|
2014-08-07 14:42:30 +02:00
|
|
|
|
2020-05-21 12:47:55 +02:00
|
|
|
protected static FlushMethod flushMethod = FlushMethod.SYNC_FLUSH;
|
2014-08-07 14:42:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the used flushed method when compressing data. The default is full flush which may not
|
|
|
|
* achieve the best compression ratio, but provides better security against certain attacks.
|
|
|
|
* Only use sync flush if you fully understand the implications.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2014-08-07 14:42:30 +02:00
|
|
|
* @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>
|
2019-08-30 12:08:30 +02:00
|
|
|
* @param flushMethod TODO javadoc me please
|
2014-08-07 14:42:30 +02:00
|
|
|
*/
|
|
|
|
public static void setFlushMethod(FlushMethod flushMethod) {
|
2020-05-21 12:47:55 +02:00
|
|
|
XMPPInputOutputStream.flushMethod = Objects.requireNonNull(flushMethod);
|
2014-08-07 14:42:30 +02:00
|
|
|
}
|
|
|
|
|
2019-02-04 08:59:39 +01:00
|
|
|
public static FlushMethod getFlushMethod() {
|
|
|
|
return flushMethod;
|
|
|
|
}
|
|
|
|
|
2014-12-19 11:15:01 +01:00
|
|
|
protected final String compressionMethod;
|
|
|
|
|
|
|
|
protected XMPPInputOutputStream(String compressionMethod) {
|
|
|
|
this.compressionMethod = compressionMethod;
|
|
|
|
}
|
2013-02-26 10:26:41 +01:00
|
|
|
|
|
|
|
public String getCompressionMethod() {
|
|
|
|
return compressionMethod;
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract boolean isSupported();
|
|
|
|
|
2015-01-25 00:21:19 +01:00
|
|
|
public abstract InputStream getInputStream(InputStream inputStream) throws IOException;
|
2013-02-26 10:26:41 +01:00
|
|
|
|
2015-01-25 00:21:19 +01:00
|
|
|
public abstract OutputStream getOutputStream(OutputStream outputStream) throws IOException;
|
2014-08-07 14:42:30 +02:00
|
|
|
|
|
|
|
public enum FlushMethod {
|
|
|
|
FULL_FLUSH,
|
|
|
|
SYNC_FLUSH,
|
|
|
|
}
|
2013-02-26 10:26:41 +01:00
|
|
|
}
|