/** * Returns the absolute uri of the Class-Path entry value as specified in <a * href="http://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html#Main_Attributes">JAR * File Specification</a>. Even though the specification only talks about relative urls, * absolute urls are actually supported too (for example, in Maven surefire plugin). */ @VisibleForTesting static URL getClassPathEntry(File jarFile, String path) throws MalformedURLException { return new URL(jarFile.toURI().toURL(), path); } }
public URL find(String classname) { char sep = File.separatorChar; String filename = directory + sep + classname.replace('.', sep) + ".class"; File f = new File(filename); if (f.exists()) try { return f.getCanonicalFile().toURI().toURL(); } catch (MalformedURLException e) {} catch (IOException e) {} return null; }
public static String createTempFileInDirectory(String dir, String contents) throws IOException { File f; do { f = new File(dir + "/" + randomFileName()); } while (f.exists()); f.getParentFile().mkdirs(); f.createNewFile(); f.deleteOnExit(); try (BufferedWriter out = new BufferedWriter(new FileWriter(f))) { out.write(contents); } return f.toURI().toString(); }
private static Collection<Arguments> testdata_testConvert_with_non_null_input() throws Exception{ final List<Arguments> params = new ArrayList<>(); params.add(Arguments.of(new URL("http://jodd.org/"))); params.add(Arguments.of(new File(SystemUtil.info().getTempDir(), "jodd.txt"))); params.add(Arguments.of(new File(SystemUtil.info().getTempDir(), "jodd.txt").toURI())); params.add(Arguments.of("http://jodd.org/")); return params; }
@Test public void testExampleRegex() throws IOException { File tmpFile = new File(tmpDir, "renames-123.gz"); tmpFile.createNewFile(); Assert.assertTrue(tmpFile.exists()); Assert.assertFalse(tmpFile.isDirectory()); Assert.assertEquals( tmpFile.getAbsolutePath(), finder.getLatestVersion(tmpDir.toURI(), Pattern.compile("renames-[0-9]*\\.gz")).getPath() ); } }
private static List<JavaFileObject> browseDir(String packageName, File directory) { List<JavaFileObject> result = new ArrayList<>(); for (File childFile : directory.listFiles()) { if (childFile.isFile() && childFile.getName().endsWith(CLASS_FILE)) { String binaryName = packageName + "." + childFile.getName().replaceAll(CLASS_FILE + "$", ""); result.add(new CustomJavaFileObject(childFile.toURI(), JavaFileObject.Kind.CLASS, binaryName)); } } return result; }
@Test public void testSimpleOneFileLatestVersion() throws IOException { File oldFile = File.createTempFile("old", ".txt", tmpDir); Assert.assertTrue(oldFile.exists()); Assert.assertEquals( oldFile.getAbsolutePath(), finder.getLatestVersion(oldFile.toURI(), Pattern.compile(".*\\.txt")).getPath() ); }
private static URLClassLoader createClassLoader(File root) throws MalformedURLException { return new URLClassLoader( new URL[]{root.toURI().toURL()}, Thread.currentThread().getContextClassLoader()); }
/** * Creates a classloader respecting the classpath option. * * @return the classloader. */ protected synchronized ClassLoader createClassloader() { URL[] urls = classpath.stream().map(path -> { File file = new File(path); try { return file.toURI().toURL(); } catch (MalformedURLException e) { throw new IllegalStateException(e); } }).toArray(URL[]::new); return new URLClassLoader(urls, this.getClass().getClassLoader()); }
public static String createTempFileInDirectory(String dir, long bytes) throws IOException { File f; do { f = new File(dir + "/" + randomFileName()); } while (f.exists()); f.getParentFile().mkdirs(); f.createNewFile(); f.deleteOnExit(); try (BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f))) { for (; bytes > 0; bytes--) { out.write(0); } } return f.toURI().toString(); }
/** * Returns URI-representation of the path for the given file name. * The path is formed base on the root location. * This implementation uses 'src/test/resources/com/puppycrawl/tools/checkstyle/' * as a root location. * @param filename file name. * @return URI-representation of the path for the file with the given file name. */ protected final String getUriString(String filename) { return new File("src/test/resources/" + getPackageLocation() + "/" + filename).toURI() .toString(); }