Android Open Source - android-simple-storage External Storage






From Project

Back to project page android-simple-storage.

License

The source code is released under:

Apache License

If you think the Android project android-simple-storage 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 com.sromku.simple.storage;
/*from w  w w. ja  v  a 2s  . co m*/
import java.io.File;

import android.os.Environment;

import com.sromku.simple.storage.SimpleStorage.StorageType;

/**
 * Storage that responsible for storing on external storage like SD card.<br>
 * This class can be initiated <b>only</b> by {@link SimpleStorage} singleton
 * class.
 * 
 * @author Roman Kushnarenko - sromku (sromku@gmail.com)
 * 
 */
public class ExternalStorage extends AbstractDiskStorage {

  /**
   * Contractor as friend. Means, only classes from the same package can
   * initiate this class.<br>
   * <br>
   * 
   * <b>DO NOT CHANGE</b> to -> public, private or protected
   */
  ExternalStorage() {
    super();
  }

  @Override
  public StorageType getStorageType() {
    return StorageType.EXTERNAL;
  }

  /**
   * Checks if external storage is available for read and write. <br>
   * 
   * @return <code>True</code> if external storage writable, otherwise return
   *         <code>False</code>
   */
  public boolean isWritable() {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
      return true;
    }
    return false;
  }
  
  @Override
  protected String buildAbsolutePath() {
    return Environment.getExternalStorageDirectory().getAbsolutePath();
  }

  /**
   * Build path of folder or file on the external storage location. <br>
   * <b>Note: </b> <li>For directory use regular name</li> <li>For file name
   * use name with .extension like <i>abc.png</i></li><br>
   * <br>
   * 
   * @param name
   *            The name of the directory
   * @param storageLocation
   * @return
   */
  protected String buildPath(String name) {
    String path = buildAbsolutePath();
    path = path + File.separator + name;
    return path;
  }

  /**
   * Build folder + file on the external storage location. <br>
   * <b>Note: </b> <li>For directory use regular name</li> <li>For file name
   * use name with .extension like <i>abc.png</i></li><br>
   * <br>
   * 
   * @param directoryName
   *            The directory name
   * @param fileName
   *            The file name
   * @return
   */
  protected String buildPath(String directoryName, String fileName) {
    String path = Environment.getExternalStorageDirectory().getAbsolutePath();
    path = path + File.separator + directoryName + File.separator + fileName;
    return path;
  }

}




Java Source Code List

com.sromku.simple.storage.AbstractDiskStorage.java
com.sromku.simple.storage.ExternalStorage.java
com.sromku.simple.storage.InternalStorage.java
com.sromku.simple.storage.SimpleStorageConfiguration.java
com.sromku.simple.storage.SimpleStorage.java
com.sromku.simple.storage.Storable.java
com.sromku.simple.storage.StorageException.java
com.sromku.simple.storage.Storage.java
com.sromku.simple.storage.helpers.ImmutablePair.java
com.sromku.simple.storage.helpers.OrderType.java
com.sromku.simple.storage.helpers.SizeUnit.java
com.sromku.simple.storage.security.CipherAlgorithmType.java
com.sromku.simple.storage.security.CipherModeType.java
com.sromku.simple.storage.security.CipherPaddingType.java
com.sromku.simple.storage.security.CipherTransformationType.java
com.sromku.simple.storage.security.SecurityUtil.java