com.google.android.exoplayer2.util.AtomicFile Java Examples

The following examples show how to use com.google.android.exoplayer2.util.AtomicFile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CachedContentIndex.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a CachedContentIndex which works on the index file in the given cacheDir.
 *
 * @param cacheDir Directory where the index file is kept.
 * @param secretKey 16 byte AES key for reading, and optionally writing, the cache index.
 * @param encrypt Whether the index will be encrypted when written. Must be false if {@code
 *     secretKey} is null.
 */
public CachedContentIndex(File cacheDir, byte[] secretKey, boolean encrypt) {
  this.encrypt = encrypt;
  if (secretKey != null) {
    Assertions.checkArgument(secretKey.length == 16);
    try {
      cipher = getCipher();
      secretKeySpec = new SecretKeySpec(secretKey, "AES");
    } catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
      throw new IllegalStateException(e); // Should never happen.
    }
  } else {
    Assertions.checkState(!encrypt);
    cipher = null;
    secretKeySpec = null;
  }
  keyToContent = new HashMap<>();
  idToKey = new SparseArray<>();
  atomicFile = new AtomicFile(new File(cacheDir, FILE_NAME));
}
 
Example #2
Source File: CachedContentIndex.java    From K-Sonic with MIT License 6 votes vote down vote up
/**
 * Creates a CachedContentIndex which works on the index file in the given cacheDir.
 *
 * @param cacheDir Directory where the index file is kept.
 * @param secretKey If not null, cache keys will be stored encrypted on filesystem using AES/CBC.
 *     The key must be 16 bytes long.
 */
public CachedContentIndex(File cacheDir, byte[] secretKey) {
  if (secretKey != null) {
    Assertions.checkArgument(secretKey.length == 16);
    try {
      cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
      secretKeySpec = new SecretKeySpec(secretKey, "AES");
    } catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
      throw new IllegalStateException(e); // Should never happen.
    }
  } else {
    cipher = null;
    secretKeySpec = null;
  }
  keyToContent = new HashMap<>();
  idToKey = new SparseArray<>();
  atomicFile = new AtomicFile(new File(cacheDir, FILE_NAME));
}
 
Example #3
Source File: CachedContentIndex.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a CachedContentIndex which works on the index file in the given cacheDir.
 *
 * @param cacheDir Directory where the index file is kept.
 * @param secretKey 16 byte AES key for reading, and optionally writing, the cache index.
 * @param encrypt Whether the index will be encrypted when written. Must be false if {@code
 *     secretKey} is null.
 */
public CachedContentIndex(File cacheDir, byte[] secretKey, boolean encrypt) {
  this.encrypt = encrypt;
  if (secretKey != null) {
    Assertions.checkArgument(secretKey.length == 16);
    try {
      cipher = getCipher();
      secretKeySpec = new SecretKeySpec(secretKey, "AES");
    } catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
      throw new IllegalStateException(e); // Should never happen.
    }
  } else {
    Assertions.checkState(!encrypt);
    cipher = null;
    secretKeySpec = null;
  }
  keyToContent = new HashMap<>();
  idToKey = new SparseArray<>();
  atomicFile = new AtomicFile(new File(cacheDir, FILE_NAME));
}
 
Example #4
Source File: ActionFile.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
/**
 * @param actionFile The file from which {@link DownloadRequest DownloadRequests} will be loaded.
 */
public ActionFile(File actionFile) {
  atomicFile = new AtomicFile(actionFile);
}
 
Example #5
Source File: ActionFile.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @param actionFile File to be used to store and load {@link DownloadAction}s.
 */
public ActionFile(File actionFile) {
  this.actionFile = actionFile;
  atomicFile = new AtomicFile(actionFile);
}
 
Example #6
Source File: ActionFile.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @param actionFile File to be used to store and load {@link DownloadAction}s.
 */
public ActionFile(File actionFile) {
  this.actionFile = actionFile;
  atomicFile = new AtomicFile(actionFile);
}
 
Example #7
Source File: ActionFile.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @param actionFile The file from which {@link DownloadRequest DownloadRequests} will be loaded.
 */
public ActionFile(File actionFile) {
  atomicFile = new AtomicFile(actionFile);
}
 
Example #8
Source File: ActionFile.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @param actionFile The file from which {@link DownloadRequest DownloadRequests} will be loaded.
 */
public ActionFile(File actionFile) {
  atomicFile = new AtomicFile(actionFile);
}