Create a core-util module with some common utilities.

This commit is contained in:
Greyson Parrelli
2020-12-04 18:31:58 -05:00
parent 831cd2f297
commit 8e93bf9075
958 changed files with 1879 additions and 2035 deletions

View File

@@ -7,8 +7,8 @@ import com.bumptech.glide.Priority;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.data.DataFetcher;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.giph.model.ChunkedImageUrl;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.net.ChunkedDataFetcher;
import org.thoughtcrime.securesms.net.RequestController;

View File

@@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.glide;
import android.content.Context;
import androidx.annotation.NonNull;
import com.bumptech.glide.Priority;

View File

@@ -1,6 +1,7 @@
package org.thoughtcrime.securesms.glide;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

View File

@@ -7,10 +7,10 @@ import com.bumptech.glide.load.Options;
import com.bumptech.glide.load.ResourceDecoder;
import com.bumptech.glide.load.engine.Resource;
import org.signal.core.util.StreamUtil;
import org.signal.glide.apng.decode.APNGDecoder;
import org.signal.glide.apng.decode.APNGParser;
import org.signal.glide.common.io.StreamReader;
import org.thoughtcrime.securesms.util.Util;
import java.io.IOException;
import java.io.InputStream;
@@ -31,7 +31,7 @@ public class ApngStreamCacheDecoder implements ResourceDecoder<InputStream, APNG
@Override
public @Nullable Resource<APNGDecoder> decode(@NonNull final InputStream source, int width, int height, @NonNull Options options) throws IOException {
byte[] data = Util.readFully(source);
byte[] data = StreamUtil.readFully(source);
if (data == null) {
return null;

View File

@@ -7,10 +7,10 @@ import com.bumptech.glide.load.Options;
import com.bumptech.glide.load.ResourceEncoder;
import com.bumptech.glide.load.engine.Resource;
import org.signal.core.util.StreamUtil;
import org.signal.core.util.logging.Log;
import org.signal.glide.apng.decode.APNGDecoder;
import org.signal.glide.common.loader.Loader;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.util.Util;
import java.io.File;
import java.io.IOException;
@@ -39,7 +39,7 @@ public class EncryptedApngCacheEncoder extends EncryptedCoder implements Resourc
InputStream input = loader.obtain().toInputStream();
OutputStream output = createEncryptedOutputStream(secret, file);
Util.copy(input, output);
StreamUtil.copy(input, output);
return true;
} catch (IOException e) {
Log.w(TAG, e);

View File

@@ -2,8 +2,8 @@ package org.thoughtcrime.securesms.glide.cache;
import android.graphics.Bitmap;
import androidx.annotation.NonNull;
import org.thoughtcrime.securesms.logging.Log;
import com.bumptech.glide.load.EncodeStrategy;
import com.bumptech.glide.load.Options;
@@ -11,6 +11,8 @@ import com.bumptech.glide.load.ResourceEncoder;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.resource.bitmap.BitmapEncoder;
import org.signal.core.util.logging.Log;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;

View File

@@ -7,7 +7,7 @@ import com.bumptech.glide.load.Options;
import com.bumptech.glide.load.ResourceDecoder;
import com.bumptech.glide.load.engine.Resource;
import org.thoughtcrime.securesms.logging.Log;
import org.signal.core.util.logging.Log;
import java.io.File;
import java.io.IOException;

View File

@@ -7,7 +7,7 @@ import com.bumptech.glide.load.Encoder;
import com.bumptech.glide.load.Options;
import com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool;
import org.thoughtcrime.securesms.logging.Log;
import org.signal.core.util.logging.Log;
import java.io.File;
import java.io.IOException;

View File

@@ -3,13 +3,13 @@ package org.thoughtcrime.securesms.glide.cache;
import androidx.annotation.NonNull;
import org.signal.core.util.StreamUtil;
import org.thoughtcrime.securesms.util.Util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
@@ -68,8 +68,8 @@ class EncryptedCoder {
byte[] theirRandom = new byte[32];
byte[] theirEncryptedMagic = new byte[MAGIC_BYTES.length];
Util.readFully(fileInputStream, theirMagic);
Util.readFully(fileInputStream, theirRandom);
StreamUtil.readFully(fileInputStream, theirMagic);
StreamUtil.readFully(fileInputStream, theirRandom);
if (!MessageDigest.isEqual(theirMagic, MAGIC_BYTES)) {
throw new IOException("Not an encrypted cache file!");
@@ -82,7 +82,7 @@ class EncryptedCoder {
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key, "AES"), new IvParameterSpec(iv));
CipherInputStream inputStream = new CipherInputStream(fileInputStream, cipher);
Util.readFully(inputStream, theirEncryptedMagic);
StreamUtil.readFully(inputStream, theirEncryptedMagic);
if (!MessageDigest.isEqual(theirEncryptedMagic, MAGIC_BYTES)) {
throw new IOException("Key change on encrypted cache file!");

View File

@@ -2,7 +2,6 @@ package org.thoughtcrime.securesms.glide.cache;
import androidx.annotation.NonNull;
import org.thoughtcrime.securesms.logging.Log;
import com.bumptech.glide.load.EncodeStrategy;
import com.bumptech.glide.load.Options;
@@ -11,6 +10,8 @@ import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.resource.gif.GifDrawable;
import com.bumptech.glide.util.ByteBufferUtil;
import org.signal.core.util.logging.Log;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;