That fuck shit the fascists are using
at master 54 lines 1.5 kB view raw
1package org.tm.archive.video; 2 3import android.media.MediaDataSource; 4 5import androidx.annotation.NonNull; 6import androidx.annotation.RequiresApi; 7 8import org.tm.archive.crypto.AttachmentSecret; 9import org.tm.archive.crypto.ClassicDecryptingPartInputStream; 10import org.tm.archive.util.Util; 11 12import java.io.File; 13import java.io.IOException; 14import java.io.InputStream; 15 16@RequiresApi(23) 17final class ClassicEncryptedMediaDataSource extends MediaDataSource { 18 19 private final AttachmentSecret attachmentSecret; 20 private final File mediaFile; 21 private final long length; 22 23 ClassicEncryptedMediaDataSource(@NonNull AttachmentSecret attachmentSecret, @NonNull File mediaFile, long length) { 24 this.attachmentSecret = attachmentSecret; 25 this.mediaFile = mediaFile; 26 this.length = length; 27 } 28 29 @Override 30 public int readAt(long position, byte[] bytes, int offset, int length) throws IOException { 31 try (InputStream inputStream = ClassicDecryptingPartInputStream.createFor(attachmentSecret, mediaFile)) { 32 byte[] buffer = new byte[4096]; 33 long headerRemaining = position; 34 35 while (headerRemaining > 0) { 36 int read = inputStream.read(buffer, 0, Util.toIntExact(Math.min((long)buffer.length, headerRemaining))); 37 38 if (read == -1) return -1; 39 40 headerRemaining -= read; 41 } 42 43 return inputStream.read(bytes, offset, length); 44 } 45 } 46 47 @Override 48 public long getSize() { 49 return length; 50 } 51 52 @Override 53 public void close() {} 54}