/** * Open an <code>InputStream</code> to <code>location</code>. If <code>location</code> is the path to an existing <code>File</code> on the local file system, a * <code>FileInputStream</code> is returned. Otherwise Spring's resource loading framework is used to open an <code>InputStream</code> to <code>location</code>. */ public static final InputStream getInputStream(String location) throws IOException { if (isExistingFile(location)) { return FileUtils.openInputStream(new File(location)); } Resource resource = getResource(location); return resource.getInputStream(); }
protected static String getCanonicalLocation(String location) { if (LocationUtils.isExistingFile(location)) { return LocationUtils.getCanonicalPath(new File(location)); } else { return location; } }
/** * Null safe method for determining if <code>location</code> exists. */ public static final boolean exists(String location) { if (location == null) { return false; } if (isExistingFile(location)) { return true; } else { Resource resource = getResource(location); return resource.exists(); } }
/** * Convert any locations representing an existing file into a fully qualified file system url. Leave any locations that do not resolve to an existing file alone. */ protected List<String> getConvertedLocations(List<String> locations) { List<String> converted = new ArrayList<String>(); for (String location : locations) { if (LocationUtils.isExistingFile(location)) { File file = new File(location); // ClassPathXmlApplicationContext needs a fully qualified URL, not a filename String url = LocationUtils.getCanonicalURLString(file); converted.add(url); } else { converted.add(location); } } return converted; }
public static final String getFilename(String location) { if (location == null) { return null; } if (isExistingFile(location)) { return getFileQuietly(location).getName(); } else { Resource resource = getResource(location); return resource.getFilename(); } }
/** * Convert any locations representing an existing file into a fully qualified file system url. Leave any locations that do not resolve to an existing file alone. */ protected List<String> getConvertedLocations(List<String> locations) { List<String> converted = new ArrayList<String>(); for (String location : locations) { if (LocationUtils.isExistingFile(location)) { File file = new File(location); // ClassPathXmlApplicationContext needs a fully qualified URL, not a filename String url = LocationUtils.getCanonicalURLString(file); converted.add(url); } else { converted.add(location); } } return converted; }
protected static void logCopy(String src, String dst, long elapsed) { String rate = ""; String size = ""; if (LocationUtils.isExistingFile(src)) { long bytes = new File(src).length(); rate = FormatUtils.getRate(elapsed, bytes); size = FormatUtils.getSize(bytes); } Object[] args = { dst, size, FormatUtils.getTime(elapsed), rate }; logger.debug("Source -> [{}]", src); logger.debug(" created [{}] - [{} {} {}]", args); }
/** * Null safe method for determining if <code>location</code> exists. */ public static final boolean exists(File file) { if (file == null) { return false; } String location = getCanonicalPath(file); if (isExistingFile(location)) { return true; } else { Resource resource = getResource(location); return resource.exists(); } }