List of usage examples for java.io File getParent
public String getParent()
null
if this pathname does not name a parent directory. From source file:com.egt.core.db.util.Reporter.java
private static Map getReportParametersMap(File file, String format, Long userid, String usercode, String username) {// w w w.j a va 2 s.co m Bitacora.trace(Reporter.class, "getReportParametersMap", file.getName(), file.getParent(), file.getPath()); Map parameters = new HashMap(); EnumFormatoInforme type = getReportType(format); String sep = System.getProperties().getProperty("file.separator"); parameters.put(JRFillParameter.REPORT_CONNECTION, TLC.getConnection()); parameters.put("ENTERPRISE_APPLICATION_CODE", EAB.ENTERPRISE_APPLICATION_CODE); parameters.put("ENTERPRISE_APPLICATION_NAME", EAB.ENTERPRISE_APPLICATION_NAME); parameters.put("RESOURCES_DIR", file.getParent() + sep + "resources" + sep); parameters.put("SUBREPORTS_DIR", file.getParent() + sep + "subreports" + sep); parameters.put("END_USER_ID", userid); parameters.put("END_USER_CODE", usercode); parameters.put("END_USER_NAME", username); parameters.put("SQL_WHERE_CLAUSE", ""); parameters.put("SQL_LIMIT_CLAUSE", ""); switch (type) { case XLS: parameters.put(JRFillParameter.IS_IGNORE_PAGINATION, Boolean.TRUE); parameters.put(JRFillParameter.REPORT_MAX_COUNT, Integer.valueOf(60000)); break; // case CSV: // parameters.put(JRFillParameter.IS_IGNORE_PAGINATION, Boolean.TRUE); // parameters.put(JRFillParameter.REPORT_MAX_COUNT, null); // break; default: parameters.put(JRFillParameter.IS_IGNORE_PAGINATION, Boolean.FALSE); parameters.put(JRFillParameter.REPORT_MAX_COUNT, null); break; } return parameters; }
From source file:com.feilong.commons.core.io.FileUtil.java
/** * parent.//ww w. ja v a 2s . c o m * * @param pathname * the pathname * @return the parent * @throws NullPointerException * the null pointer exception */ public static String getParent(String pathname) throws NullPointerException { if (Validator.isNullOrEmpty(pathname)) { throw new NullPointerException("pathname can't be null/empty!"); } File file = new File(pathname); String parent = file.getParent(); return parent; }
From source file:mx.itesm.imb.EcoreImbEditor.java
/** * /*from w w w . ja va2 s . c o m*/ * @param ecoreProject */ @SuppressWarnings("unchecked") public static void generateProvidersArtifacts(final File ecoreProject, final File templateProject) { File provider; File imbProject; List<File> imbTypes; Iterator<File> files; List<String> types; String typesPackage; // Get imb types imbProject = new File(ecoreProject.getParent(), ecoreProject.getName() + ".edit"); files = FileUtils.iterateFiles(new File(imbProject, "/src/imb"), new String[] { "java" }, true); imbTypes = new ArrayList<File>(); while (files.hasNext()) { imbTypes.add(files.next()); } // Get providers files files = FileUtils.iterateFiles(imbProject, new IOFileFilter() { @Override public boolean accept(final File file) { return file.getName().endsWith("ItemProvider.java"); } @Override public boolean accept(File directory, String file) { return file.endsWith("ItemProvider.java"); } }, TrueFileFilter.INSTANCE); typesPackage = null; types = new ArrayList<String>(); while (files.hasNext()) { try { provider = files.next(); types.add(provider.getName().replace("ItemProvider.java", "")); typesPackage = provider.getPath() .substring(provider.getPath().indexOf("src") + "src".length() + 1, provider.getPath().indexOf(provider.getName().replace(".java", "")) - 1) .replace('/', '.'); EcoreImbEditor.writeEcoreAspect(provider, imbTypes); EcoreImbEditor.writeEcoreController(imbProject, templateProject, provider, imbTypes); System.out.println("Artifacts for " + provider + " successfully generated"); } catch (Exception e) { e.printStackTrace(); System.out.println("Error generating Artifacts: " + e.getMessage()); } } // Configuration properties file try { FileUtils.copyFile(new File(templateProject, "/templates/configuration-template.properties"), new File(imbProject, "/src/mx/itesm/imb/configuration.properties")); FileUtils.copyFile(new File(templateProject, "/templates/configuration-template.properties"), new File(ecoreProject.getParent(), ecoreProject.getName() + ".editor/src/mx/itesm/imb/configuration.properties")); } catch (IOException e) { System.out.println("Unable to generate configuration properties file: " + e.getMessage()); } // Selection aspect typesPackage = typesPackage.replace(".provider", ""); EcoreImbEditor.writeSelectionAspect(ecoreProject, typesPackage, types); }
From source file:com.feilong.commons.core.io.FileUtil.java
/** * ??/*from ww w . j av a 2 s .c o m*/ * * <pre> * {@code * Example 1: * "mp2-product\\mp2-product-impl\\src\\main\\java\\com\\baozun\\mp2\\rpc\\impl\\item\\repo\\package-info.java" * * mp2-product * } * </pre> * * @param pathname * ?????? File .??. * @return ,, E:/ E:/ * @throws NullPointerException * isNullOrEmpty(fileName) * * @since 1.0.7 */ public static final String getFileTopParentName(String pathname) throws NullPointerException { if (Validator.isNullOrEmpty(pathname)) { throw new NullPointerException("pathname can't be null/empty!"); } File file = new File(pathname); String parent = file.getParent(); if (Validator.isNullOrEmpty(parent)) { return pathname; } // String fileTopParentName = getFileTopParentName(file); if (log.isDebugEnabled()) { log.debug("pathname:[{}],fileTopParentName:[{}]", pathname, fileTopParentName); } return fileTopParentName; }
From source file:com.khepry.utilities.GenericUtilities.java
public static void generateOutFile(String outFilePath, String outputText, Handler handler) { Logger.getLogger("").addHandler(handler); File outFile = new File(outFilePath); if (outFile.getParentFile().exists()) { try {// ww w. j av a 2s.c o m BufferedWriter bw = new BufferedWriter(new FileWriter(outFilePath)); bw.write(outputText); bw.close(); } catch (IOException ex) { Logger.getLogger(GenericUtilities.class.getName()).log(Level.SEVERE, null, ex); } } else { Logger.getLogger(GenericUtilities.class.getName()).log(Level.SEVERE, "Output path: " + outFile.getParent() + " does not exist!", new FileNotFoundException()); } }
From source file:com.jcalvopinam.core.Zipping.java
private static void splitAndZipFile(File inputFile, int bufferSize, CustomFile customFile) throws IOException { int counter = 1; byte[] bufferPart; byte[] buffer = new byte[bufferSize]; File newFile;/*from w w w . j a v a 2 s . co m*/ FileInputStream fileInputStream; ZipOutputStream out; String temporalName; String outputFileName; try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(inputFile))) { int tmp; System.out.println("Please wait while the file is split:"); while ((tmp = bis.read(buffer)) > 0) { temporalName = String.format("%s.%03d", customFile.getFileName(), counter); newFile = new File(inputFile.getParent(), temporalName); try (FileOutputStream fileOutputStream = new FileOutputStream(newFile)) { fileOutputStream.write(buffer, 0, tmp); } fileInputStream = new FileInputStream(newFile);//file001.zip outputFileName = String.format("%s%s_%03d%s", customFile.getPath(), customFile.getFileName(), counter, Extensions.ZIP.getExtension()); out = new ZipOutputStream(new FileOutputStream(outputFileName)); out.putNextEntry(new ZipEntry(customFile.getFileNameExtension())); bufferPart = new byte[CustomFile.BYTE_SIZE]; int count; while ((count = fileInputStream.read(bufferPart)) > 0) { out.write(bufferPart, 0, count); System.out.print("."); } counter++; fileInputStream.close(); out.close(); FileUtils.deleteQuietly(newFile); } } System.out.println("\nEnded process!"); }
From source file:com.runwaysdk.business.generation.maven.MavenClasspathBuilder.java
public static MavenProject loadProject(File pomFile) throws IOException, XmlPullParserException { MavenProject ret = null;/*from w w w . java2 s. co m*/ MavenXpp3Reader mavenReader = new MavenXpp3Reader(); if (pomFile != null && pomFile.exists()) { FileReader reader = null; try { reader = new FileReader(pomFile); Model model = mavenReader.read(reader); model.setPomFile(pomFile); List<Repository> repositories = model.getRepositories(); Properties properties = model.getProperties(); properties.setProperty("basedir", pomFile.getParent()); Parent parent = model.getParent(); if (parent != null) { File parentPom = new File(pomFile.getParent(), parent.getRelativePath()); MavenProject parentProj = loadProject(parentPom); if (parentProj == null) { throw new CoreException("Unable to load parent project at " + parentPom.getAbsolutePath()); } repositories.addAll(parentProj.getRepositories()); model.setRepositories(repositories); properties.putAll(parentProj.getProperties()); } ret = new MavenProject(model); } finally { reader.close(); } } return ret; }
From source file:FileUtil.java
public static void copyFile(String from, String to, Boolean overwrite) { try {/*from ww w . j a v a 2s. co m*/ File fromFile = new File(from); File toFile = new File(to); if (!fromFile.exists()) { throw new IOException("File not found: " + from); } if (!fromFile.isFile()) { throw new IOException("Can't copy directories: " + from); } if (!fromFile.canRead()) { throw new IOException("Can't read file: " + from); } if (toFile.isDirectory()) { toFile = new File(toFile, fromFile.getName()); } if (toFile.exists() && !overwrite) { throw new IOException("File already exists."); } else { String parent = toFile.getParent(); if (parent == null) { parent = System.getProperty("user.dir"); } File dir = new File(parent); if (!dir.exists()) { throw new IOException("Destination directory does not exist: " + parent); } if (dir.isFile()) { throw new IOException("Destination is not a valid directory: " + parent); } if (!dir.canWrite()) { throw new IOException("Can't write on destination: " + parent); } } FileInputStream fis = null; FileOutputStream fos = null; try { fis = new FileInputStream(fromFile); fos = new FileOutputStream(toFile); byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = fis.read(buffer)) != -1) { fos.write(buffer, 0, bytesRead); } } finally { if (from != null) { try { fis.close(); } catch (IOException e) { System.out.println(e); } } if (to != null) { try { fos.close(); } catch (IOException e) { System.out.println(e); } } } } catch (Exception e) { System.out.println("Problems when copying file."); } }
From source file:com.parse.ParseFileUtils.java
/** * Determines whether the specified file is a Symbolic Link rather than an actual file. * <p>/*w ww . j av a 2 s . c om*/ * Will not return true if there is a Symbolic Link anywhere in the path, * only if the specific file is. * <p> * <b>Note:</b> the current implementation always returns {@code false} if the system * is detected as Windows using {@link FilenameUtils#isSystemWindows()} * <p> * For code that runs on Java 1.7 or later, use the following method instead: * <br> * {@code boolean java.nio.file.Files.isSymbolicLink(Path path)} * @param file the file to check * @return true if the file is a Symbolic Link * @throws IOException if an IO error occurs while checking the file * @since 2.0 */ public static boolean isSymlink(final File file) throws IOException { if (file == null) { throw new NullPointerException("File must not be null"); } // if (FilenameUtils.isSystemWindows()) { // return false; // } File fileInCanonicalDir = null; if (file.getParent() == null) { fileInCanonicalDir = file; } else { final File canonicalDir = file.getParentFile().getCanonicalFile(); fileInCanonicalDir = new File(canonicalDir, file.getName()); } if (fileInCanonicalDir.getCanonicalFile().equals(fileInCanonicalDir.getAbsoluteFile())) { return false; } else { return true; } }
From source file:ips1ap101.lib.core.db.util.Reporter.java
private static Map getReportParametersMap(File file, String format, Long userid, String usercode, String username, Locale locale) { Bitacora.trace(Reporter.class, "getReportParametersMap", file.getName(), file.getParent(), file.getPath()); Map parameters = new HashMap(); EnumFormatoInforme type = getReportType(format); String sep = System.getProperties().getProperty("file.separator"); String parent = getParent(file, userid); parameters.put(JRParameter.REPORT_LOCALE, locale == null ? Locale.getDefault() : locale); parameters.put(JRFillParameter.REPORT_CONNECTION, TLC.getConnection()); parameters.put("ENTERPRISE_APPLICATION_CODE", EAB.ENTERPRISE_APPLICATION_CODE); parameters.put("ENTERPRISE_APPLICATION_NAME", BundleWebui.getString(EAB.ENTERPRISE_APPLICATION_CODE)); parameters.put("RESOURCES_DIR", parent + sep + "resources" + sep); parameters.put("SUBREPORTS_DIR", parent + sep + "subreports" + sep); parameters.put("END_USER_ID", userid); parameters.put("END_USER_CODE", usercode); parameters.put("END_USER_NAME", username); parameters.put("SQL_SELECT_STATEMENT", ""); parameters.put("SQL_WHERE_CLAUSE", ""); parameters.put("SQL_LIMIT_CLAUSE", ""); switch (type) { case XLS:/*from w w w . ja v a 2 s . c o m*/ parameters.put(JRFillParameter.IS_IGNORE_PAGINATION, Boolean.TRUE); parameters.put(JRFillParameter.REPORT_MAX_COUNT, Integer.valueOf(60000)); break; // case CSV: // parameters.put(JRFillParameter.IS_IGNORE_PAGINATION, Boolean.TRUE); // parameters.put(JRFillParameter.REPORT_MAX_COUNT, null); // break; default: parameters.put(JRFillParameter.IS_IGNORE_PAGINATION, Boolean.FALSE); parameters.put(JRFillParameter.REPORT_MAX_COUNT, null); break; } return parameters; }