Tabnine Logo
com.nostra13.universalimageloader.cache.disc.impl.ext
Code IndexAdd Tabnine to your IDE (free)

How to use com.nostra13.universalimageloader.cache.disc.impl.ext

Best Java code snippets using com.nostra13.universalimageloader.cache.disc.impl.ext (Showing top 20 results out of 315)

origin: nostra13/Android-Universal-Image-Loader

/**
 * Closes the cache and deletes all of its stored values. This will delete
 * all files in the cache directory including files that weren't created by
 * the cache.
 */
public void delete() throws IOException {
  close();
  Util.deleteContents(directory);
}
origin: nostra13/Android-Universal-Image-Loader

/**
 * Returns the last committed value as a string, or null if no value
 * has been committed.
 */
public String getString(int index) throws IOException {
  InputStream in = newInputStream(index);
  return in != null ? inputStreamToString(in) : null;
}
origin: nostra13/Android-Universal-Image-Loader

public void abortUnlessCommitted() {
  if (!committed) {
    try {
      abort();
    } catch (IOException ignored) {
    }
  }
}
origin: nostra13/Android-Universal-Image-Loader

@Override
public void clear() {
  try {
    cache.delete();
  } catch (IOException e) {
    L.e(e);
  }
  try {
    initCache(cache.getDirectory(), reserveCacheDir, cache.getMaxSize(), cache.getMaxFileCount());
  } catch (IOException e) {
    L.e(e);
  }
}
origin: nostra13/Android-Universal-Image-Loader

@Override
public boolean save(String imageUri, InputStream imageStream, IoUtils.CopyListener listener) throws IOException {
  DiskLruCache.Editor editor = cache.edit(getKey(imageUri));
  if (editor == null) {
    return false;
  }
  OutputStream os = new BufferedOutputStream(editor.newOutputStream(0), bufferSize);
  boolean copied = false;
  try {
    copied = IoUtils.copyStream(imageStream, os, listener, bufferSize);
  } finally {
    IoUtils.closeSilently(os);
    if (copied) {
      editor.commit();
    } else {
      editor.abort();
    }
  }
  return copied;
}
origin: nostra13/Android-Universal-Image-Loader

@Override
public File get(String imageUri) {
  DiskLruCache.Snapshot snapshot = null;
  try {
    snapshot = cache.get(getKey(imageUri));
    return snapshot == null ? null : snapshot.getFile(0);
  } catch (IOException e) {
    L.e(e);
    return null;
  } finally {
    if (snapshot != null) {
      snapshot.close();
    }
  }
}
origin: nostra13/Android-Universal-Image-Loader

private synchronized Editor edit(String key, long expectedSequenceNumber) throws IOException {
  checkNotClosed();
  validateKey(key);
  Entry entry = lruEntries.get(key);
  if (expectedSequenceNumber != ANY_SEQUENCE_NUMBER && (entry == null
      || entry.sequenceNumber != expectedSequenceNumber)) {
    return null; // Snapshot is stale.
  }
  if (entry == null) {
    entry = new Entry(key);
    lruEntries.put(key, entry);
  } else if (entry.currentEditor != null) {
    return null; // Another edit is in progress.
  }
  Editor editor = new Editor(entry);
  entry.currentEditor = editor;
  // Flush the journal before creating files to prevent file leaks.
  journalWriter.write(DIRTY + ' ' + key + '\n');
  journalWriter.flush();
  return editor;
}
origin: nostra13/Android-Universal-Image-Loader

/** Force buffered operations to the filesystem. */
public synchronized void flush() throws IOException {
  checkNotClosed();
  trimToSize();
  trimToFileCount();
  journalWriter.flush();
}
origin: nostra13/Android-Universal-Image-Loader

/** Closes this cache. Stored values will remain on the filesystem. */
public synchronized void close() throws IOException {
  if (journalWriter == null) {
    return; // Already closed.
  }
  for (Entry entry : new ArrayList<Entry>(lruEntries.values())) {
    if (entry.currentEditor != null) {
      entry.currentEditor.abort();
    }
  }
  trimToSize();
  trimToFileCount();
  journalWriter.close();
  journalWriter = null;
}
origin: nostra13/Android-Universal-Image-Loader

@Override
public boolean remove(String imageUri) {
  try {
    return cache.remove(getKey(imageUri));
  } catch (IOException e) {
    L.e(e);
    return false;
  }
}
origin: nostra13/Android-Universal-Image-Loader

/** Sets the value at {@code index} to {@code value}. */
public void set(int index, String value) throws IOException {
  Writer writer = null;
  try {
    writer = new OutputStreamWriter(newOutputStream(index), Util.UTF_8);
    writer.write(value);
  } finally {
    Util.closeQuietly(writer);
  }
}
origin: nostra13/Android-Universal-Image-Loader

private void initCache(File cacheDir, File reserveCacheDir, long cacheMaxSize, int cacheMaxFileCount)
    throws IOException {
  try {
    cache = DiskLruCache.open(cacheDir, 1, 1, cacheMaxSize, cacheMaxFileCount);
  } catch (IOException e) {
    L.e(e);
    if (reserveCacheDir != null) {
      initCache(reserveCacheDir, null, cacheMaxSize, cacheMaxFileCount);
    }
    if (cache == null) {
      throw e; //new RuntimeException("Can't initialize disk cache", e);
    }
  }
}
origin: nostra13/Android-Universal-Image-Loader

/**
 * Returns an editor for the entry named {@code key}, or null if another
 * edit is in progress.
 */
public Editor edit(String key) throws IOException {
  return edit(key, ANY_SEQUENCE_NUMBER);
}
origin: nostra13/Android-Universal-Image-Loader

  public void close() {
    for (InputStream in : ins) {
      Util.closeQuietly(in);
    }
  }
}
origin: nostra13/Android-Universal-Image-Loader

@Override
public File getDirectory() {
  return cache.getDirectory();
}
origin: nostra13/Android-Universal-Image-Loader

/**
 * Commits this edit so it is visible to readers.  This releases the
 * edit lock so another edit may be started on the same key.
 */
public void commit() throws IOException {
  if (hasErrors) {
    completeEdit(this, false);
    remove(entry.key); // The previous entry is stale.
  } else {
    completeEdit(this, true);
  }
  committed = true;
}
origin: nostra13/Android-Universal-Image-Loader

/** Returns the string value for {@code index}. */
public String getString(int index) throws IOException {
  return inputStreamToString(getInputStream(index));
}
origin: nostra13/Android-Universal-Image-Loader

/** Set lengths using decimal numbers like "10123". */
private void setLengths(String[] strings) throws IOException {
  if (strings.length != valueCount) {
    throw invalidLengths(strings);
  }
  try {
    for (int i = 0; i < strings.length; i++) {
      lengths[i] = Long.parseLong(strings[i]);
    }
  } catch (NumberFormatException e) {
    throw invalidLengths(strings);
  }
}
origin: nostra13/Android-Universal-Image-Loader

private static String inputStreamToString(InputStream in) throws IOException {
  return Util.readFully(new InputStreamReader(in, Util.UTF_8));
}
origin: nostra13/Android-Universal-Image-Loader

@Override
public void close() {
  try {
    cache.close();
  } catch (IOException e) {
    L.e(e);
  }
  cache = null;
}
com.nostra13.universalimageloader.cache.disc.impl.ext

Most used classes

  • DiskLruCache$Editor$FaultHidingOutputStream
  • DiskLruCache$Editor
    Edits the values for an entry.
  • DiskLruCache$Entry
  • DiskLruCache$Snapshot
    A snapshot of the values for an entry.
  • DiskLruCache
    A cache that uses a bounded amount of space on a filesystem. Each cache entry has a string key and a
  • StrictLineReader,
  • Util
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