Java Code Examples for org.scijava.util.FileUtils

The following examples show how to use org.scijava.util.FileUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: imagej-server   Source File: DefaultImageJServerService.java    License: Apache License 2.0 6 votes vote down vote up
private synchronized void initConfigFilePath() {
	if (configFilePath != null) return;

	try {
		final InputStream in = getClass().getResourceAsStream("imagej-server.yml");
		final byte[] bytes = readStreamFully(in);

		final File configFile = File.createTempFile("imagej-server", ".yml");
		FileUtils.writeFile(configFile, bytes);
		configFile.deleteOnExit();
		configFilePath = configFile.getAbsolutePath();
	}
	catch (final IOException exc) {
		log.error(exc);
	}
}
 
Example 2
Source Project: scijava-jupyter-kernel   Source File: ScijavaEvaluator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Path getTempFolder() {
    log.debug("getTempFolder()");
    try {
        return FileUtils.createTemporaryDirectory("scijava-jupyter-kernel", null).toPath();
    }
    catch (final IOException exc) {
        throw new RuntimeException(exc);
    }
}
 
Example 3
Source Project: sciview   Source File: ResourceLoader.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Creates a temporary file on disk with the contents of the given resource. */
public static File createFile( Class<?> c, String resourcePath ) throws IOException {
    final byte[] bytes;
    try (InputStream in = c.getResourceAsStream( resourcePath )) {
        bytes = readStreamFully( in );
    }

    String extension = "." + FileUtils.getExtension( resourcePath );
    File configFile = File.createTempFile( "SciView", extension );
    FileUtils.writeFile( configFile, bytes );
    configFile.deleteOnExit();
    return configFile;
}
 
Example 4
@Test
public void testReadmesExample() throws Exception {
	// extract the example script
	final File readme = new File("README.md");
	final String contents = new String(FileUtils.readFile(readme), "UTF-8");
	final String telltale = String.format("```python%n");
	final int begin = contents.indexOf(telltale) + telltale.length();
	assertTrue(begin > telltale.length());
	assertTrue(contents.indexOf(telltale, begin) < 0);
	final int end = contents.indexOf(String.format("```%n"), begin);
	assertTrue(end > 0);
	final String snippet = contents.substring(begin, end);
	assertTrue(snippet.startsWith("# @ImageJ ij"));

	final Context context = new Context();
	final ScriptService script = context.getService(ScriptService.class);

	// create mock ImageJ gateway
	script.addAlias("ImageJ", Mock.class);
	final ScriptModule module =
		script.run("op-example.py", snippet, true).get();
	assertNotNull(module);
	module.run();

	final Mock ij = context.getService(Mock.class);
	assertEquals(3, ij.images.size());
	assertEquals(11.906, ij.getPixel("sinusoid", 50, 50), 1e-3);
	assertEquals(100, ij.getPixel("gradient", 50, 50), 1e-3);
	assertEquals(111.906, ij.getPixel("composite", 50, 50), 1e-3);
}
 
Example 5
Source Project: Scripts   Source File: Runner.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void openLastLoadedResource() {
	if (lastLoadedURL == null) {
		return;
	}
	final TextEditor editor = new TextEditor(context);
	editor.loadTemplate(lastLoadedURL);
	editor.setTitle(FileUtils.shortenPath(lastLoadedURL.getPath(), 0));
	editor.setVisible(true);
}
 
Example 6
Source Project: sciview   Source File: OBJMeshIO.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public boolean supportsOpen(final String source) {
    return FileUtils.getExtension(source).toLowerCase().equals(EXTENSION);
}
 
Example 7
Source Project: Scripts   Source File: Runner.java    License: GNU General Public License v3.0 4 votes vote down vote up
public File getLastLoadedResource() {
	return FileUtils.urlToFile(lastLoadedURL);
}
 
Example 8
Source Project: imagej-server   Source File: DefaultTableIOPlugin.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean supportsOpen(final String source) {
	final String ext = FileUtils.getExtension(source).toLowerCase();
	return SUPPORTED_EXTENSIONS.contains(ext);
}