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

The following examples show how to use com.google.android.exoplayer2.util.AtomicFile. These examples are extracted from open source projects. 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
/**
 * 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 Project: K-Sonic   Source File: CachedContentIndex.java    License: 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
/**
 * 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 Project: MediaSDK   Source File: ActionFile.java    License: 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 Project: TelePlus-Android   Source File: ActionFile.java    License: 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 Project: TelePlus-Android   Source File: ActionFile.java    License: 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 Project: Telegram-FOSS   Source File: ActionFile.java    License: 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 Project: Telegram   Source File: ActionFile.java    License: 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);
}