Tabnine Logo
DiskLruCache$Value
Code IndexAdd Tabnine to your IDE (free)

How to use
DiskLruCache$Value
in
com.bumptech.glide.disklrucache

Best Java code snippets using com.bumptech.glide.disklrucache.DiskLruCache$Value (Showing top 20 results out of 315)

origin: bumptech/glide

@Override
public File get(Key key) {
 String safeKey = safeKeyGenerator.getSafeKey(key);
 if (Log.isLoggable(TAG, Log.VERBOSE)) {
  Log.v(TAG, "Get: Obtained: " + safeKey + " for for Key: " + key);
 }
 File result = null;
 try {
  // It is possible that the there will be a put in between these two gets. If so that shouldn't
  // be a problem because we will always put the same value at the same key so our input streams
  // will still represent the same data.
  final DiskLruCache.Value value = getDiskCache().get(safeKey);
  if (value != null) {
   result = value.getFile(0);
  }
 } catch (IOException e) {
  if (Log.isLoggable(TAG, Log.WARN)) {
   Log.w(TAG, "Unable to get from disk cache", e);
  }
 }
 return result;
}
origin: guolindev/giffun

/**
 * Returns a snapshot of the entry named {@code key}, or null if it doesn't
 * exist is not currently readable. If a value is returned, it is moved to
 * the head of the LRU queue.
 */
public synchronized Value get(String key) throws IOException {
 checkNotClosed();
 Entry entry = lruEntries.get(key);
 if (entry == null) {
  return null;
 }
 if (!entry.readable) {
  return null;
 }
 for (File file : entry.cleanFiles) {
   // A file must have been deleted manually!
   if (!file.exists()) {
     return null;
   }
 }
 redundantOpCount++;
 journalWriter.append(READ);
 journalWriter.append(' ');
 journalWriter.append(key);
 journalWriter.append('\n');
 if (journalRebuildRequired()) {
  executorService.submit(cleanupCallable);
 }
 return new Value(key, entry.sequenceNumber, entry.cleanFiles, entry.lengths);
}
origin: amahi/android

  metadata.setAudioTitle(value.getString(TITLE_INDEX));
  metadata.setAudioAlbum(value.getString(ALBUM_INDEX));
  metadata.setAudioArtist(value.getString(ARTIST_INDEX));
  metadata.setDuration(value.getString(DURATION_INDEX));
} catch (IOException e) {
  e.printStackTrace();
origin: com.github.bumptech.glide/disklrucache

/**
 * Returns a snapshot of the entry named {@code key}, or null if it doesn't
 * exist is not currently readable. If a value is returned, it is moved to
 * the head of the LRU queue.
 */
public synchronized Value get(String key) throws IOException {
 checkNotClosed();
 Entry entry = lruEntries.get(key);
 if (entry == null) {
  return null;
 }
 if (!entry.readable) {
  return null;
 }
 for (File file : entry.cleanFiles) {
   // A file must have been deleted manually!
   if (!file.exists()) {
     return null;
   }
 }
 redundantOpCount++;
 journalWriter.append(READ);
 journalWriter.append(' ');
 journalWriter.append(key);
 journalWriter.append('\n');
 if (journalRebuildRequired()) {
  executorService.submit(cleanupCallable);
 }
 return new Value(key, entry.sequenceNumber, entry.cleanFiles, entry.lengths);
}
origin: mozilla-tw/FirefoxLite

/**
 * Returns a snapshot of the entry named {@code key}, or null if it doesn't
 * exist is not currently readable. If a value is returned, it is moved to
 * the head of the LRU queue.
 */
public synchronized Value get(String key) throws IOException {
 checkNotClosed();
 Entry entry = lruEntries.get(key);
 if (entry == null) {
  return null;
 }
 if (!entry.readable) {
  return null;
 }
 for (File file : entry.cleanFiles) {
   // A file must have been deleted manually!
   if (!file.exists()) {
     return null;
   }
 }
 redundantOpCount++;
 journalWriter.append(READ);
 journalWriter.append(' ');
 journalWriter.append(key);
 journalWriter.append('\n');
 if (journalRebuildRequired()) {
  executorService.submit(cleanupCallable);
 }
 return new Value(key, entry.sequenceNumber, entry.cleanFiles, entry.lengths);
}
origin: mozilla-tw/FirefoxLite

@Test public void journalFileIsPreferredOverBackupFile() throws Exception {
 DiskLruCache.Editor creator = cache.edit("k1");
 creator.set(0, "ABC");
 creator.set(1, "DE");
 creator.commit();
 cache.flush();
 FileUtils.copyFile(journalFile, journalBkpFile);
 creator = cache.edit("k2");
 creator.set(0, "F");
 creator.set(1, "GH");
 creator.commit();
 cache.close();
 assertThat(journalFile.exists()).isTrue();
 assertThat(journalBkpFile.exists()).isTrue();
 cache = DiskLruCache.open(cacheDir, appVersion, 2, Integer.MAX_VALUE);
 DiskLruCache.Value valueA = cache.get("k1");
 assertThat(valueA.getString(0)).isEqualTo("ABC");
 assertThat(valueA.getLength(0)).isEqualTo(3);
 assertThat(valueA.getString(1)).isEqualTo("DE");
 assertThat(valueA.getLength(1)).isEqualTo(2);
 DiskLruCache.Value valueB = cache.get("k2");
 assertThat(valueB.getString(0)).isEqualTo("F");
 assertThat(valueB.getLength(0)).isEqualTo(1);
 assertThat(valueB.getString(1)).isEqualTo("GH");
 assertThat(valueB.getLength(1)).isEqualTo(2);
 assertThat(journalBkpFile.exists()).isFalse();
 assertThat(journalFile.exists()).isTrue();
}
origin: amahi/android

private Bitmap getBitmap(DiskLruCache.Value value) {
  Bitmap bitmap = null;
  final File file = value.getFile(BITMAP_INDEX);
  if (file != null) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    FileInputStream fileInputStream = null;
    try {
      fileInputStream = new FileInputStream(file);
      bitmap = BitmapFactory.decodeStream(fileInputStream, null, options);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } finally {
      if (fileInputStream != null) {
        try {
          fileInputStream.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
  }
  return bitmap;
}
origin: mozilla-tw/Rocket

@Override
public File get(Key key) {
 String safeKey = safeKeyGenerator.getSafeKey(key);
 if (Log.isLoggable(TAG, Log.VERBOSE)) {
  Log.v(TAG, "Get: Obtained: " + safeKey + " for for Key: " + key);
 }
 File result = null;
 try {
  // It is possible that the there will be a put in between these two gets. If so that shouldn't
  // be a problem because we will always put the same value at the same key so our input streams
  // will still represent the same data.
  final DiskLruCache.Value value = getDiskCache().get(safeKey);
  if (value != null) {
   result = value.getFile(0);
  }
 } catch (IOException e) {
  if (Log.isLoggable(TAG, Log.WARN)) {
   Log.w(TAG, "Unable to get from disk cache", e);
  }
 }
 return result;
}
origin: REBOOTERS/AndroidAnimationExercise

/**
 * 获取是否有某张原图的缓存
 * 缓存模式必须是:DiskCacheStrategy.SOURCE 才能获取到缓存文件
 */
public static File getGlideCacheFile(Context context, String url) {
  try {
    OriginalKey originalKey = new OriginalKey(url, EmptySignature.obtain());
    SafeKeyGenerator safeKeyGenerator = new SafeKeyGenerator();
    String safeKey = safeKeyGenerator.getSafeKey(originalKey);
    File file = new File(context.getCacheDir(), DiskCache.Factory.DEFAULT_DISK_CACHE_DIR);
    DiskLruCache diskLruCache = DiskLruCache.open(file, 1, 1, DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE);
    DiskLruCache.Value value = diskLruCache.get(safeKey);
    if (value != null) {
      return value.getFile(0);
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
  return null;
}
origin: mozilla-tw/FirefoxLite

@Test public void restoreBackupFile() throws Exception {
 DiskLruCache.Editor creator = cache.edit("k1");
 creator.set(0, "ABC");
 creator.set(1, "DE");
 creator.commit();
 cache.close();
 assertThat(journalFile.renameTo(journalBkpFile)).isTrue();
 assertThat(journalFile.exists()).isFalse();
 cache = DiskLruCache.open(cacheDir, appVersion, 2, Integer.MAX_VALUE);
 DiskLruCache.Value value = cache.get("k1");
 assertThat(value.getString(0)).isEqualTo("ABC");
 assertThat(value.getLength(0)).isEqualTo(3);
 assertThat(value.getString(1)).isEqualTo("DE");
 assertThat(value.getLength(1)).isEqualTo(2);
 assertThat(journalBkpFile.exists()).isFalse();
 assertThat(journalFile.exists()).isTrue();
}
origin: mozilla-tw/FirefoxLite

@Test public void updateExistingEntryWithTooFewValuesReusesPreviousValues() throws Exception {
 DiskLruCache.Editor creator = cache.edit("k1");
 creator.set(0, "A");
 creator.set(1, "B");
 creator.commit();
 DiskLruCache.Editor updater = cache.edit("k1");
 updater.set(0, "C");
 updater.commit();
 DiskLruCache.Value value = cache.get("k1");
 assertThat(value.getString(0)).isEqualTo("C");
 assertThat(value.getLength(0)).isEqualTo(1);
 assertThat(value.getString(1)).isEqualTo("B");
 assertThat(value.getLength(1)).isEqualTo(1);
}
origin: mozilla-tw/FirefoxLite

@Test public void readAndWriteEntryWithoutProperClose() throws Exception {
 DiskLruCache.Editor creator = cache.edit("k1");
 creator.set(0, "A");
 creator.set(1, "B");
 creator.commit();
 // Simulate a dirty close of 'cache' by opening the cache directory again.
 DiskLruCache cache2 = DiskLruCache.open(cacheDir, appVersion, 2, Integer.MAX_VALUE);
 DiskLruCache.Value value = cache2.get("k1");
 assertThat(value.getString(0)).isEqualTo("A");
 assertThat(value.getLength(0)).isEqualTo(1);
 assertThat(value.getString(1)).isEqualTo("B");
 assertThat(value.getLength(1)).isEqualTo(1);
 cache2.close();
}
origin: mozilla-tw/FirefoxLite

@Test public void readAndWriteEntryAcrossCacheOpenAndClose() throws Exception {
 DiskLruCache.Editor creator = cache.edit("k1");
 creator.set(0, "A");
 creator.set(1, "B");
 creator.commit();
 cache.close();
 cache = DiskLruCache.open(cacheDir, appVersion, 2, Integer.MAX_VALUE);
 DiskLruCache.Value value = cache.get("k1");
 assertThat(value.getString(0)).isEqualTo("A");
 assertThat(value.getLength(0)).isEqualTo(1);
 assertThat(value.getString(1)).isEqualTo("B");
 assertThat(value.getLength(1)).isEqualTo(1);
}
origin: mozilla-tw/FirefoxLite

@Test public void writeAndReadEntry() throws Exception {
 DiskLruCache.Editor creator = cache.edit("k1");
 creator.set(0, "ABC");
 creator.set(1, "DE");
 assertThat(creator.getString(0)).isNull();
 assertThat(creator.getString(1)).isNull();
 creator.commit();
 DiskLruCache.Value value = cache.get("k1");
 assertThat(value.getString(0)).isEqualTo("ABC");
 assertThat(value.getLength(0)).isEqualTo(3);
 assertThat(value.getString(1)).isEqualTo("DE");
 assertThat(value.getLength(1)).isEqualTo(2);
}
origin: mozilla-tw/FirefoxLite

/** @see <a href="https://github.com/JakeWharton/DiskLruCache/issues/2">Issue #2</a> */
@Test public void aggressiveClearingHandlesPartialEdit() throws Exception {
 set("a", "a", "a");
 set("b", "b", "b");
 DiskLruCache.Editor a = cache.get("a").edit();
 a.set(0, "a1");
 FileUtils.deleteDirectory(cacheDir);
 a.set(1, "a2");
 a.commit();
 assertThat(cache.get("a")).isNull();
}
origin: mozilla-tw/FirefoxLite

@Test public void editSinceEvictedAndRecreated() throws Exception {
 cache.close();
 cache = DiskLruCache.open(cacheDir, appVersion, 2, 10);
 set("a", "aa", "aaa"); // size 5
 DiskLruCache.Value value = cache.get("a");
 set("b", "bb", "bbb"); // size 5
 set("c", "cc", "ccc"); // size 5; will evict 'A'
 set("a", "a", "aaaa"); // size 5; will evict 'B'
 cache.flush();
 assertThat(value.edit()).isNull();
}
origin: mozilla-tw/FirefoxLite

@Test public void editSameVersion() throws Exception {
 set("a", "a", "a");
 DiskLruCache.Value value = cache.get("a");
 DiskLruCache.Editor editor = value.edit();
 editor.set(1, "a2");
 editor.commit();
 assertValue("a", "a", "a2");
}
origin: mozilla-tw/FirefoxLite

@Test public void readingTheSameFileMultipleTimes() throws Exception {
 set("a", "a", "b");
 DiskLruCache.Value value = cache.get("a");
 assertThat(value.getFile(0)).isSameAs(value.getFile(0));
}
origin: mozilla-tw/FirefoxLite

@Test public void editSinceEvicted() throws Exception {
 cache.close();
 cache = DiskLruCache.open(cacheDir, appVersion, 2, 10);
 set("a", "aa", "aaa"); // size 5
 DiskLruCache.Value value = cache.get("a");
 set("b", "bb", "bbb"); // size 5
 set("c", "cc", "ccc"); // size 5; will evict 'A'
 cache.flush();
 assertThat(value.edit()).isNull();
}
origin: mozilla-tw/FirefoxLite

/** @see <a href="https://github.com/JakeWharton/DiskLruCache/issues/2">Issue #2</a> */
@Test public void aggressiveClearingHandlesEdit() throws Exception {
 set("a", "a", "a");
 DiskLruCache.Editor a = cache.get("a").edit();
 FileUtils.deleteDirectory(cacheDir);
 a.set(1, "a2");
 a.commit();
}
com.bumptech.glide.disklrucacheDiskLruCache$Value

Javadoc

A snapshot of the values for an entry.

Most used methods

  • getFile
  • <init>
  • getString
    Returns the string value for index.
  • edit
    Returns an editor for this snapshot's entry, or null if either the entry has changed since this snap
  • getLength
    Returns the byte length of the value for index.

Popular in Java

  • Making http post requests using okhttp
  • getContentResolver (Context)
  • putExtra (Intent)
  • startActivity (Activity)
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • URL (java.net)
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now