/** * 对一个图像进行旋转 * * @param srcPath * 原图像文件路径 * @param taPath * 转换后的图像文件路径 * @param degree * 旋转角度, 90 为顺时针九十度, -90 为逆时针九十度 * @return 旋转后得图像对象 */ public static BufferedImage rotate(String srcPath, String taPath, int degree) throws IOException { File srcIm = Files.findFile(srcPath); if (null == srcIm) throw Lang.makeThrow("Fail to find image file '%s'!", srcPath); File taIm = Files.createFileIfNoExists(taPath); return rotate(srcIm, taIm, degree); }
public UU32FilePool(String path) { this.root = Files.createDirIfNoExists(path); }
/** * @see #getSuffixName(String) */ public static String getSuffixName(File f) { if (null == f) return null; return getSuffixName(f.getAbsolutePath()); }
public void clear() { Files.deleteDir(root); this.root = Files.createDirIfNoExists(root); }
@Override public File cast(String src, Class<?> toType, String... args) throws FailToCastObjectException { return Files.findFile(src); }
/** * 将内容写到一个文件内,内容对象可以是: * <ul> * <li>InputStream - 按二进制方式写入 * <li>byte[] - 按二进制方式写入 * <li>Reader - 按 UTF-8 方式写入 * <li>其他对象被 toString() 后按照 UTF-8 方式写入 * </ul> * * @param path * 文件路径,如果不存在,则创建 * @param obj * 内容对象 */ public static void write(String path, Object obj) { if (null == path || null == obj) return; try { write(Files.createFileIfNoExists(path), obj); } catch (IOException e) { throw Lang.wrapThrow(e); } }
public void truncate(long len) throws SQLException { Files.write(file, new Byte[]{}); }
/** * 根据一个文件路径建立一个输入流 * * @param path * 文件路径 * @return 输入流 */ public static InputStream fileIn(String path) { InputStream ins = Files.findFileAsStream(path); if (null == ins) { File f = Files.findFile(path); if (null != f) try { ins = Streams._input(f); } catch (IOException e) {} } if (null == ins) { // TODO 考虑一下,应该抛异常呢?还是返回null呢? throw new RuntimeException(new FileNotFoundException(path)); // return null; } return buff(ins); }
public File removeDir(long fId) { File f = Pools.getFileById(home, fId, null); if (f.isDirectory()) { Files.deleteDir(f); } else { Files.deleteFile(f); } return f; }
/** * 将文件后缀改名,从而生成一个新的文件对象。但是并不在磁盘上创建它 * * @param f * 文件 * @param suffix * 新后缀, 比如 ".gif" 或者 ".jpg" * @return 新文件对象 */ public static File renameSuffix(File f, String suffix) { if (null == f || null == suffix || suffix.length() == 0) return f; return new File(renameSuffix(f.getAbsolutePath(), suffix)); }
public void clear() { key = null; File f = Files.findFile(god_key_file_my); if (null != f) Files.deleteFile(f); }
public static File createFileIfNoExists2(String path) { try { return createFileIfNoExists(path); } catch (IOException e) { throw Lang.wrapThrow(e); } }
public void free() throws SQLException { Files.deleteFile(file); }
/** * 获取输出流 * * @param path * 文件路径 * @param enc * 文件路径编码 * * @return 输出流 */ public static InputStream findFileAsStream(String path, String enc) { return findFileAsStream(path, Files.class, enc); }
/** * 将一个目录下的特殊名称的目录彻底删除,比如 '.svn' 或者 '.cvs' * * @param dir * 目录 * @param name * 要清除的目录名 * @throws IOException */ public static void cleanAllFolderInSubFolderes(File dir, String name) throws IOException { File[] files = dir.listFiles(); if (files == null) return; for (File d : files) { if (d.isDirectory()) if (d.getName().equalsIgnoreCase(name)) deleteDir(d); else cleanAllFolderInSubFolderes(d, name); } }
byte[] data = Files.readBytes(mf); if (data[0] == '{') { // 看上去是个json,悲催了...
private String doScan() { final StringBuilder sb = new StringBuilder(); final HashMap<String, Boolean> paths = new HashMap<String, Boolean>(); File home = Files.createDirIfNoExists(rsHome); Context context = Lang.context(); context.set(Webs.RS, rs); File theF = Files.getFile(home, path);