Android Open Source - Dumbledroid File Controller






From Project

Back to project page Dumbledroid.

License

The source code is released under:

Copyright (c) 2013, Leocadio Tin? All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: ...

If you think the Android project Dumbledroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package io.leocad.dumbledroid.data.cache;
/*from   w ww.jav a2 s  . c om*/
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.os.Environment;

public class FileController {

  private static final String DUMBLEDROID_CACHE_DIR = "dumbledroid";

  private final Context mContext;

  public FileController(Context ctx) {
    mContext = ctx;
  }

  public FileInputStream getFileInputStream(String fileName) throws FileNotFoundException {
    final File file = new File(getCacheDir(), fileName);
    return new FileInputStream(file);
  }

  public FileOutputStream getFileOutputStream(String fileName) throws FileNotFoundException {
    final File file = new File(getCacheDir(), fileName);
    file.getParentFile().mkdirs();
    return new FileOutputStream(file);
  }

  public void erase(String fileName) {
    final File file = new File(getCacheDir(), fileName);
    file.delete();
  }

  private File getCacheDir() {
    final File cacheDir = isExternalStorageAvailable() ? getExternalCacheDir() : mContext.getCacheDir();
    return new File(cacheDir, DUMBLEDROID_CACHE_DIR);
  }

  @TargetApi(8)
  private File getExternalCacheDir() {
    if (Build.VERSION.SDK_INT >= 8) {
      final File externalCacheDir = mContext.getExternalCacheDir();
      if(externalCacheDir != null) {
        return externalCacheDir;
      }
    }
    final String cacheDirPath = "Android" + File.separator + "data" + File.separator + mContext.getPackageName() + File.separator + "cache";
    return new File(Environment.getExternalStorageDirectory(), cacheDirPath);
  }

  private static boolean isExternalStorageAvailable() {
    return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) || !isExternalStorageRemovable();
  }

  @TargetApi(9)
  private static boolean isExternalStorageRemovable() {
    if (Build.VERSION.SDK_INT >= 9) {
      return Environment.isExternalStorageRemovable();
    }
    return true;
  }
}




Java Source Code List

io.leocad.dumbledoreexample.activities.AboutActivity.java
io.leocad.dumbledoreexample.activities.BaseActivity.java
io.leocad.dumbledoreexample.activities.FlickrActivity.java
io.leocad.dumbledoreexample.activities.JediActivity.java
io.leocad.dumbledoreexample.activities.MainActivity.java
io.leocad.dumbledoreexample.activities.SithActivity.java
io.leocad.dumbledoreexample.adapters.FlickrAdapter.java
io.leocad.dumbledoreexample.models.FlickrPhotos.java
io.leocad.dumbledoreexample.models.Jedi.java
io.leocad.dumbledoreexample.models.Media.java
io.leocad.dumbledoreexample.models.PhotoItem.java
io.leocad.dumbledoreexample.models.Sith.java
io.leocad.dumbledoreexample.models.Suit.java
io.leocad.dumbledroid.data.AbstractModel.java
io.leocad.dumbledroid.data.DataController.java
io.leocad.dumbledroid.data.DataType.java
io.leocad.dumbledroid.data.JsonReflector.java
io.leocad.dumbledroid.data.ReflectionHelper.java
io.leocad.dumbledroid.data.XmlReflector.java
io.leocad.dumbledroid.data.cache.DiskCache.java
io.leocad.dumbledroid.data.cache.FileController.java
io.leocad.dumbledroid.data.cache.MemoryCache.java
io.leocad.dumbledroid.data.cache.ModelHolder.java
io.leocad.dumbledroid.data.cache.ObjectCopier.java
io.leocad.dumbledroid.data.xml.Node.java
io.leocad.dumbledroid.data.xml.SaxHandler.java
io.leocad.dumbledroid.data.xml.SaxParser.java
io.leocad.dumbledroid.net.HttpLoader.java
io.leocad.dumbledroid.net.HttpMethod.java
io.leocad.dumbledroid.net.NoConnectionException.java
io.leocad.dumbledroid.net.TimeoutException.java
io.leocad.dumbledroidplugin.core.ClassMapper.java
io.leocad.dumbledroidplugin.core.ClassWriter.java
io.leocad.dumbledroidplugin.core.DumbledroidClassCreator.java
io.leocad.dumbledroidplugin.core.FileUtils.java
io.leocad.dumbledroidplugin.core.JsonReverseReflector.java
io.leocad.dumbledroidplugin.core.XmlReverseReflector.java
io.leocad.dumbledroidplugin.exceptions.InvalidContentException.java
io.leocad.dumbledroidplugin.exceptions.InvalidUrlException.java
io.leocad.dumbledroidplugin.exceptions.UnsupportedContentTypeException.java
io.leocad.dumbledroidplugin.wizards.DataInputPage.java
io.leocad.dumbledroidplugin.wizards.FileCreationPage.java
io.leocad.dumbledroidplugin.wizards.NewModelWizard.java
org.apache.commons.validator.routines.DomainValidator.java
org.apache.commons.validator.routines.InetAddressValidator.java
org.apache.commons.validator.routines.RegexValidator.java
org.apache.commons.validator.routines.UrlValidator.java