List of usage examples for java.io File getPath
public String getPath()
From source file:Main.java
static String composeFilesString(final String dirPath, final List<String> subDirPaths, final String pattern, int skip) { final StringBuilder sb = new StringBuilder(); final List<File> allFiles = new ArrayList<>(); final FilenameFilter filter = new FilenameFilter() { @Override//www . j ava2 s.co m public boolean accept(File dir, String name) { return name.matches(pattern); } }; for (final String subDirPath : subDirPaths) { final File subDir = new File(dirPath, subDirPath); final File[] files = subDir.listFiles(filter); if (files == null) { throw new RuntimeException(String.format("%s directory does not exist", subDir.getPath())); } Arrays.sort(files); Collections.addAll(allFiles, files); } final int m; final int n; if (skip >= 0) { m = skip; n = allFiles.size(); } else { m = 0; n = allFiles.size() + skip; } for (int i = m; i < n; i++) { final File file = allFiles.get(i); if (sb.length() > 0) { sb.append(' '); } sb.append(file.getPath()); } return sb.toString(); }
From source file:ips1ap101.lib.core.db.util.SqlAgent.java
public static Process executeProcedure(String procedimiento, long funcion, Object[] args) { Bitacora.trace(SqlAgent.class, "executeProcedure", procedimiento, String.valueOf(funcion)); Utils.traceObjectArray(args);/* w w w. j a va 2 s . c om*/ Long rastro = null; Process process = null; try { procedimiento = StringUtils.trimToEmpty(procedimiento); if (STP.esIdentificadorArchivoValido(procedimiento)) { if (TLC.getControlador().esFuncionAutorizada(funcion)) { rastro = TLC.getControlador().ponerProcesoPendiente(funcion); String path = Utils.sep(EA.getString(EAC.SQLPRC_RUNNER_DIR)); String command = path + EA.getString(EAC.SQLPRC_RUNNER_CMD); command += " " + commandParameters(procedimiento, funcion, rastro, args); String[] envp = null; File dir = new File(path); Bitacora.trace(command); Bitacora.trace(dir.getPath()); process = Runtime.getRuntime().exec(command, envp, dir); TLC.getBitacora().info(CBM.PROCESS_EXECUTION_REQUEST, procedimiento); } else { throw new ExcepcionAplicacion( Bitacora.getTextoMensaje(CBM.FUNCION_NO_AUTORIZADA, procedimiento)); } } else { throw new ExcepcionAplicacion( Bitacora.getTextoMensaje(CBM.IDENTIFICADOR_ARCHIVO_INVALIDO, procedimiento)); } } catch (Exception ex) { CondicionEjeFunEnumeration condicion = CondicionEjeFunEnumeration.EJECUCION_CANCELADA; String mensaje = ThrowableUtils.getString(ex); Auditor.grabarRastroProceso(rastro, condicion, null, mensaje); TLC.getBitacora().error(mensaje); } return process; }
From source file:com.fjn.helper.common.io.file.common.FileUtil.java
public static File ensureChildDirExists(String parentDir, String childDir) { File parent = ensureDirExists(parentDir); String child = parent.getPath() + File.separator + childDir; File file = ensureDirExists(child); return file;/*from w w w . j a va 2s .co m*/ }
From source file:com.spidasoftware.EclipseFormatter.Formatter.java
/** * Format by using the first line of the file. * * @param file File that will be formatted * @param cmd the list of command line arguments. * @return a String that represents the name of the backup file created, null otherwise. *//* w w w . j a v a 2 s .c o m*/ public static String formatUsingHashBang(File file, CommandLine cmd) { String fileName = file.getPath(); String nameWithDate = null; String code = readInFile(fileName); if (code.indexOf("\n") > -1) { String firstLine = code.substring(0, code.indexOf("\n")); if (firstLine.indexOf("#!/usr/bin/env groovy") > -1 && groovyFormatting(cmd)) { GroovyFormat groovyFormatter = new GroovyFormat(); groovyFormatter.format(fileName, code); if (groovyFormatter.isFormatted() && cmd.hasOption("b")) nameWithDate = createBackupFile(fileName, code); } } return nameWithDate; }
From source file:Main.java
public static String savetoJPEG(byte[] data, int width, int height, String file) { Rect frame = new Rect(0, 0, width, height); YuvImage img = new YuvImage(data, ImageFormat.NV21, width, height, null); OutputStream os = null;//from w w w .ja v a2 s.c om File jpgfile = new File(file); try { os = new FileOutputStream(jpgfile); img.compressToJpeg(frame, 100, os); os.flush(); os.close(); } catch (Exception e) { e.printStackTrace(); } return jpgfile.getPath(); }
From source file:info.magnolia.cms.util.ClasspathResourcesUtil.java
/** * Load resources from jars or directories * * @param resources found resources will be added to this collection * @param jarOrDir a File, can be a jar or a directory * @param filter used to filter resources *///w w w.j a v a2s. c om private static void collectFiles(Collection resources, File jarOrDir, Filter filter) { if (!jarOrDir.exists()) { log.warn("missing file: {}", jarOrDir.getAbsolutePath()); return; } if (jarOrDir.isDirectory()) { if (log.isDebugEnabled()) log.debug("looking in dir {}", jarOrDir.getAbsolutePath()); Collection files = FileUtils.listFiles(jarOrDir, new TrueFileFilter() { }, new TrueFileFilter() { }); for (Iterator iter = files.iterator(); iter.hasNext();) { File file = (File) iter.next(); String name = StringUtils.substringAfter(file.getPath(), jarOrDir.getPath()); // please, be kind to Windows!!! name = StringUtils.replace(name, "\\", "/"); if (!name.startsWith("/")) { name = "/" + name; } if (filter.accept(name)) { resources.add(name); } } } else if (jarOrDir.getName().endsWith(".jar")) { if (log.isDebugEnabled()) log.debug("looking in jar {}", jarOrDir.getAbsolutePath()); JarFile jar; try { jar = new JarFile(jarOrDir); } catch (IOException e) { log.error("IOException opening file {}, skipping", jarOrDir.getAbsolutePath()); return; } for (Enumeration em = jar.entries(); em.hasMoreElements();) { JarEntry entry = (JarEntry) em.nextElement(); if (!entry.isDirectory()) { if (filter.accept("/" + entry.getName())) { resources.add("/" + entry.getName()); } } } } else { if (log.isDebugEnabled()) log.debug("Unknown (not jar) file in classpath: {}, skipping.", jarOrDir.getName()); } }
From source file:Main.java
public static void reNameSuffix(File dir, String oldSuffix, String newSuffix) { if (dir.isDirectory()) { File[] listFiles = dir.listFiles(); for (int i = 0; i < listFiles.length; i++) { reNameSuffix(listFiles[i], oldSuffix, newSuffix); }/* w ww. ja v a 2s. co m*/ } else { dir.renameTo(new File(dir.getPath().replace(oldSuffix, newSuffix))); } }
From source file:Main.java
/** * Zips a subfolder//from w w w . j a v a 2 s .co m */ protected static void zipSubFolder(ZipOutputStream zipOut, File srcFolder, int basePathLength) throws IOException { final int BUFFER = 2048; File[] fileList = srcFolder.listFiles(); BufferedInputStream bis = null; for (File file : fileList) { if (file.isDirectory()) { zipSubFolder(zipOut, file, basePathLength); } else { byte data[] = new byte[BUFFER]; String unmodifiedFilePath = file.getPath(); String relativePath = unmodifiedFilePath.substring(basePathLength); Log.d("ZIP SUBFOLDER", "Relative Path : " + relativePath); FileInputStream fis = new FileInputStream(unmodifiedFilePath); bis = new BufferedInputStream(fis, BUFFER); ZipEntry zipEntry = new ZipEntry(relativePath); zipOut.putNextEntry(zipEntry); int count; while ((count = bis.read(data, 0, BUFFER)) != -1) { zipOut.write(data, 0, count); } bis.close(); } } }
From source file:org.jamwiki.utils.ImageUtil.java
/** * Given a file that corresponds to an existing image, return a * BufferedImage object./*from w ww . ja va 2 s. c om*/ */ private static BufferedImage loadImage(File file) throws Exception { BufferedImage image = null; String key = file.getPath(); Element cacheElement = WikiCache.retrieveFromCache(CACHE_IMAGES, key); if (cacheElement != null) { return (BufferedImage) cacheElement.getObjectValue(); } FileInputStream fis = null; try { fis = new FileInputStream(file); image = ImageIO.read(fis); WikiCache.addToCache(CACHE_IMAGES, key, image); return image; } finally { if (fis != null) { try { fis.close(); } catch (Exception e) { } } } }
From source file:com.lidroid.util.OtherUtils.java
public static long getAvailableSpace(File dir) { try {/*from ww w . j ava 2 s .com*/ final StatFs stats = new StatFs(dir.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); } catch (Throwable e) { Logger.e(e.getMessage(), e); return -1; } }