mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 06:12:05 +01:00
compression: remove Android SDK level < 19 compatiblity
Since we now require Android SDK 19 or higher, we can use the method directly.
This commit is contained in:
parent
390f7823e1
commit
85af4a022d
1 changed files with 15 additions and 39 deletions
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright 2013-2018 Florian Schmaus
|
* Copyright 2013-2020 Florian Schmaus
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -19,8 +19,6 @@ package org.jivesoftware.smack.compression;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.zip.Deflater;
|
import java.util.zip.Deflater;
|
||||||
import java.util.zip.DeflaterOutputStream;
|
import java.util.zip.DeflaterOutputStream;
|
||||||
import java.util.zip.Inflater;
|
import java.util.zip.Inflater;
|
||||||
|
@ -41,31 +39,15 @@ import java.util.zip.InflaterInputStream;
|
||||||
* @author Florian Schmaus
|
* @author Florian Schmaus
|
||||||
*/
|
*/
|
||||||
public class Java7ZlibInputOutputStream extends XMPPInputOutputStream {
|
public class Java7ZlibInputOutputStream extends XMPPInputOutputStream {
|
||||||
private static final Method method;
|
|
||||||
private static final boolean supported;
|
|
||||||
private static final int compressionLevel = Deflater.DEFAULT_COMPRESSION;
|
private static final int compressionLevel = Deflater.DEFAULT_COMPRESSION;
|
||||||
|
|
||||||
private static final int SYNC_FLUSH_INT = 2;
|
|
||||||
private static final int FULL_FLUSH_INT = 3;
|
|
||||||
|
|
||||||
static {
|
|
||||||
Method m = null;
|
|
||||||
try {
|
|
||||||
m = Deflater.class.getMethod("deflate", byte[].class, int.class, int.class, int.class);
|
|
||||||
} catch (SecurityException e) {
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
}
|
|
||||||
method = m;
|
|
||||||
supported = method != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Java7ZlibInputOutputStream() {
|
public Java7ZlibInputOutputStream() {
|
||||||
super("zlib");
|
super("zlib");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSupported() {
|
public boolean isSupported() {
|
||||||
return supported;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -101,29 +83,23 @@ public class Java7ZlibInputOutputStream extends XMPPInputOutputStream {
|
||||||
@Override
|
@Override
|
||||||
public OutputStream getOutputStream(OutputStream outputStream) {
|
public OutputStream getOutputStream(OutputStream outputStream) {
|
||||||
final int flushMethodInt;
|
final int flushMethodInt;
|
||||||
if (flushMethod == FlushMethod.SYNC_FLUSH) {
|
switch (flushMethod) {
|
||||||
flushMethodInt = SYNC_FLUSH_INT;
|
case SYNC_FLUSH:
|
||||||
} else {
|
flushMethodInt = Deflater.SYNC_FLUSH;
|
||||||
flushMethodInt = FULL_FLUSH_INT;
|
break;
|
||||||
|
case FULL_FLUSH:
|
||||||
|
flushMethodInt = Deflater.FULL_FLUSH;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new DeflaterOutputStream(outputStream, new Deflater(compressionLevel)) {
|
return new DeflaterOutputStream(outputStream, new Deflater(compressionLevel)) {
|
||||||
@Override
|
@Override
|
||||||
public void flush() throws IOException {
|
public void flush() throws IOException {
|
||||||
if (!supported) {
|
int count;
|
||||||
super.flush();
|
while ((count = def.deflate(buf, 0, buf.length, flushMethodInt)) > 0) {
|
||||||
return;
|
out.write(buf, 0, count);
|
||||||
}
|
|
||||||
try {
|
|
||||||
int count;
|
|
||||||
while ((count = (Integer) method.invoke(def, buf, 0, buf.length, flushMethodInt)) != 0) {
|
|
||||||
out.write(buf, 0, count);
|
|
||||||
}
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
throw new IOException("Can't flush");
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
throw new IOException("Can't flush");
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
throw new IOException("Can't flush");
|
|
||||||
}
|
}
|
||||||
super.flush();
|
super.flush();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue