org.scijava.util.FileUtils Java Examples
The following examples show how to use
org.scijava.util.FileUtils.
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 File: DefaultImageJServerService.java From imagej-server with Apache License 2.0 | 6 votes |
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 File: ScijavaEvaluator.java From scijava-jupyter-kernel with Apache License 2.0 | 5 votes |
@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 File: ResourceLoader.java From sciview with BSD 2-Clause "Simplified" License | 5 votes |
/** 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
Source File: ReadmeExampleTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@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 File: Runner.java From Scripts with GNU General Public License v3.0 | 5 votes |
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 File: OBJMeshIO.java From sciview with BSD 2-Clause "Simplified" License | 4 votes |
@Override public boolean supportsOpen(final String source) { return FileUtils.getExtension(source).toLowerCase().equals(EXTENSION); }
Example #7
Source File: Runner.java From Scripts with GNU General Public License v3.0 | 4 votes |
public File getLastLoadedResource() { return FileUtils.urlToFile(lastLoadedURL); }
Example #8
Source File: DefaultTableIOPlugin.java From imagej-server with Apache License 2.0 | 4 votes |
@Override public boolean supportsOpen(final String source) { final String ext = FileUtils.getExtension(source).toLowerCase(); return SUPPORTED_EXTENSIONS.contains(ext); }