@Override public void download(String downloadUrl, String destination, String userName, String password) throws DownloadException { // force tls to 1.2 since github removed weak cryptographic standards // https://blog.github.com/2018-02-02-weak-cryptographic-standards-removal-notice/ System.setProperty("https.protocols", "TLSv1.2"); String fixedDownloadUrl = downloadUrl; try { fixedDownloadUrl = FilenameUtils.separatorsToUnix(fixedDownloadUrl); URI downloadURI = new URI(fixedDownloadUrl); if ("file".equalsIgnoreCase(downloadURI.getScheme())) { FileUtils.copyFile(new File(downloadURI), new File(destination)); } else { CloseableHttpResponse response = execute(fixedDownloadUrl, userName, password); int statusCode = response.getStatusLine().getStatusCode(); if(statusCode != 200){ throw new DownloadException("Got error code "+ statusCode +" from the server."); } new File(FilenameUtils.getFullPathNoEndSeparator(destination)).mkdirs(); ReadableByteChannel rbc = Channels.newChannel(response.getEntity().getContent()); FileOutputStream fos = new FileOutputStream(destination); fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); fos.close(); } } catch (IOException | URISyntaxException e) { throw new DownloadException("Could not download " + fixedDownloadUrl, e); } }
/** * Test for https://issues.apache.org/jira/browse/IO-248 */ @Test public void testGetFullPathNoEndSeparator_IO_248() { // Test single separator assertEquals("/", FilenameUtils.getFullPathNoEndSeparator("/")); assertEquals("\\", FilenameUtils.getFullPathNoEndSeparator("\\")); // Test one level directory assertEquals("/", FilenameUtils.getFullPathNoEndSeparator("/abc")); assertEquals("\\", FilenameUtils.getFullPathNoEndSeparator("\\abc")); // Test one level directory assertEquals("/abc", FilenameUtils.getFullPathNoEndSeparator("/abc/xyz")); assertEquals("\\abc", FilenameUtils.getFullPathNoEndSeparator("\\abc\\xyz")); }
@Override public void init(RootNode root) { List<DexNode> dexNodes = root.getDexNodes(); if (dexNodes.isEmpty()) { return; } InputFile firstInputFile = dexNodes.get(0).getDexFile().getInputFile(); String firstInputFileName = firstInputFile.getFile().getAbsolutePath(); String inputPath = FilenameUtils.getFullPathNoEndSeparator(firstInputFileName); String inputName = FilenameUtils.getBaseName(firstInputFileName); File deobfMapFile = new File(inputPath, inputName + ".jobf"); JadxArgs args = root.getArgs(); deobfuscator = new Deobfuscator(args, dexNodes, deobfMapFile); boolean deobfuscationOn = args.isDeobfuscationOn(); if (deobfuscationOn) { deobfuscator.execute(); } boolean isCaseSensitive = FileUtils.isCaseSensitiveFS(new File(inputPath)); // args.getOutDir() - not set in gui checkClasses(root, isCaseSensitive); }
@Test public void testGetFullPathNoEndSeparator() { assertEquals(null, FilenameUtils.getFullPathNoEndSeparator(null)); assertEquals("", FilenameUtils.getFullPathNoEndSeparator("noseperator.inthispath")); assertEquals("a/b", FilenameUtils.getFullPathNoEndSeparator("a/b/c.txt")); assertEquals("a/b", FilenameUtils.getFullPathNoEndSeparator("a/b/c")); assertEquals("a/b/c", FilenameUtils.getFullPathNoEndSeparator("a/b/c/")); assertEquals("a\\b", FilenameUtils.getFullPathNoEndSeparator("a\\b\\c")); assertEquals(null, FilenameUtils.getFullPathNoEndSeparator(":")); assertEquals(null, FilenameUtils.getFullPathNoEndSeparator("1:/a/b/c.txt")); assertEquals(null, FilenameUtils.getFullPathNoEndSeparator("1:")); assertEquals(null, FilenameUtils.getFullPathNoEndSeparator("1:a")); assertEquals(null, FilenameUtils.getFullPathNoEndSeparator("///a/b/c.txt")); assertEquals(null, FilenameUtils.getFullPathNoEndSeparator("//a")); assertEquals("", FilenameUtils.getFullPathNoEndSeparator("")); assertEquals("C:", FilenameUtils.getFullPathNoEndSeparator("C:")); assertEquals("C:/", FilenameUtils.getFullPathNoEndSeparator("C:/")); assertEquals("//server/", FilenameUtils.getFullPathNoEndSeparator("//server/")); assertEquals("~", FilenameUtils.getFullPathNoEndSeparator("~")); assertEquals("~/", FilenameUtils.getFullPathNoEndSeparator("~/")); assertEquals("~user", FilenameUtils.getFullPathNoEndSeparator("~user")); assertEquals("~user/", FilenameUtils.getFullPathNoEndSeparator("~user/")); assertEquals("a/b", FilenameUtils.getFullPathNoEndSeparator("a/b/c.txt")); assertEquals("/a/b", FilenameUtils.getFullPathNoEndSeparator("/a/b/c.txt")); assertEquals("C:", FilenameUtils.getFullPathNoEndSeparator("C:a")); assertEquals("C:a/b", FilenameUtils.getFullPathNoEndSeparator("C:a/b/c.txt")); assertEquals("C:/a/b", FilenameUtils.getFullPathNoEndSeparator("C:/a/b/c.txt"));
@SuppressWarnings("PMD.SystemPrintln") private static String setOuputFolder(String[] args, File sampleFile) { String outputPath = FilenameUtils.getFullPathNoEndSeparator(sampleFile.getAbsolutePath()); if (args.length > 3) { outputPath = args[3]; System.out.println("Output folder has been specified: " + outputPath); final File outputFolder = new File(outputPath); if (!outputFolder.exists()) { System.out.println("Creating it"); outputFolder.mkdirs(); } } else { System.out.println( "Output folder hasn't been specified. The files will be created beside the sample file, at: " + outputPath); } return outputPath; }
/** * Devuelve el path de un archivo ejemplo c:/carpeta1/subcarpeta1/archivo.txt * retorna /carpeta1/subcarpeta1 * @param file nombre y path del archivo * @return el path del archivo */ public static String getFullPathNoEndSeparator(String file){ return FilenameUtils.getFullPathNoEndSeparator(file); }
/** * 获得文件的完整路径,不包含最后的路径分隔条 * * @param filename * 文件完整路径 * @return */ public static String getFullPathNoEndSeparator(String filename) { return FilenameUtils.getFullPathNoEndSeparator(filename); }
/** * This method fixes the problem when a resource in a group uses deep wildcard and starts at the root. * <p/> * Find more details <a href="https://github.com/alexo/wro4j/pull/44">here</a>. */ private String getFullPathNoEndSeparator(final String uri) { String result = FilenameUtils.getFullPathNoEndSeparator(uri); if (result != null && 1 == result.length() && 0 == FilenameUtils.indexOfLastSeparator(result)) return ""; return result; } };
public static String addedObjectPackage(String uri) { String path = FilenameUtils.getFullPathNoEndSeparator(uri); if (path.isEmpty()) { return EMPTY; } return "." + packageName(path); }
@Override public Object handle (Task aTask) { return FilenameUtils.getFullPathNoEndSeparator(aTask.getRequiredString("filename")); }
/** * This method fixes the problem when a resource in a group uses deep wildcard and starts at the root. * <p/> * Find more details <a href="https://github.com/alexo/wro4j/pull/44">here</a>. */ private String getFullPathNoEndSeparator(final Resource resource) { final String result = FilenameUtils.getFullPathNoEndSeparator(resource.getUri()); if (result != null && 1 == result.length() && 0 == FilenameUtils.indexOfLastSeparator(result)) { return ""; } return result; } };
/** * This method fixes the problem when a resource in a group uses deep wildcard and starts at the root. * <p/> * Find more details <a href="https://github.com/alexo/wro4j/pull/44">here</a>. */ private String getFullPathNoEndSeparator(final Resource resource1) { final String result = FilenameUtils.getFullPathNoEndSeparator(resource1.getUri()); if (result != null && 1 == result.length() && 0 == FilenameUtils.indexOfLastSeparator(result)) { return ""; } return result; } };
private FileAlterationObserver createObserver(String fileName) { final File file = new File(fileName); if (file.isDirectory()) { return new FileAlterationObserver(file); } else { return new FileAlterationObserver(FilenameUtils.getFullPathNoEndSeparator(fileName), FileFilterUtils .nameFileFilter(FilenameUtils.getName(fileName))); } }
/** * @return an input stream for an uri containing a wildcard for a given location. */ private InputStream locateWildcardStream(final String uri, final String location) throws IOException { LOG.debug("wildcard detected for location: {}", location); // prefix with '/' because we use class relative resource retrieval. Using ClassLoader.getSystemResource doesn't // work well. final String fullPath = "/" + FilenameUtils.getFullPathNoEndSeparator(location); URL url = getClass().getResource(fullPath); LOG.debug("Attempting to find resource {} at the following location: {}", uri, fullPath); try { return locateWildcardStream(uri, url); } catch (final IOException e) { //do not attempt unless exception is of this type if (e instanceof NoMoreAttemptsIOException) { throw e; } // try once more, in order to treat classpath resources located in the currently built project. url = getClass().getResource(""); LOG.debug("Attempting to find resource {} at the following URL: {}", uri, url); return locateWildcardStream(uri, url); } }
/** * @return an input stream for an uri containing a wildcard for a given location. */ private InputStream locateWildcardStream(final String uri, final String location) throws IOException { LOG.debug("wildcard detected for location: {}", location); // prefix with '/' because we use class relative resource retrieval. Using ClassLoader.getSystemResource doesn't // work well. final String fullPath = "/" + FilenameUtils.getFullPathNoEndSeparator(location); URL url = getClass().getResource(fullPath); LOG.debug("Attempting to find resource {} at the following location: {}", uri, fullPath); try { return locateWildcardStream(uri, url); } catch (final IOException e) { //do not attempt unless exception is of this type if (e instanceof NoMoreAttemptsIOException) { throw e; } // try once more, in order to treat classpath resources located in the currently built project. url = getClass().getResource(""); LOG.debug("Attempting to find resource {} at the following URL: {}", uri, url); return locateWildcardStream(uri, url); } }
/** * @return Path of the target's parent directory. */ public String getTargetFileDirectory() { final String targetFile = getTargetFile(); if (targetFile == null) return null; final String normalizedTargetFile = FilenameNormalization.normalize(targetFile); return FilenameUtils.getFullPathNoEndSeparator(normalizedTargetFile); }
/** * @return Path of the target's parent directory. */ public String getTargetFileDirectory() { final String targetFile = getTargetFile(); if (targetFile == null) return null; final String normalizedTargetFile = FilenameNormalization.normalize(targetFile); return FilenameUtils.getFullPathNoEndSeparator(normalizedTargetFile); }
/** * @return Path of the target's parent directory. */ public String getTargetFileDirectory() { final String targetFile = getTargetFile(); if (targetFile == null) return null; final String normalizedTargetFile = FilenameNormalization.normalize(targetFile); return FilenameUtils.getFullPathNoEndSeparator(normalizedTargetFile); }
private String getParentDir() { String filename = PathUtils.normalize(getFilename()); if (filename == null) return null; return FilenameUtils.getFullPathNoEndSeparator(filename); }
protected Log[] getPastLogs(final String liveLog) throws IOException { final File dir = new File(FilenameUtils.getFullPathNoEndSeparator(liveLog)); final String pastPattern = FilenameUtils.getName(liveLog) + getPastLogsSuffixPattern(); final FileFilter fileFilter = new WildcardFileFilter(pastPattern); final File[] files = dir.listFiles(fileFilter); final FileLog[] logs = new FileLog[files.length]; Arrays.sort(files, getPastLogsType().getPastComparator()); int i = 0; for (final File file : files) { // TODO Decouple direct file log association logs[i++] = new FileLog(file); } logger.debug("Found {} past logs for {} with pattern {}", logs.length, liveLog, pastPattern); return logs; }