List of usage examples for java.io File getCanonicalPath
public String getCanonicalPath() throws IOException
From source file:hoot.services.utils.MultipartSerializer.java
private static boolean validatePath(String basePath, String newPath) { boolean isValidated = false; try {/*www . ja va 2 s. co m*/ File f = new File(newPath); String potentialPath = f.getCanonicalPath(); f = new File(basePath); String containerPath = f.getCanonicalPath(); // verify that newPath is within basePath if (potentialPath.indexOf(containerPath) == 0) { isValidated = true; } } catch (IOException ex) { logger.error("Failed to validate MultipartSerializer path: {}", ex.getMessage()); } return isValidated; }
From source file:apim.restful.exportimport.utils.ArchiveGenerator.java
public static void getAllFiles(File dir, List<File> fileList) { try {/* w ww .java 2s . co m*/ File[] files = dir.listFiles(); if (files != null) { for (File file : files) { fileList.add(file); if (file.isDirectory()) { System.out.println("directory:" + file.getCanonicalPath()); getAllFiles(file, fileList); } else { System.out.println(" file:" + file.getCanonicalPath()); } } } } catch (IOException e) { e.printStackTrace(); } }
From source file:com.stevpet.sonar.plugins.dotnet.mscover.vstowrapper.implementation.VisualStudioProjectBuilder.java
private static boolean isInSourceDir(File file, File folder) { try {//from w w w . ja v a2s . c om return file.getCanonicalPath().replace('\\', '/') .startsWith(folder.getCanonicalPath().replace('\\', '/') + "/"); } catch (IOException e) { throw Throwables.propagate(e); } }
From source file:net.certiv.antlr.project.util.Utils.java
public static String findJarPathname(Class<?> ref) { try {//from ww w .jav a 2 s . co m File path = new File(ref.getClass().getProtectionDomain().getCodeSource().getLocation().toURI()); String name = path.getCanonicalPath(); if (name.endsWith("jar")) { Log.info(Utils.class, "Found: " + name); return name; } } catch (NullPointerException | URISyntaxException | IOException e) { Log.warn(Utils.class, "Unable to access executing jar"); } return null; }
From source file:kr.ac.kaist.wala.hybridroid.analysis.resource.AndroidDecompiler.java
public static String decompile(String apk) { if (!apk.endsWith(".apk")) throw new InternalError("only support apk file : " + apk); File apkFile = new File(apk); if (!apkFile.exists()) throw new InternalError("the file does not exist : " + apk); try {//from www . j a v a2 s . c o m String path = apkFile.getCanonicalPath(); String toPath = path.substring(0, path.length() - 4); String[] cmds = { "-f", "d", path, "-o", toPath }; // String apktool = Shell.walaProperties.getProperty(WalaProperties.ANDROID_APK_TOOL); // File f = new File(apktool); // if(!f.exists() || !f.isFile()){ // throw new InternalError("Cannot find APK tool: " + apktool); // } // String[] cmd = {"java", "-jar", apktool, "-f", "d", path, "-o", toPath}; // ProcessBuilder pb = new ProcessBuilder(); // pb.command(cmd); //// System.out.println(pb.command().toString()); // Process p = pb.start(); // BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); // BufferedReader bre = new BufferedReader(new InputStreamReader(p.getErrorStream())); // // String r = null; // while((r = br.readLine()) != null){ // System.out.println(r); // } // // while((r = bre.readLine()) != null){ // System.err.println(r); // } // // int res = p.waitFor(); // if(res != 0){ // throw new InternalError("failed to decompile: " + path); // } brut.apktool.Main.main(cmds); if (!SystemUtils.IS_OS_WINDOWS) permission(toPath); return toPath; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.cisco.dbds.utils.configfilehandler.ConfigFileHandler.java
/** * Load config file.// w w w .ja v a 2 s . co m * * @param filepath the filepath * @throws IOException Signals that an I/O exception has occurred. */ public static void loadConfigFile(String filepath) throws IOException { System.out.println("loadConfigFile inisde"); //File dir = new File("src/it/resources"); File dir = new File(filepath); String[] extensions = new String[] { "properties" }; System.out.println("Getting all .properties files in " + dir.getCanonicalPath() + " including those in subdirectories"); List<File> files = (List<File>) FileUtils.listFiles(dir, extensions, true); for (File file : files) { System.out.println("file: " + file.getCanonicalPath()); FileInputStream fn = new FileInputStream(file.getCanonicalPath()); setSystemvariable(fn); fn.close(); } }
From source file:com.wso2telco.identity.application.authentication.endpoint.util.TenantDataManager.java
private static String buildFilePath(String path) throws IOException { if (path != null && path.startsWith(".")) { //relative path is given File currentDirectory = new File(new File(".").getAbsolutePath()); path = currentDirectory.getCanonicalPath() + File.separator + path; }/*from w w w. j a v a 2 s .c om*/ if (log.isDebugEnabled()) { log.debug("File path for KeyStore/TrustStore : " + path); } return path; }
From source file:Main.java
public static void copyExifData(File srcImgFile, File dstImgFile) throws IOException { ExifInterface srcExif = new ExifInterface(srcImgFile.getCanonicalPath()); ExifInterface dstExif = new ExifInterface(dstImgFile.getCanonicalPath()); int buildSDKVersion = Build.VERSION.SDK_INT; // From API 11 if (buildSDKVersion >= Build.VERSION_CODES.HONEYCOMB) { if (srcExif.getAttribute(ExifInterface.TAG_APERTURE) != null) { dstExif.setAttribute(ExifInterface.TAG_APERTURE, srcExif.getAttribute(ExifInterface.TAG_APERTURE)); }// ww w . j a v a 2 s . c o m if (srcExif.getAttribute(ExifInterface.TAG_EXPOSURE_TIME) != null) { dstExif.setAttribute(ExifInterface.TAG_EXPOSURE_TIME, srcExif.getAttribute(ExifInterface.TAG_EXPOSURE_TIME)); } if (srcExif.getAttribute(ExifInterface.TAG_ISO) != null) { dstExif.setAttribute(ExifInterface.TAG_ISO, srcExif.getAttribute(ExifInterface.TAG_ISO)); } } // From API 9 if (buildSDKVersion >= Build.VERSION_CODES.GINGERBREAD) { if (srcExif.getAttribute(ExifInterface.TAG_GPS_ALTITUDE) != null) { dstExif.setAttribute(ExifInterface.TAG_GPS_ALTITUDE, srcExif.getAttribute(ExifInterface.TAG_GPS_ALTITUDE)); } if (srcExif.getAttribute(ExifInterface.TAG_GPS_ALTITUDE_REF) != null) { dstExif.setAttribute(ExifInterface.TAG_GPS_ALTITUDE_REF, srcExif.getAttribute(ExifInterface.TAG_GPS_ALTITUDE_REF)); } } // From API 8 if (buildSDKVersion >= Build.VERSION_CODES.FROYO) { if (srcExif.getAttribute(ExifInterface.TAG_FOCAL_LENGTH) != null) { dstExif.setAttribute(ExifInterface.TAG_FOCAL_LENGTH, srcExif.getAttribute(ExifInterface.TAG_FOCAL_LENGTH)); } if (srcExif.getAttribute(ExifInterface.TAG_GPS_DATESTAMP) != null) { dstExif.setAttribute(ExifInterface.TAG_GPS_DATESTAMP, srcExif.getAttribute(ExifInterface.TAG_GPS_DATESTAMP)); } if (srcExif.getAttribute(ExifInterface.TAG_GPS_PROCESSING_METHOD) != null) { dstExif.setAttribute(ExifInterface.TAG_GPS_PROCESSING_METHOD, srcExif.getAttribute(ExifInterface.TAG_GPS_PROCESSING_METHOD)); } if (srcExif.getAttribute(ExifInterface.TAG_GPS_TIMESTAMP) != null) { dstExif.setAttribute(ExifInterface.TAG_GPS_TIMESTAMP, srcExif.getAttribute(ExifInterface.TAG_GPS_TIMESTAMP)); } } if (srcExif.getAttribute(ExifInterface.TAG_DATETIME) != null) { dstExif.setAttribute(ExifInterface.TAG_DATETIME, srcExif.getAttribute(ExifInterface.TAG_DATETIME)); } if (srcExif.getAttribute(ExifInterface.TAG_FLASH) != null) { dstExif.setAttribute(ExifInterface.TAG_FLASH, srcExif.getAttribute(ExifInterface.TAG_FLASH)); } if (srcExif.getAttribute(ExifInterface.TAG_GPS_LATITUDE) != null) { dstExif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, srcExif.getAttribute(ExifInterface.TAG_GPS_LATITUDE)); } if (srcExif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF) != null) { dstExif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, srcExif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF)); } if (srcExif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE) != null) { dstExif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, srcExif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE)); } if (srcExif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF) != null) { dstExif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, srcExif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF)); } if (srcExif.getAttribute(ExifInterface.TAG_IMAGE_LENGTH) != null) { dstExif.setAttribute(ExifInterface.TAG_IMAGE_LENGTH, srcExif.getAttribute(ExifInterface.TAG_IMAGE_LENGTH)); } if (srcExif.getAttribute(ExifInterface.TAG_IMAGE_WIDTH) != null) { dstExif.setAttribute(ExifInterface.TAG_IMAGE_WIDTH, srcExif.getAttribute(ExifInterface.TAG_IMAGE_WIDTH)); } if (srcExif.getAttribute(ExifInterface.TAG_MAKE) != null) { dstExif.setAttribute(ExifInterface.TAG_MAKE, srcExif.getAttribute(ExifInterface.TAG_MAKE)); } if (srcExif.getAttribute(ExifInterface.TAG_MODEL) != null) { dstExif.setAttribute(ExifInterface.TAG_MODEL, srcExif.getAttribute(ExifInterface.TAG_MODEL)); } if (srcExif.getAttribute(ExifInterface.TAG_ORIENTATION) != null) { dstExif.setAttribute(ExifInterface.TAG_ORIENTATION, srcExif.getAttribute(ExifInterface.TAG_ORIENTATION)); } if (srcExif.getAttribute(ExifInterface.TAG_WHITE_BALANCE) != null) { dstExif.setAttribute(ExifInterface.TAG_WHITE_BALANCE, srcExif.getAttribute(ExifInterface.TAG_WHITE_BALANCE)); } dstExif.saveAttributes(); }
From source file:com.moz.fiji.schema.mapreduce.DistributedCacheJars.java
/** * @param conf Configuration to get FileSystem from * @param jarDirectory The directory of jars to get. * @return A list of qualified paths to the jars in jarDirectory. * @throws IOException if there's a problem. *//*from w w w . j a va 2 s. com*/ public static List<String> getJarsFromDirectory(Configuration conf, File jarDirectory) throws IOException { if (!jarDirectory.isDirectory()) { throw new IOException("Attempted to add jars from non-directory: " + jarDirectory.getCanonicalPath()); } List<String> allJars = new ArrayList<String>(); FileSystem fileSystem = FileSystem.getLocal(conf); for (File jar : jarDirectory.listFiles()) { if (jar.exists() && !jar.isDirectory() && jar.getName().endsWith(".jar")) { Path jarPath = new Path(jar.getCanonicalPath()); String qualifiedPath = jarPath.makeQualified(fileSystem).toString(); allJars.add(qualifiedPath); } } return allJars; }
From source file:com.adaptris.util.datastore.TestSimpleDataStore.java
private static Properties createProperties() throws IOException { Properties sp = new Properties(); File dataFile = File.createTempFile("junitsds", ".dat"); File lockFile = File.createTempFile("junitsds", ".lock"); dataFile.delete();/* ww w. ja va 2 s . c o m*/ lockFile.delete(); sp.setProperty(SimpleDataStore.FILE_PROPERTY, dataFile.getCanonicalPath()); sp.setProperty(SimpleDataStore.LOCK_PROPERTY, lockFile.getCanonicalPath()); sp.setProperty(SimpleDataStore.MAXLOCK_PROPERTY, "10"); return sp; }