List of usage examples for java.io File getCanonicalPath
public String getCanonicalPath() throws IOException
From source file:com.canoo.webtest.util.FileUtil.java
/** * Writes a String to a file.//from w ww. j a va 2s. c o m * * @param file * @param content * @param step * @throws StepExecutionException if something goes wrong */ public static void writeStringToFile(final File file, final String content, final Step step) { String canonicalPath = null; FileOutputStream outputStream = null; try { canonicalPath = file.getCanonicalPath(); outputStream = new FileOutputStream(file); IOUtils.write(content, outputStream); } catch (IOException e) { throw new StepExecutionException("Could not find/write \"" + canonicalPath + "\".", step); } finally { IOUtils.closeQuietly(outputStream); } }
From source file:net.menthor.editor.v2.util.Util.java
/** Returns the canonical absolute path for a file. * If an IO error occurred, or if the file doesn't exist yet, * we will at least return a non-canonical but absolute path for it. * <p> Note: if filename=="", we return "". *//*from w w w . j a va2 s . com*/ public static final String canon(String filename) { if (filename == null || filename.length() == 0) return ""; if (filename.startsWith(jarPrefix())) { char sep = File.separatorChar, other = (sep == '/' ? '\\' : '/'); return filename.replace(other, sep); } File file = new File(filename); try { return file.getCanonicalPath(); } catch (IOException ex) { return file.getAbsolutePath(); } }
From source file:com.canoo.webtest.util.FileUtil.java
/** * Reads a file into a String.// w w w .ja va 2s . c om * * @param file * @param step * @return the resulting String */ public static String readFileToString(final File file, final Step step) { String canonicalPath = null; String result = null; InputStream inputStream = null; try { canonicalPath = file.getCanonicalPath(); inputStream = new FileInputStream(file); result = IOUtils.toString(inputStream); } catch (IOException e) { throw new StepExecutionException("Could not find/read \"" + canonicalPath + "\".", step); } finally { IOUtils.closeQuietly(inputStream); } return result; }
From source file:com.canoo.webtest.util.FileUtil.java
/** * Reads a file into a byte[]./*from w w w . j a va 2 s . co m*/ * * @param file * @param step * @return the resulting byte[] */ public static byte[] readFileToByteArray(final File file, final Step step) { String canonicalPath = null; byte[] result = null; InputStream inputStream = null; try { canonicalPath = file.getCanonicalPath(); inputStream = new FileInputStream(file); result = IOUtils.toByteArray(inputStream); } catch (IOException e) { throw new StepExecutionException("Could not find/read \"" + canonicalPath + "\".", step); } finally { IOUtils.closeQuietly(inputStream); } return result; }
From source file:com.mgmtp.perfload.perfalyzer.util.IoUtilities.java
/** * Normalizes the specified file using {@link FilenameUtils#normalize(String)}. If {@code file} * is a directory, the normalized result always ends with the file separator. * * @param file/*from w w w .ja va2 s .c o m*/ * the file to normalize * @return the normalized file path */ public static String computeNormalizedPath(final File file) throws IOException { String normalizedPath = normalize(file.getCanonicalPath()); if (file.isDirectory()) { normalizedPath = ensureEndsWithFileSeparator(normalizedPath); } return normalizedPath; }
From source file:com.sap.dirigible.ide.workspace.wizard.project.create.ProjectTemplateType.java
private static Image createImageFromStream(File project, String imageName) throws IOException, FileNotFoundException { Image image;//w w w .j a v a 2s .c o m String imgPath = project.getCanonicalPath() + SEPARATOR + imageName; File imgFile = new File(imgPath); byte[] imgContent = IOUtils.toByteArray(new FileInputStream(imgFile)); image = createImage(imgContent); return image; }
From source file:edu.kit.dama.util.ZipUtils.java
/** * Write all files located in pDirectory into a zip file specified by * pZipOut. All entries within the zip file will be structured relative to * pDirectory.//from w w w . j a va 2 s . com * * @param pDirectory The directory containing the input files * @param pZipOut The zip output file * @throws IOException If something goes wrong, in most cases if there are * problems with reading the input files or writing into the output file */ public static void zip(File pDirectory, File pZipOut) throws IOException { zip(pDirectory, pDirectory.getCanonicalPath(), pZipOut); }
From source file:eu.eubrazilcc.lvl.service.io.DatasetWriter.java
private static File writeGbXmlSequence(final File inFile, final File outDir, final String compression) throws IOException { final File outFile = new File(outDir, getName(inFile.getCanonicalPath())); String outFilename = outFile.getCanonicalPath(); LOGGER.trace(/*w ww .j a v a2 s . c om*/ "Writing NCBI sequence from '" + inFile.getCanonicalPath() + "' to '" + outFile.getCanonicalPath()); outFile.getParentFile().mkdirs(); try (final FileInputStream fin = new FileInputStream(inFile); final FileOutputStream fos = new FileOutputStream(outFile)) { copy(fin, fos); } if (compression.equals(GZIP)) { outFilename = gzip(outFile.getCanonicalPath()); outFile.delete(); } return new File(outFilename); }
From source file:Main.java
public static Set<String> compareXmlFiles(String firstFolderPath, String secondFolderPath, boolean outConsole) { Set<String> identicalFiles = new HashSet<String>(); File firstFolder = new File(firstFolderPath); File secondFolder = new File(secondFolderPath); Map<String, File> firstFileMap = new HashMap<String, File>(); Map<String, File> secondFileMap = new HashMap<String, File>(); traverseFolder(firstFileMap, firstFolder, firstFolder); traverseFolder(secondFileMap, secondFolder, secondFolder); // temporarily - comparison by MD5 instead of XML parsing SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = null;/* www . j a v a 2s . c o m*/ try { saxParser = factory.newSAXParser(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } System.out.println("Parser: " + saxParser); Set<String> sourceKeys = firstFileMap.keySet(); Set<String> destKeys = secondFileMap.keySet(); for (String key1 : sourceKeys) { File file1 = firstFileMap.get(key1); File file2 = secondFileMap.get(key1); if (file1 != null && file2 != null) { try { String node1 = calculateMd5Checksum(file1.getCanonicalPath()); String node2 = calculateMd5Checksum(file2.getCanonicalPath()); // System.out.println("Source:" + node1 + " Dest:" + node2); if (node1.equals(node2)) { firstFileMap.remove(key1); secondFileMap.remove(key1); } } catch (Exception ex) { ex.printStackTrace(); // can be ignored } } } for (String key1 : sourceKeys) { if (destKeys.contains(key1)) { identicalFiles.add(key1); sourceKeys.remove(key1); destKeys.remove(key1); } } if (outConsole == true) { } return identicalFiles; }
From source file:eu.eubrazilcc.lvl.service.io.DatasetWriter.java
private static File writeFastaSequences(final List<File> files, final File outDir, final String compression) throws IOException { final File outFile = new File(outDir, "sequences.fasta" + (compression.equals(GZIP) ? ".gz" : "")); LOGGER.trace("Writing a bulk of FASTA sequences to '" + outFile.getCanonicalPath()); toFasta(files, outFile.getCanonicalPath(), compression.equals(GZIP)); return outFile; }