@Test public void testInTargetDir() throws IOException { logger.debug("[{}]testInTargetDir: entered.", Integer.toHexString(identityHashCode(this))); System.out.println("####### testInTargetDir #######"); final File tmpDir = createTempDirectory(this.getClass().getSimpleName()); final File testDir = tmpDir; System.out.println("testDir= " + testDir.getAbsolutePath()); final File subFolder = createFile(testDir, "subFolder"); subFolder.mkdirs(); final File fileName = createFile(subFolder, "fileName"); fileName.createNewFile(); System.out.println("fileName= " + fileName.getAbsolutePath()); final String relPath = getRelativePath(testDir, fileName); System.out.println("relPath= " + relPath); assertThat(relPath).isNotNull(); assertThat(fileName.getAbsolutePath().endsWith(relPath)).isTrue(); assertThat(relPath).isEqualTo("subFolder/fileName"); }
@Deprecated public static String getRelativePath(File baseDir, final String file) throws IOException { if (baseDir.isAbsolute()) baseDir = createFile(simplifyPath(baseDir)); else baseDir = createFile(simplifyPath(baseDir.getAbsoluteFile())); File absFile; final File tmpF = createFile(file); if (tmpF.isAbsolute()) absFile = tmpF; else absFile = createFile(baseDir, file); final File dest = absFile; File b = baseDir; String up = ""; while (b.getParentFile() != null) { final String res = _getRelativePath(b, dest.getAbsolutePath()); if (res != null) return up + res; up = ".." + FILE_SEPARATOR + up; b = b.getParentFile(); } return absFile.getAbsolutePath(); }
IOUtil { @Deprecated public static String getRelativePath(File baseDir, final String file) throws IOException { if (baseDir.isAbsolute()) baseDir = createFile(simplifyPath(baseDir)); else baseDir = createFile(simplifyPath(baseDir.getAbsoluteFile())); File absFile; final File tmpF = createFile(file); if (tmpF.isAbsolute()) absFile = tmpF; else absFile = createFile(baseDir, file); final File dest = absFile; File b = baseDir; String up = ""; while (b.getParentFile() != null) { final String res = _getRelativePath(b, dest.getAbsolutePath()); if (res != null) return up + res; up = ".." + FILE_SEPARATOR + up; b = b.getParentFile(); } return absFile.getAbsolutePath(); } }
IOUtil { @Deprecated public static String getRelativePath(File baseDir, final String file) throws IOException { if (baseDir.isAbsolute()) baseDir = createFile(simplifyPath(baseDir)); else baseDir = createFile(simplifyPath(baseDir.getAbsoluteFile())); File absFile; final File tmpF = createFile(file); if (tmpF.isAbsolute()) absFile = tmpF; else absFile = createFile(baseDir, file); final File dest = absFile; File b = baseDir; String up = ""; while (b.getParentFile() != null) { final String res = _getRelativePath(b, dest.getAbsolutePath()); if (res != null) return up + res; up = ".." + FILE_SEPARATOR + up; b = b.getParentFile(); } return absFile.getAbsolutePath(); } private  IOUtil(); }
IOUtil { @Deprecated public static String getRelativePath(File baseDir, final String file) throws IOException { if (baseDir.isAbsolute()) baseDir = createFile(simplifyPath(baseDir)); else baseDir = createFile(simplifyPath(baseDir.getAbsoluteFile())); File absFile; final File tmpF = createFile(file); if (tmpF.isAbsolute()) absFile = tmpF; else absFile = createFile(baseDir, file); final File dest = absFile; File b = baseDir; String up = ""; while (b.getParentFile() != null) { final String res = _getRelativePath(b, dest.getAbsolutePath()); if (res != null) return up + res; up = ".." + FILE_SEPARATOR + up; b = b.getParentFile(); } return absFile.getAbsolutePath(); } private  IOUtil(); @Deprecated static String getRelativePath(File baseDir, final String file); @Deprecated static String getRelativePath(final File baseDir, final File file); @Deprecated static String getRelativePath(final String baseDir, final String file); static String simplifyPath(final File path); static long transferStreamData(final InputStream in, final OutputStream out, final long inputOffset, final long inputLen); static long transferStreamData(final InputStream in, final OutputStream out, final long inputOffset, final long inputLen, final ProgressMonitor monitor); static long transferStreamData(final InputStream in, final OutputStream out); @Deprecated static boolean deleteDirectoryRecursively(final File dir); @Deprecated static boolean deleteDirectoryRecursively(final String dir); static synchronized File createUniqueIncrementalFolder(final File rootFolder, final String prefix); static synchronized File createUniqueRandomFolder(final File rootFolder, final String prefix, final long maxIterations, final long uniqueOutOf); static File createUniqueRandomFolder(final File rootFolder, final String prefix); static File getFile(final File file, final String ... subDirs); static void writeTextFile(final File file, final String text, final String encoding); static String readTextFile(final File f, final String encoding); static String readTextFile(final File f); static void writeTextFile(final File file, final String text); static String readTextFile(final InputStream in, final String encoding); static String readTextFile(final InputStream in); static String getFileExtension(final String fileName); static String getFileNameWithoutExtension(final String fileName); static File getTempDir(); static File createUserTempDir(final String prefix, final String suffix); static File getUserTempDir(final String prefix, final String suffix); static File getUserHome(); static boolean compareInputStreams(final InputStream inputStream1, final InputStream inputStream2); static boolean compareFiles(final File f1, final File f2); static void copyDirectory(final File sourceDirectory, final File destinationDirectory); static void copyDirectory(final File sourceDirectory, final File destinationDirectory, final FileFilter fileFilter); static void copyResource(final Class<?> sourceResClass, final String sourceResName, final String destinationFilename); static void copyResource(final Class<?> sourceResClass, final String sourceResName, final File destinationFile); static void copyFile(final File sourceFile, final File destinationFile); static void copyFile(final File sourceFile, final File destinationFile, final ProgressMonitor monitor); static String addFinalSlash(final String directory); static void replaceTemplateVariables(final File destinationFile, final File templateFile, final String characterSet, final Map<?, ?> variables); static String replaceTemplateVariables(final String template, final Map<?, ?> variables); static void replaceTemplateVariables(final Writer writer, final Reader reader, final Map<?, ?> variables); static byte[] getBytesFromFile(final File file); static File createCollisionFile(final File file); static void deleteOrFail(final File file); static int readOrFail(final InputStream in); static void readOrFail(final InputStream in, final byte[] buf, int off, int len); static byte[] longToBytes(final long value); static long bytesToLong(final byte[] bytes); static byte[] intToBytes(final int value); static int bytesToInt(final byte[] bytes); }
IOUtil { @Deprecated public static String getRelativePath(File baseDir, final String file) throws IOException { if (baseDir.isAbsolute()) baseDir = createFile(simplifyPath(baseDir)); else baseDir = createFile(simplifyPath(baseDir.getAbsoluteFile())); File absFile; final File tmpF = createFile(file); if (tmpF.isAbsolute()) absFile = tmpF; else absFile = createFile(baseDir, file); final File dest = absFile; File b = baseDir; String up = ""; while (b.getParentFile() != null) { final String res = _getRelativePath(b, dest.getAbsolutePath()); if (res != null) return up + res; up = ".." + FILE_SEPARATOR + up; b = b.getParentFile(); } return absFile.getAbsolutePath(); } private  IOUtil(); @Deprecated static String getRelativePath(File baseDir, final String file); @Deprecated static String getRelativePath(final File baseDir, final File file); @Deprecated static String getRelativePath(final String baseDir, final String file); static String simplifyPath(final File path); static long transferStreamData(final InputStream in, final OutputStream out, final long inputOffset, final long inputLen); static long transferStreamData(final InputStream in, final OutputStream out, final long inputOffset, final long inputLen, final ProgressMonitor monitor); static long transferStreamData(final InputStream in, final OutputStream out); @Deprecated static boolean deleteDirectoryRecursively(final File dir); @Deprecated static boolean deleteDirectoryRecursively(final String dir); static synchronized File createUniqueIncrementalFolder(final File rootFolder, final String prefix); static synchronized File createUniqueRandomFolder(final File rootFolder, final String prefix, final long maxIterations, final long uniqueOutOf); static File createUniqueRandomFolder(final File rootFolder, final String prefix); static File getFile(final File file, final String ... subDirs); static void writeTextFile(final File file, final String text, final String encoding); static String readTextFile(final File f, final String encoding); static String readTextFile(final File f); static void writeTextFile(final File file, final String text); static String readTextFile(final InputStream in, final String encoding); static String readTextFile(final InputStream in); static String getFileExtension(final String fileName); static String getFileNameWithoutExtension(final String fileName); static File getTempDir(); static File createUserTempDir(final String prefix, final String suffix); static File getUserTempDir(final String prefix, final String suffix); static File getUserHome(); static boolean compareInputStreams(final InputStream inputStream1, final InputStream inputStream2); static boolean compareFiles(final File f1, final File f2); static void copyDirectory(final File sourceDirectory, final File destinationDirectory); static void copyDirectory(final File sourceDirectory, final File destinationDirectory, final FileFilter fileFilter); static void copyResource(final Class<?> sourceResClass, final String sourceResName, final String destinationFilename); static void copyResource(final Class<?> sourceResClass, final String sourceResName, final File destinationFile); static void copyFile(final File sourceFile, final File destinationFile); static void copyFile(final File sourceFile, final File destinationFile, final ProgressMonitor monitor); static String addFinalSlash(final String directory); static void replaceTemplateVariables(final File destinationFile, final File templateFile, final String characterSet, final Map<?, ?> variables); static String replaceTemplateVariables(final String template, final Map<?, ?> variables); static void replaceTemplateVariables(final Writer writer, final Reader reader, final Map<?, ?> variables); static byte[] getBytesFromFile(final File file); static File createCollisionFile(final File file); static void deleteOrFail(final File file); static int readOrFail(final InputStream in); static void readOrFail(final InputStream in, final byte[] buf, int off, int len); static byte[] longToBytes(final long value); static long bytesToLong(final byte[] bytes); static byte[] intToBytes(final int value); static int bytesToInt(final byte[] bytes); static final String CHARSET_NAME_UTF_8; static final long GIGABYTE; static final String COLLISION_FILE_NAME_INFIX; }