List of usage examples for java.io File getAbsoluteFile
public File getAbsoluteFile()
From source file:br.edimarmanica.trinity.check.CheckAttributeNotFound.java
private void readOffSets() { /**/* ww w. j a v a 2 s. com*/ * Lendos os Run02.NR_SHARED_PAGES primeiros elementos de cada offset */ File dir = new File(Paths.PATH_TRINITY + site.getPath() + "/offset"); for (int nrOffset = 0; nrOffset < dir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".csv"); } }).length; nrOffset++) { List<Map<String, String>> offset = new ArrayList<>(); //cada arquivo um offset try (Reader in = new FileReader(dir.getAbsoluteFile() + "/result_" + nrOffset + ".csv")) { try (CSVParser parser = new CSVParser(in, CSVFormat.EXCEL)) { int nrRegistro = 0; for (CSVRecord record : parser) { for (int nrRegra = 0; nrRegra < record.size(); nrRegra++) { String value; try { value = formatValue(Preprocessing.filter(record.get(nrRegra))); } catch (InvalidValue ex) { value = ""; } if (nrRegistro == 0) { Map<String, String> regra = new HashMap<>(); regra.put(record.get(0), value); offset.add(regra); } else { offset.get(nrRegra).put(record.get(0), value); } } nrRegistro++; } } offsets.add(offset); } catch (FileNotFoundException ex) { Logger.getLogger(CheckAttributeNotFound.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(CheckAttributeNotFound.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:core.AnnotationTask.java
public void setupVisualization() { copyFolder("./data/visualization", outputDir); File file = new File(outputDir + "/file_list.js"); try {/* w w w . j av a2s. c o m*/ // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write("var files=[\n"); String prefixName = ""; for (String fileName : files) { prefixName = FilenameUtils.getBaseName(fileName); bw.write("\"/" + Utils.getOutDir(Utils.OutDirIndex.ORIGINAL) + "/" + prefixName + ".tsv\",\n"); } bw.write("];"); bw.close(); } catch (IOException e) { e.printStackTrace(); } System.out.println("Done creating filelist"); }
From source file:net.lmxm.ute.utils.FileSystemUtils.java
/** * Creates the directory.// ww w . j a v a2s . c o m * * @param path the path * @return the file */ public File createDirectory(final String path) { final String prefix = "createDirectory() :"; LOGGER.debug("{} entered", prefix); checkArgument(StringUtils.isNotBlank(path), "Path may not be blank or null"); final File directory = new File(path); if (directory.exists()) { LOGGER.debug("{} directory already exists", prefix); } else { if (directory.mkdirs()) { LOGGER.debug("{} successfully created directory", prefix); } else { LOGGER.debug("{} failed to create directory", prefix); throw new TaskExecuterException(ExceptionResourceType.DIRECTORY_ALREADY_EXISTS, directory.getAbsoluteFile()); } } LOGGER.debug("{} returning {}", prefix, directory); return directory; }
From source file:de.smartics.maven.plugin.jboss.modules.index.Indexer.java
/** * Writes the index.//w w w . j a va2s . c om * * @throws MojoExecutionException on any problem writing the file. */ public void writeIndex() throws MojoExecutionException { final File indexFile = new File(outputDirectory, "META-INF/INDEX.LIST"); indexFile.getParentFile().mkdirs(); PrintWriter writer = null; try { writer = new PrintWriter(new OutputStreamWriter(FileUtils.openOutputStream(indexFile), "UTF-8")); for (final String fileName : fileNames) { writer.append(fileName).append('\n'); } } catch (final IOException e) { throw new MojoExecutionException( String.format("Cannot write index file '%s'.", indexFile.getAbsoluteFile()), e); } finally { IOUtils.closeQuietly(writer); } }
From source file:com.thoughtworks.go.config.GoRepoConfigDataSourceIntegrationTest.java
private String setupExternalConfigRepo(File configRepo, String configRepoTestResource) throws IOException { ClassPathResource resource = new ClassPathResource(configRepoTestResource); FileUtils.copyDirectory(resource.getFile(), configRepo); CommandLine.createCommandLine("git").withEncoding("utf-8").withArg("init") .withArg(configRepo.getAbsolutePath()).runOrBomb(null); CommandLine.createCommandLine("git").withEncoding("utf-8").withArgs("config", "commit.gpgSign", "false") .withWorkingDir(configRepo.getAbsoluteFile()).runOrBomb(null); gitAddDotAndCommit(configRepo);/*from www . j a v a2 s .com*/ ConsoleResult consoleResult = CommandLine.createCommandLine("git").withEncoding("utf-8").withArg("log") .withArg("-1").withArg("--pretty=format:%h").withWorkingDir(configRepo).runOrBomb(null); return consoleResult.outputAsString(); }
From source file:br.edimarmanica.trinity.intrasitemapping.auto.MappingController.java
private void reading() { /**/*from ww w . j a v a2s . co m*/ * Lendos os Run02.NR_SHARED_PAGES primeiros elementos de cada offset */ File dir = new File(Paths.PATH_TRINITY + site.getPath() + "/offset"); for (int nrOffset = 0; nrOffset < dir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".csv"); } }).length; nrOffset++) { List<List<String>> offset = new ArrayList<>(); //cada arquivo um offset try (Reader in = new FileReader(dir.getAbsoluteFile() + "/result_" + nrOffset + ".csv")) { try (CSVParser parser = new CSVParser(in, CSVFormat.EXCEL)) { int nrRegistro = 0; for (CSVRecord record : parser) { if (nrRegistro >= Extract.NR_SHARED_PAGES) { break; } for (int nrRegra = 0; nrRegra < record.size(); nrRegra++) { if (nrRegistro == 0) { List<String> regra = new ArrayList<>(); try { regra.add(Preprocessing.filter(record.get(nrRegra))); } catch (InvalidValue ex) { regra.add(""); } offset.add(regra); } else { try { offset.get(nrRegra).add(Preprocessing.filter(record.get(nrRegra))); } catch (InvalidValue ex) { offset.get(nrRegra).add(""); } } } nrRegistro++; } } offsets.add(offset); } catch (FileNotFoundException ex) { Logger.getLogger(MappingController.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(MappingController.class.getName()).log(Level.SEVERE, null, ex); } } /** * Mostrando a leitura */ /*for (int i = 1; i < offsets.size(); i++) { for (int j = 0; j < 5; j++) { System.out.print(offsets.get(i).get(0).get(j) + " - "); } System.out.println(""); }*/ }
From source file:com.tobedevoured.solrsail.SolrConfig.java
/** * Install Solr Config t the local file system by extracting from the * SolrSail jar//from www . j av a 2 s. c o m * * @param jar File * @throws IOException */ public void installFromJar(File jar) throws IOException { logger.info("Installing config from Jar to {}", this.getSolrHome()); logger.debug("Opening Jar {}", jar.toString()); JarFile jarFile = new JarFile(jar); for (Enumeration<JarEntry> enumeration = jarFile.entries(); enumeration.hasMoreElements();) { JarEntry entry = enumeration.nextElement(); if (!entry.getName().equals("solr/") && entry.getName().startsWith("solr/")) { StringBuilder dest = new StringBuilder(getSolrHome()).append(File.separator) .append(entry.getName().replaceFirst("solr/", "")); File file = new File(dest.toString()); if (entry.isDirectory()) { file.mkdirs(); } else { if (file.getParentFile() != null) { file.getParentFile().mkdirs(); } logger.debug("Copying {} to {}", entry.getName(), dest.toString()); InputStream input = jarFile.getInputStream(entry); Writer writer = new FileWriter(file.getAbsoluteFile()); IOUtils.copy(input, writer); input.close(); writer.close(); } } } }
From source file:com.github.riccardove.easyjasub.EasyJaSubInputFromCommand.java
private static File getOutputBdnFile(EasyJaSubInputCommand command, File outputIdxFile, DefaultFileList defaultFileList) throws EasyJaSubException { String fileName = command.getOutputBdnFileName(); if (isDisabled(fileName)) { return null; }/*from w ww . j a v a2s .c o m*/ File file = null; File directory = null; String fileNameBase = null; if (fileName != null && !isDefault(fileName)) { file = new File(fileName); } else { fileNameBase = defaultFileList.getDefaultFileNamePrefix(); String directoryName = command.getOutputBdnDirectory(); if (directoryName != null) { directory = new File(directoryName); } else if (outputIdxFile != null) { directory = new File(outputIdxFile.getAbsoluteFile().getParentFile(), fileNameBase + "_easyjasub"); } else { directory = defaultFileList.getDefaultDirectory(); } file = new File(directory, fileNameBase + ".xml"); fileName = file.getAbsolutePath(); } checkOutputFile(fileName, file); return file; }
From source file:com.elevenpaths.googleindexretriever.GoogleSearch.java
public void saveKeywords() throws IOException { File file = new File("keywords.txt"); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile();/*from ww w . j av a 2s . c om*/ } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); for (String k : keywords) { bw.write(k); bw.newLine(); } bw.close(); fw.close(); }
From source file:com.frostwire.android.gui.adapters.menu.FileListAdapter.java
private boolean checkIfNotExists(FileDescriptor fd) { if (fd == null || fd.filePath == null) { return true; }/*from w ww.j a va 2 s. co m*/ File f = new File(fd.filePath); if (!f.exists()) { if (SystemUtils.isSecondaryExternalStorageMounted(f.getAbsoluteFile())) { UIUtils.showShortMessage(getContext(), R.string.file_descriptor_sd_mounted); Librarian.instance().deleteFiles(fileType, Arrays.asList(fd), getContext()); deleteItem(fd); } else { UIUtils.showShortMessage(getContext(), R.string.file_descriptor_sd_unmounted); } return true; } else { return false; } }