NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

public class FileUtility {
public static final String VIDEO_DIRECTORY_NAME = "video";
public static final String TEMP_VIDEO_FILE = "temp.mp4";

public static File getVideoFileLocal(Context context, String url) {
File parentDirectory = getVideoDirectoryLocal(context);
return new File(parentDirectory, Utils.getFileNameFromURL(url));
}

public static File getInternalFileLocation(Context context, String videoname) {
File parentInternalDir = getVideoDirectoryLocal(context);
parentInternalDir.mkdir();
return new File(parentInternalDir, videoname);
}

public static void renameFile(File inputFile, File outputFile) {
if (inputFile.exists())
inputFile.renameTo(outputFile);
}

public static File getMemoryCardFileLocation(Context context, String videoName) {
File[] f = ContextCompat.getExternalFilesDirs(context, null);
if (f != null) {
if (f.length > 1 && f[1] != null) {
File dirVideos = new File(f[1], VIDEO_DIRECTORY_NAME);
dirVideos.mkdir();
return new File(dirVideos, videoName);
}
}
File file = getMemoryCardVideosDir(context);
if (file != null) {
return new File(file.getAbsolutePath(), videoName);
}
return null;
}

public static File getMemoryCardVideosDir(Context context) {
File[] f = ContextCompat.getExternalFilesDirs(context, null);
if (f != null) {
if (f.length > 1 && f[1] != null) {
File dirVideos = new File(f[1], VIDEO_DIRECTORY_NAME);
dirVideos.mkdirs();
return dirVideos;
}
}
final String rawSecondaryStoragesStr = System.getenv("SECONDARY_STORAGE");
final String rawExternalStorage = System.getenv("EXTERNAL_STORAGE");
if (!Utils.isEmpty(rawSecondaryStoragesStr) && new File(rawSecondaryStoragesStr).exists()) {
File sdcardAndroiDataPath = new File(rawSecondaryStoragesStr, "Android/data/" + context.getPackageName() + File.separator + "files" + File.separator + VIDEO_DIRECTORY_NAME);
sdcardAndroiDataPath.mkdirs();
if (sdcardAndroiDataPath.exists())
return sdcardAndroiDataPath;
}
// else if (!Utils.isEmpty(rawExternalStorage) && new File(rawExternalStorage).exists() && new File(rawExternalStorage).canWrite()) {
// File sdcardAndroiDataPath = new File(rawExternalStorage, "Android/data/" + context.getPackageName() + File.separator + "files" + File.separator + VIDEO_DIRECTORY_NAME);
// sdcardAndroiDataPath.mkdirs();
// if (sdcardAndroiDataPath.exists())
// return sdcardAndroiDataPath;
// }
return null;
}

public static File getPartFilePath(Context context, String videoTitle) {
videoTitle = videoTitle.replace(".mp4", ".part");
File extPart = FileUtility.getMemoryCardFileLocation(context, videoTitle);
if (extPart != null && extPart.exists())
return extPart;
File internalLocationPart = FileUtility.getInternalFileLocation(context, videoTitle);
if (internalLocationPart != null && internalLocationPart.exists())
return internalLocationPart;
return null;
}

public static boolean moveFile(File inputPath, File outputPath) {

InputStream in = null;
OutputStream out = null;
try {

//create output directory if it doesn't exist
in = new FileInputStream(inputPath);
out = new FileOutputStream(outputPath);

byte[] buffer = new byte[2048];
int read;
while ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
in.close();
in = null;
// write the output file
out.flush();
out.close();
out = null;

// delete the original file
inputPath.delete();


} catch (Exception fnfe1) {
LOGHB.e("tag", fnfe1.getMessage());
}
return outputPath.exists();

}


public static boolean spaceAvailableInSDCard(Context context, long fileSize) {
// File[] f = ContextCompat.getExternalFilesDirs(context, null);
File f = getMemoryCardVideosDir(context);
if (f != null) {
StatFs stat = new StatFs(f.getAbsolutePath());
long bytesAvailable = 0;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
bytesAvailable = stat.getAvailableBlocksLong() * stat.getBlockSizeLong();
} else {
bytesAvailable = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
}
// long megAvailable = bytesAvailable / 1048576;
LOGHB.e("Size", "Available Space :" + bytesAvailable + " >> new File Size " + fileSize);
return bytesAvailable > fileSize;
}
// if (f != null) {
// if (f.length > 1 && f[1] != null) {
//
// }
// }
return false;
}

public static boolean spaceAvailableInInternalMemory(Context context, long fileSize) {
File[] f = ContextCompat.getExternalFilesDirs(context, null);
if (f != null) {
if (f.length > 0 && f[0] != null) {
StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
long bytesAvailable = 0;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
bytesAvailable = stat.getAvailableBlocksLong() * stat.getBlockSizeLong();
} else {
bytesAvailable = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
}
LOGHB.e("Size", "Available Space :" + bytesAvailable + " >> new File Size " + fileSize);
return bytesAvailable > fileSize;
}
}
return false;
}

public static boolean isSDCardAvailable(Context context) {

File[] f = ContextCompat.getExternalFilesDirs(context, null);
if (f != null) {
if (f.length > 1 && f[1] != null && !Utils.isEmpty(f[1].getAbsolutePath())) {
return Environment.MEDIA_MOUNTED.equalsIgnoreCase(EnvironmentCompat.getStorageState(f[1]));
}
}
final String rawExternalStorage = System.getenv("EXTERNAL_STORAGE");
// All Secondary SD-CARDs (all exclude primary) separated by ":"
final String rawSecondaryStoragesStr = System.getenv("SECONDARY_STORAGE");
// Primary emulated SD-CARD
final String rawEmulatedStorageTarget = System.getenv("EMULATED_STORAGE_TARGET");
if (!Utils.isEmpty(rawSecondaryStoragesStr) && new File(rawSecondaryStoragesStr).exists()) {
File sdcardAndroiDataPath = new File(rawSecondaryStoragesStr, "Android/data/" + context.getPackageName() + File.separator + "files");
sdcardAndroiDataPath.mkdirs();
return sdcardAndroiDataPath.exists();
}
// else if (!Utils.isEmpty(rawExternalStorage) && new File(rawExternalStorage).exists() && new File(rawExternalStorage).canWrite()) {
// File sdcardAndroiDataPath = new File(rawExternalStorage, "Android/data/" + context.getPackageName() + File.separator + "files");
// sdcardAndroiDataPath.mkdirs();
// return sdcardAndroiDataPath.exists();
// }
return false;
}

public static File getRequiredDirectoryPath(Context context, String directoryName) {
File[] f = ContextCompat.getExternalFilesDirs(context, null);
if (f != null) {
LOGHB.d("Array Size", f.length + "");
if (f.length >= 1 && f[1] != null) {
File dir = new File(f[1], "/" + directoryName);
dir.mkdir();
LOGHB.d("sd card", dir + "");
return dir;
} else {
File dir = new File(f[0], "/" + directoryName);
dir.mkdir();
LOGHB.d("internal card", dir + "");
return dir;
}
}
return null;
}

public static File getVideoDirectoryLocal(Context context) {
File temp = context.getExternalFilesDir(null);
File tempSD = new File(Environment.getExternalStorageDirectory() + File.separator + "Android" + File.separator + "data" + File.separator + context.getPackageName() + File.separator + "files" + File.separator);
if (temp == null) {
tempSD.mkdirs();
temp = new File(tempSD.getAbsolutePath());
}
File parentDir = new File(temp.getAbsolutePath() + File.separator + VIDEO_DIRECTORY_NAME + File.separator);
parentDir.mkdirs();
return parentDir;
}

public static File getCacheDirectory(Context context) {
File cacheDir = new File(context.getCacheDir() + File.separator + VIDEO_DIRECTORY_NAME);
cacheDir.mkdirs();
return new File(cacheDir, TEMP_VIDEO_FILE);
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.