List of usage examples for java.io File canRead
public boolean canRead()
From source file:Main.java
public static List<String> getSubtitlePath(String videoPath) { List<String> sbPathList = new ArrayList<String>(); if (TextUtils.isEmpty(videoPath)) return sbPathList; if (videoPath.contains("file")) { videoPath = videoPath.substring(7); }//from www .j a va 2 s . co m int end = videoPath.lastIndexOf("/", videoPath.length()); String path = videoPath.substring(0, end + 1); end = videoPath.lastIndexOf(".", videoPath.length()); if (-1 == end || null == path) return sbPathList; String subffix = videoPath.substring(0, end); File files = new File(path); if ((files != null) && (files.exists()) && (files.isDirectory())) { File[] filesInDir = files.listFiles(); long count = filesInDir.length; for (int num = 0; num < count; num++) { String filePath = filesInDir[num].getPath(); File subTitleFile = new File(filePath); if ((subTitleFile != null) && (subTitleFile.isFile()) && (subTitleFile.canRead())) { int pos = filePath.lastIndexOf(".", filePath.length()); String sub = filePath.substring(pos + 1, filePath.length()); if ((filePath.startsWith(subffix)) && (sub != null) && ((sub.equalsIgnoreCase("srt")) || (sub.equalsIgnoreCase("ass")) || (sub.equalsIgnoreCase("smi")) || (sub.equalsIgnoreCase("ssa")))) { sbPathList.add(filePath); } } } if (sbPathList.size() != 0) { return sbPathList; } } return sbPathList; }
From source file:Main.java
public static List<String> getSubtitlePath(String videoPath) { List<String> sbPathList = new ArrayList<String>(); if (TextUtils.isEmpty(videoPath)) return sbPathList; if (videoPath.contains("file")) { videoPath = videoPath.substring(7); }//from w w w . ja va2 s .c om int end = videoPath.lastIndexOf("/", videoPath.length()); String path = videoPath.substring(0, end + 1); end = videoPath.lastIndexOf(".", videoPath.length()); if (-1 == end || null == path) return sbPathList; String subffix = videoPath.substring(0, end); File files = new File(path); if ((files != null) && (files.exists()) && (files.isDirectory())) { File[] filesInDir = files.listFiles(); long count = filesInDir.length; for (int num = 0; num < count; num++) { String filePath = filesInDir[num].getPath(); File subTitleFile = new File(filePath); if ((subTitleFile != null) && (subTitleFile.isFile()) && (subTitleFile.canRead())) { int pos = filePath.lastIndexOf(".", filePath.length()); String sub = filePath.substring(pos + 1, filePath.length()); if ((filePath.startsWith(subffix)) && (sub != null) && ((sub.equalsIgnoreCase("srt")) || (sub.equalsIgnoreCase("ass")) || (sub.equalsIgnoreCase("smi")) || (sub.equalsIgnoreCase("ssa")) || (sub.equalsIgnoreCase("sub")))) { sbPathList.add(filePath); } } } if (sbPathList.size() != 0) { return sbPathList; } } return sbPathList; }
From source file:Main.java
@SuppressWarnings("deprecation") public static int[] getBitmapSize(File file, int targetWidth, int targetHeight) { if (null != file && file.exists() && file.isFile() && file.canRead()) { String path = file.getAbsolutePath(); Options opts = new Options(); if (targetWidth > 0 && targetHeight > 0) { opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(path, opts); opts.inSampleSize = computeSampleSize(opts, Math.min(targetWidth, targetHeight), targetWidth * targetHeight); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { opts.inInputShareable = true; opts.inPurgeable = true; }// w ww . ja v a 2 s . c o m } BitmapFactory.decodeFile(path, opts); return new int[] { opts.outWidth, opts.outHeight }; } return null; }
From source file:Main.java
public static String[] getMountedVolumes() { final String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { // we can read the External Storage... //Retrieve the primary External Storage: final File primaryExternalStorage = Environment.getExternalStorageDirectory(); //Retrieve the External Storages root directory: String externalStorageRootDir = null; if ((externalStorageRootDir = primaryExternalStorage.getParent()) == null) { // no parent... return (new String[] { "ONLY A SINGLE VOLUME HAS BEEN DETECTED!", (Environment.isExternalStorageRemovable() ? "(REMOVABLE SD-CARD)" : "(INTERNAL STORAGE)") + " PRIMARY STORAGE: " + primaryExternalStorage }); } else {/* ww w .ja v a 2 s.c om*/ final File externalStorageRoot = new File(externalStorageRootDir); final File[] files = externalStorageRoot.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String filename) { // TODO Auto-generated method stub File file = new File(dir, filename); if (file.isDirectory() && file.canRead() && file.canWrite() && !file.isHidden()) { return true; } return false; } }); //.listFiles(); List<String> data = new ArrayList<String>(); if (files.length > 1) { data.add("MULTIPLE VOLUMES HAS BEEN DETECTED!"); data.add("Enumerating detected volumes . . ."); } else { data.add("ONLY A SINGLE VOLUME HAS BEEN DETECTED!"); } for (final File file : files) { if (file.isDirectory() && file.canRead() && file.canWrite() && !file.isHidden() && (files.length > 0)) { // it is a real directory (not a USB drive)... if (file.toString().equals(primaryExternalStorage.toString())) data.add((Environment.isExternalStorageRemovable() ? "(REMOVABLE SD-CARD)" : "(INTERNAL Memory)") + " PRIMARY STORAGE: " + file.getAbsolutePath()); else { data.add(((file.toString().contains("usb") || file.toString().contains("USB")) ? "MOUNTED USB" : "MOUNTED") + " STORAGE: " + file.getAbsolutePath()); } } } return data.toArray(new String[data.size()]); } } else { // we cannot read the External Storage..., return null return null; } }
From source file:eu.eubrazilcc.lvl.oauth2.AllJUnitTests.java
@BeforeClass public static void setup() { System.out.println("AllJUnitTests.setup()"); final URL anchorURL = AllJUnitTests.class.getClassLoader().getResource(ANCHOR_FILENAME); File anchorFile = null;// w w w. j a v a 2 s . co m try { anchorFile = new File(anchorURL.toURI()); } catch (Exception e) { anchorFile = new File(System.getProperty("user.dir")); } TEST_RESOURCES_PATH = concat(anchorFile.getParent(), "files"); final File resDir = new File(TEST_RESOURCES_PATH); if (resDir != null && resDir.isDirectory() && resDir.canRead()) { try { TEST_RESOURCES_PATH = resDir.getCanonicalPath(); } catch (IOException e) { // nothing to do } } else { throw new IllegalStateException("Invalid test resources pathname: " + TEST_RESOURCES_PATH); } System.out.println("Test resources pathname: " + TEST_RESOURCES_PATH); // load logging bridges LOG_MANAGER.preload(); // system pre-loading LIGHT_CLOSER_SERVICE_MOCK.preload(); }
From source file:edu.kit.checkstyle.Main.java
/** * Traverses a specified node looking for files to check. Found * files are added to a specified list. Subdirectories are also * traversed./*from w w w .j av a 2 s . c om*/ * * @param aNode the node to process * @param aFiles list to add found files to */ private static void traverse(File aNode, List<File> aFiles) { if (aNode.canRead()) { if (aNode.isDirectory()) { final File[] nodes = aNode.listFiles(); for (File element : nodes) { traverse(element, aFiles); } } else if (aNode.isFile()) { aFiles.add(aNode); } } }
From source file:eu.eubrazilcc.lvl.storage.AllJUnitTests.java
@BeforeClass public static void setup() { System.out.println("AllJUnitTests.setup()"); final URL anchorURL = AllIntegrationTests.class.getClassLoader().getResource(ANCHOR_FILENAME); File anchorFile = null;// www .j a v a 2 s . c o m try { anchorFile = new File(anchorURL.toURI()); } catch (Exception e) { anchorFile = new File(System.getProperty("user.dir")); } TEST_RESOURCES_PATH = concat(anchorFile.getParent(), "files"); final File resDir = new File(TEST_RESOURCES_PATH); if (resDir != null && resDir.isDirectory() && resDir.canRead()) { try { TEST_RESOURCES_PATH = resDir.getCanonicalPath(); } catch (IOException e) { // nothing to do } } else { throw new IllegalStateException("Invalid test resources pathname: " + TEST_RESOURCES_PATH); } System.out.println("Test resources pathname: " + TEST_RESOURCES_PATH); // load logging bridges LOG_MANAGER.preload(); // system pre-loading LIGHT_CLOSER_SERVICE_MOCK.preload(); }
From source file:eu.eubrazilcc.lvl.storage.AllIntegrationTests.java
@BeforeClass public static void setup() { System.out.println("AllIntegrationTests.setup()"); final URL anchorURL = AllIntegrationTests.class.getClassLoader().getResource(ANCHOR_FILENAME); File anchorFile = null;/* w w w. j a va 2s . c o m*/ try { anchorFile = new File(anchorURL.toURI()); } catch (Exception e) { anchorFile = new File(System.getProperty("user.dir")); } TEST_RESOURCES_PATH = concat(anchorFile.getParent(), "files"); final File resDir = new File(TEST_RESOURCES_PATH); if (resDir != null && resDir.isDirectory() && resDir.canRead()) { try { TEST_RESOURCES_PATH = resDir.getCanonicalPath(); } catch (IOException e) { // nothing to do } } else { throw new IllegalStateException("Invalid test resources pathname: " + TEST_RESOURCES_PATH); } System.out.println("Test resources pathname: " + TEST_RESOURCES_PATH); // load logging bridges LOG_MANAGER.preload(); // system pre-loading CLOSER_SERVICE_MOCK.preload(); }
From source file:edu.kit.dama.staging.util.StagingUtils.java
/** * Checking directory for beeing a directory, readable and writable. * * @param pDir The directory to check.//from ww w . j a v a2 s. co m * * @return TRUE if pDir is a directory, readable and writable. */ private static boolean isAccessibleDirectory(File pDir) { return pDir != null && pDir.isDirectory() && pDir.canRead() && pDir.canWrite(); }
From source file:Main.java
public static void copyfile(String fromFilePath, String toFilePath, Boolean rewrite) { File fromFile = new File(fromFilePath); File toFile = new File(toFilePath); if (!fromFile.exists() || !fromFile.isFile() || !fromFile.canRead()) { return;//ww w .j a v a 2s . c o m } if (!toFile.getParentFile().exists()) { toFile.getParentFile().mkdirs(); } if (toFile.exists() && rewrite) { toFile.delete(); } try { FileInputStream fosfrom = new FileInputStream(fromFile); FileOutputStream fosto = new FileOutputStream(toFile); byte[] bt = new byte[1024]; int c; while ((c = fosfrom.read(bt)) > 0) { fosto.write(bt, 0, c); } fosfrom.close(); fosto.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }