{"id":13464115,"url":"https://github.com/sromku/android-storage","last_synced_at":"2025-03-25T10:32:01.136Z","repository":{"id":12806176,"uuid":"15481033","full_name":"sromku/android-storage","owner":"sromku","description":"Create, read, delete, append, encrypt files and more, on internal or external disk spaces with a really simple API","archived":true,"fork":false,"pushed_at":"2020-09-30T15:03:57.000Z","size":993,"stargazers_count":904,"open_issues_count":19,"forks_count":204,"subscribers_count":45,"default_branch":"master","last_synced_at":"2024-10-29T16:22:56.988Z","etag":null,"topics":["android","library","storage"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sromku.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-27T20:07:00.000Z","updated_at":"2024-09-01T20:14:37.000Z","dependencies_parsed_at":"2022-08-29T08:30:29.305Z","dependency_job_id":null,"html_url":"https://github.com/sromku/android-storage","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sromku%2Fandroid-storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sromku%2Fandroid-storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sromku%2Fandroid-storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sromku%2Fandroid-storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sromku","download_url":"https://codeload.github.com/sromku/android-storage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245444167,"owners_count":20616335,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","library","storage"],"created_at":"2024-07-31T14:00:34.580Z","updated_at":"2025-03-25T10:32:00.627Z","avatar_url":"https://github.com/sromku.png","language":"Java","readme":"android-storage\n======================\n\nLibrary to create, read, delete, append, encrypt files and more, on internal or external disk spaces with a really simple API.\n\n## Latest Release\n\n[ ![Download](https://api.bintray.com/packages/sromku/maven/storage/images/download.svg) ](https://bintray.com/sromku/maven/storage/_latestVersion)\n\n``` groovy\ndependencies {\n    compile 'com.snatik:storage:2.1.0'\n}\n```\n\nDon't forget to update `AndroidManifest.xml` and add next line:\n\n``` xml\n\u003cuses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\" /\u003e\n```\n\n## Usage\n\n``` java\n\n// init\nStorage storage = new Storage(getApplicationContext());\n\n// get external storage\nString path = storage.getExternalStorageDirectory();\n\n// new dir\nString newDir = path + File.separator + \"My Sample Directory\";\nstorage.createDirectory(newDir);\n```\n\nCheck all options, scroll down ;)\n\n\n## Sample app\n\nThe app has some simple UI screens and uses the storage library. This is just an example of what can be done with this lib.\n\n\u003cimg src=\"assets/sample_app.png\"/\u003e\n\n## Options\n* [Easy define Internal or External storage](#initialize)\n* [Create directory](#create-directory)\n* [Create file](#create-file)\n* [Read file content](#read-file)\n* [Append content to file](#append-content-to-file)\n* [Copy](#copy)\n* [Move](#move)\n* [Delete directory](#delete-directory)\n* [Delete file](#delete-file)\n* [Get files](#get-files)\n* [More options](#more)\n* [Encrypt the file content](#security-configuration)\n\n### Initialize\n\n```\nStorage storage = new Storage(getApplicationContext());\n```\n\nWork on **External Storage**.\n\n- Check if external writable\n\n\t``` java\n\tboolean isWritable = storage.isExternalWritable();\n\t```\n\n- Root external storage path\n\n\t``` java\n\tString path = storage.getExternalStorageDirectory();\n\t```\n\n- If you want to use a particular public directory\n\n    ``` java\n    Storage storage = SimpleStorage.getExternalStorage(Environment.DIRECTORY_PICTURES);\n    ```\n\nWork on **Internal Storage**. \n\n- Directory for storing app internal files ([documentation](https://developer.android.com/training/basics/data-storage/files.html#WriteInternalStorage)):\n\n\t``` java\n\tString path = SimpleStorage.getInternalFilesDirectory();\n\t```\n\t\n- Cache dir\n\n\t``` java\n\tString path = SimpleStorage.getInternalCacheDirectory();\n\t```\n\t\n- Root internal storage dir\n\n\t``` java\n\tString path = SimpleStorage.getInternalRootDirectory();\n\t```\n\n### Create directory\n\n- Create directory\n\n\t``` java\n\tstorage.createDirectory(path);\n\t```\n\n- Create directory and **override** the existing one. \n\n\t``` java\n\tstorage.createDirectory(path, true);\n\t```\n\n### Create file\n\nCreate a new file with the content in it.\n\n``` java\nstorage.createFile(path, \"some content of the file\");\n```\n\nThe `content` of the file can be one of the next types:\n- `String`\n- `byte[]`\n- `Bitmap`\n- `Storable`\n\n### Read file\n\nRead the content of any file to byte array.\n\n``` java\nbyte[] bytes = storage.readFile(path);\n```\n\nRead the content of the file to String.\n``` java\nString content = storage.readTextFile(path);\n```\n\n### Append content to file\n``` java\nstorage.appendFile(path, \"more new data\");\n```\n\nYou can append:\n- `String`\n- `byte[]`\n\n### Copy\n``` java\nstorage.copy(fromPath, toPath);\n```\n\n### Move\n``` java\nstorage.move(fromPath, toPath);\n```\n\n### Delete directory\n``` java\nstorage.deleteDirectory(path);\n```\n\n### Delete file\n``` java\nstorage.deleteFile(path);\n```\n\n### Get files\n- Get files in ordered way by: `name`, `date`, `size`\n\t``` java\n\tList\u003cFile\u003e files = storage.getFiles(path, OrderType.DATE);\n\t```\n\n- Get files and filter by regular expression:\n\t``` java\n\tString regex = ...;\n\tList\u003cFile\u003e files = storage.getFiles(path, regex);\n\t```\n\n* Get all nested files (without the directories)\n\t``` java\n\tList\u003cFile\u003e files = storage.getNestedFiles(path);\n\t```\n\n### More...\n\n* Is directory exists\n\t``` java\n\tboolean dirExists = storage.isDirectoryExists(path);\n\t```\n\n* Is file exists\n\t``` java\n\tboolean fileExists = storage.isFileExist(path);\n\t```\n\n\n## Security configuration\nYou can write and read files while the content is **encrypted**. It means, that no one can read the data of your files from external or internal storage.\n\nYou will continue using the same api as before. The only thing you need to do is to configure the Simple Storage library before the you want to create/read encrypted data.\n\n``` java\n// set encryption\nString IVX = \"abcdefghijklmnop\"; // 16 lenght - not secret\nString SECRET_KEY = \"secret1234567890\"; // 16 lenght - secret\nbyte[] SALT = \"0000111100001111\".getBytes(); // random 16 bytes array\n\n// build configuratio\nEncryptConfiguration configuration = new EncryptConfiguration.Builder()\n\t.setEncryptContent(IVX, SECRET_KEY, SALT)\n\t.build();\n\t\n// configure the simple storage\nstorage.setEncryptConfiguration(configuration);\n```\n\nNow, you can create a new file with content and the content will be automatically encrypted.\u003cbr\u003e\nYou can read the file and the content will be decrypted.\n\n**Example**\n\nCreate file with next content `\"this is the secret data\"`:\n``` java\nstorage.setEncryptConfiguration(configuration);\nstorage.createFile(path, \"this is the secret data\");\n```\n\nIf we open the file to see it's content then it we will something like this: `„f°α�ΤG†_i\u0003ΐp` . It looks good :)\n\nAnd now, read the file data with the same api:\n``` java\nstorage.setEncryptConfiguration(configuration);\nString content = storage.readTextFile(path);\n```\nYou will see that the content will be: `\"this is the secret data\"`.\n\n## Tests\n\nJust play and check the sample app ;)\n","funding_links":[],"categories":["Java"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsromku%2Fandroid-storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsromku%2Fandroid-storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsromku%2Fandroid-storage/lists"}