<commit_before>/**
 *
 */
package com.stanfy.enroscar.images.cache;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;

import android.content.Context;
import android.os.Environment;

import com.stanfy.enroscar.beans.Bean;
import com.stanfy.enroscar.beans.BeansContainer;
import com.stanfy.enroscar.beans.EnroscarBean;
import com.stanfy.enroscar.images.ImagesManager;
import com.stanfy.enroscar.net.cache.BaseFileResponseCache;
import com.stanfy.enroscar.net.cache.CacheEntry;
import com.stanfy.enroscar.net.cache.CacheTimeRule;
import com.stanfy.enroscar.sdkdep.SdkDepUtils;
import com.stanfy.enroscar.sdkdep.SdkDependentUtils;

/**
 * File-based cache used by images manager.
 * @author <NAME> (Stanfy - http://stanfy.com)
 */
@EnroscarBean(value = ImagesManager.CACHE_BEAN_NAME, contextDependent = true)
public class ImageFileCache extends BaseFileResponseCache implements Bean {

  /** Bigger images cache (10M). */
  public static final long MAX_SIZE = 10 * 1024 * 1024;

  /** Application context. */
  private final Context context;
  
  public ImageFileCache(final Context context) {
    this.context = context;
  }
  
  @Override
  public void onInitializationFinished(final BeansContainer beansContainer) {
    final String eState = Environment.getExternalStorageState();
    SdkDependentUtils sdkUtils = SdkDepUtils.get(context);
    final File baseDir = Environment.MEDIA_MOUNTED.equals(eState)
        ? sdkUtils.getExternalCacheDir(context)
        : context.getCacheDir();
    setWorkingDirectory(new File(baseDir, "images"));
    setMaxSize(MAX_SIZE);
    super.onInitializationFinished(beansContainer);
  }
  
  @Override
  protected CacheEntry createCacheEntry() { return new ImageCacheEntry(); }

  /** Image cache entry. */
  public static class ImageCacheEntry extends CacheEntry {
    /** Image type identifier. */
    int imageType = -1;

    @Override
    protected void writeMetaData(final Writer writer) throws IOException {
      writeInt(writer, imageType);
    }<commit_msg>change images file cache directory selection<commit_after>/**
 *
 */
package com.stanfy.enroscar.images.cache;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;

import android.content.Context;
import android.os.Environment;
import android.util.Log;

import com.stanfy.enroscar.beans.Bean;
import com.stanfy.enroscar.beans.BeansContainer;
import com.stanfy.enroscar.beans.EnroscarBean;
import com.stanfy.enroscar.images.ImagesManager;
import com.stanfy.enroscar.net.cache.BaseFileResponseCache;
import com.stanfy.enroscar.net.cache.CacheEntry;
import com.stanfy.enroscar.net.cache.CacheTimeRule;
import com.stanfy.enroscar.sdkdep.SdkDepUtils;
import com.stanfy.enroscar.sdkdep.SdkDependentUtils;

/**
 * File-based cache used by images manager.
 * @author <NAME> (Stanfy - http://stanfy.com)
 */
@EnroscarBean(value = ImagesManager.CACHE_BEAN_NAME, contextDependent = true)
public class ImageFileCache extends BaseFileResponseCache implements Bean {

  /** Bigger images cache (10M). */
  public static final long MAX_SIZE = 10 * 1024 * 1024;

  /** Application context. */
  private final Context context;
  
  public ImageFileCache(final Context context) {
    this.context = context;
  }
  
  @Override
  public void onInitializationFinished(final BeansContainer beansContainer) {
    if (getWorkingDirectory() == null) {
      final String eState = Environment.getExternalStorageState();
      SdkDependentUtils sdkUtils = SdkDepUtils.get(context);
      File baseDir = Environment.MEDIA_MOUNTED.equals(eState)
          ? sdkUtils.getExternalCacheDir(context)
          : context.getCacheDir();
      if (baseDir == null) {
        baseDir = context.getCacheDir();
        Log.w(TAG, "Could not locate cache on the external storage");
      }
      setWorkingDirectory(new File(baseDir, "images"));
    }
    if (getMaxSize() == 0) {
      setMaxSize(MAX_SIZE);
    }
    super.onInitializationFinished(beansContainer);
  }
  
  @Override
  protected CacheEntry createCacheEntry() { return new ImageCacheEntry(); }

  /** Image cache entry. */
  public static class ImageCacheEntry extends CacheEntry {
    /** Image type identifier. */
    int imageType = -1;

    @Override
    protected void writeMetaData(final Writer writer) throws IOException {
      writeInt(writer, imageType);
    }
{'fraction_non_alphanumeric': 0.10386363636363637, 'fraction_numerical': 0.006136363636363636, 'mean_word_length': 4.18374558303887, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1465581', 'n_tokens_mistral': 1353, 'n_tokens_neox': 1315, 'n_words': 294}