• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java FileUtils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.scijava.util.FileUtils的典型用法代码示例。如果您正苦于以下问题:Java FileUtils类的具体用法?Java FileUtils怎么用?Java FileUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



FileUtils类属于org.scijava.util包,在下文中一共展示了FileUtils类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: loadGraph

import org.scijava.util.FileUtils; //导入依赖的package包/类
@Override
public Graph loadGraph(final Location source, final String modelName,
	final String graphPath) throws IOException
{
	final String key = modelName + "/" + graphPath;

	// If the graph is already cached in memory, return it.
	if (graphs.containsKey(key)) return graphs.get(key);

	// Get a local directory with unpacked model data.
	final File modelDir = modelDir(source, modelName);

	// Read the serialized graph.
	final byte[] graphDef = FileUtils.readFile(new File(modelDir, graphPath));

	// Convert to a TensorFlow Graph object.
	final Graph graph = new Graph();
	graph.importGraphDef(graphDef);

	// Cache the result for performance next time.
	graphs.put(key, graph);

	return graph;
}
 
开发者ID:imagej,项目名称:imagej-tensorflow,代码行数:25,代码来源:DefaultTensorFlowService.java


示例2: loadRemoteFile

import org.scijava.util.FileUtils; //导入依赖的package包/类
public static File loadRemoteFile(final URL url) throws IllegalArgumentException, SecurityException, IOException {

		// If a file URI, simply return local file
		if (url.toString().startsWith("file:"))
			return new File(url.getFile());

		final String filename = Paths.get(url.getPath()).getFileName().toString();
		if (filename == null || filename.trim().length() < 3)
			throw new IllegalArgumentException("URL does not contain a valid file path?");
		final File tempDir = FileUtils.createTemporaryDirectory("ipnat", null);
		final File file = new File(tempDir, filename);
		final InputStream in = url.openStream();
		Files.copy(in, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
		String data = null;
		final BufferedReader br = new BufferedReader(new FileReader(file));
		data = br.readLine();
		br.close();
		if (data == null || data.isEmpty())
			throw new IOException("No data could be read from parsed URL");
		return file;
	}
 
开发者ID:tferr,项目名称:hIPNAT,代码行数:22,代码来源:Utils.java


示例3: supports

import org.scijava.util.FileUtils; //导入依赖的package包/类
@Override
public boolean supports(final File file) {
	final String extension = FileUtils.getExtension(file);
	if (!EXTENSION.equalsIgnoreCase(extension)) {
		return false;
	}

	try (FileInputStream reader = new FileInputStream(file)) {
		final byte[] dataStart = new byte[5];
		reader.read(dataStart, 0, 5);
		// ASCII STL files begin with the line solid <name> whereas binary files
		// have an arbitrary header
		return !"solid".equals(Arrays.toString(dataStart));
	}
	catch (IOException e) {
		return false;
	}
}
 
开发者ID:imagej,项目名称:imagej-mesh,代码行数:19,代码来源:AbstractBinarySTLFormat.java


示例4: setup

import org.scijava.util.FileUtils; //导入依赖的package包/类
@Setup(Level.Trial)
public void setup() throws Exception {
	// cleanup
	baseDirectory = new File("output").getAbsoluteFile();
	FileUtils.deleteRecursively(baseDirectory);
	baseDirectory.mkdirs();

	// Read test image
	final File testImage = new File(getClass().getResource(IMG1).getPath());
	m_sfimg = opener.openImgs(testImage.getPath()).get(0);

	m_tiffPath = getFormatPath("tif");
	m_omeTiffPath = getFormatPath("ome.tif");
	m_pngPath = getFormatPath("png");
	m_epsPath = getFormatPath("eps");
	m_icsPath = getFormatPath("ics");
	m_jpgPath = getFormatPath("jpg");
}
 
开发者ID:scifio,项目名称:scifio-benchmark,代码行数:19,代码来源:WriteMediumFileTest.java


示例5: setup

import org.scijava.util.FileUtils; //导入依赖的package包/类
@Before
public void setup() throws Exception {
	// cleanup
	baseDirectory = new File("output").getAbsoluteFile();
	FileUtils.deleteRecursively(baseDirectory);
	baseDirectory.mkdirs();

	// Read test image
	final File testImage = new File(getClass().getResource(IMG1).getPath());
	m_sfimg = opener.openImgs(testImage.getPath()).get(0);

	m_tiffPath = getFormatPath("tif");
	m_omeTiffPath = getFormatPath("ome.tif");
	m_pngPath = getFormatPath("png");
	m_epsPath = getFormatPath("eps");
	m_icsPath = getFormatPath("ics");
	m_jpgPath = getFormatPath("jpg");
}
 
开发者ID:scifio,项目名称:scifio-benchmark,代码行数:19,代码来源:WriteLargeFileProfiling.java


示例6: getTempFolder

import org.scijava.util.FileUtils; //导入依赖的package包/类
@Override
public Path getTempFolder() {
    log.debug("getTempFolder()");
    try {
        return FileUtils.createTemporaryDirectory("scijava-jupyter-kernel", null).toPath();
    }
    catch (final IOException exc) {
        throw new RuntimeException(exc);
    }
}
 
开发者ID:scijava,项目名称:scijava-jupyter-kernel,代码行数:11,代码来源:ScijavaEvaluator.java


示例7: setUp

import org.scijava.util.FileUtils; //导入依赖的package包/类
@Before
public void setUp() throws IOException {
	context = new Context(Java3DService.class);
	j3d = context.service(Java3DService.class);

	tmp1 = FileUtils.createTemporaryDirectory("libExt", "1");
	tmp2 = FileUtils.createTemporaryDirectory("libExt", "2");
}
 
开发者ID:scijava,项目名称:scijava-java3d,代码行数:9,代码来源:Java3DServiceTest.java


示例8: write

import org.scijava.util.FileUtils; //导入依赖的package包/类
protected < T > void write( final Iterable< T > source, final String path ) throws IOException
{
	final StringBuilder sb = new StringBuilder( "" );
	final Iterator< T > it = source.iterator();
	if ( it.hasNext() )
		sb.append( it.next() );
	while ( it.hasNext() )
		sb.append( "\n" ).append( it.next() );
	FileUtils.writeFile( new File( path ), sb.toString().getBytes() );
}
 
开发者ID:saalfeldlab,项目名称:z-spacing,代码行数:11,代码来源:CSVVisitor.java


示例9: testReadmesExample

import org.scijava.util.FileUtils; //导入依赖的package包/类
@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);
}
 
开发者ID:imagej,项目名称:imagej-ops,代码行数:31,代码来源:ReadmeExampleTest.java


示例10: parsePosition

import org.scijava.util.FileUtils; //导入依赖的package包/类
private void parsePosition(final Metadata meta, final int posIndex)
	throws IOException, FormatException
{
	final Position p = meta.getPositions().get(posIndex);
	final byte[] bytes = FileUtils.readFile(new File(p.metadataFile));
	final String s = DigestUtils.string(bytes);
	parsePosition(s, meta, posIndex);

	buildTIFFList(meta, posIndex);
}
 
开发者ID:scifio,项目名称:scifio,代码行数:11,代码来源:MicromanagerFormat.java


示例11: parseXMLFile

import org.scijava.util.FileUtils; //导入依赖的package包/类
/** Parse metadata values from the Acqusition.xml file. */
private void parseXMLFile(final Metadata meta, final int imageIndex)
	throws IOException
{
	final Position p = meta.getPositions().get(imageIndex);
	final byte[] bytes = FileUtils.readFile(new File(p.xmlFile));
	String xmlData = DigestUtils.string(bytes);
	xmlData = xmlService.sanitizeXML(xmlData);

	final DefaultHandler handler = new MicromanagerHandler();
	xmlService.parseXML(xmlData, handler);
}
 
开发者ID:scifio,项目名称:scifio,代码行数:13,代码来源:MicromanagerFormat.java


示例12: openLastLoadedResource

import org.scijava.util.FileUtils; //导入依赖的package包/类
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);
}
 
开发者ID:tferr,项目名称:Scripts,代码行数:10,代码来源:Runner.java


示例13: generateAll

import org.scijava.util.FileUtils; //导入依赖的package包/类
/** Generates OMERO script stubs for all available ImageJ modules. */
public int generateAll(final File omeroDir) throws IOException {
	final File scriptsDir = new File(new File(omeroDir, "lib"), "scripts");
	if (!scriptsDir.exists()) {
		System.err.println("OMERO scripts directory not found: " + scriptsDir);
		return 1;
	}

	final File dir = new File(scriptsDir, namespace);
	if (dir.exists()) {
		if (!forceOverwrite) {
			System.err.println("Path already exists: " + dir);
			System.err.println("Please run with --force if you wish to generate scripts.");
			return 2;
		}
		FileUtils.deleteRecursively(dir);
	}

	// create the directory
	final boolean success = dir.mkdirs();
	if (!success) {
		System.err.println("Could not create directory: " + dir);
		return 3;
	}

	// we will execute ImageJ.app/lib/run-script
	final File baseDir = appService.getApp().getBaseDirectory();
	final File libDir = new File(baseDir, "lib");
	final File runScript = new File(libDir, "run-script");
	final String exe = runScript.getAbsolutePath();

	// generate the scripts
	generateAll(menuService.getMenu(), dir, exe, 0);
	return 0;
}
 
开发者ID:imagej,项目名称:imagej-omero,代码行数:36,代码来源:ScriptGenerator.java


示例14: tearDown

import org.scijava.util.FileUtils; //导入依赖的package包/类
@After
public void tearDown() {
	FileUtils.deleteRecursively(tmp1);
	FileUtils.deleteRecursively(tmp2);
}
 
开发者ID:scijava,项目名称:scijava-java3d,代码行数:6,代码来源:Java3DServiceTest.java


示例15: getLastLoadedResource

import org.scijava.util.FileUtils; //导入依赖的package包/类
public File getLastLoadedResource() {
	return FileUtils.urlToFile(lastLoadedURL);
}
 
开发者ID:tferr,项目名称:Scripts,代码行数:4,代码来源:Runner.java


示例16: installLib

import org.scijava.util.FileUtils; //导入依赖的package包/类
public int installLib(final boolean verbose) {

		final String commonPath = ""; // We'll keep it empty for now in case it
										// parent of the lib directory changes
										// again (eg, in some previous BAR
										// versions "lib" was not on the root of
										// resources but at "scripts/BAR/")
		final String resourcePath = commonPath + "lib/";
		exitStatus = CLEAN_EXIT;
		try {
			final URL source = Utils.getBARresource(resourcePath);
			if (verbose)
				logService.info("Recursively copying resources from " + source);

			// Define destination path
			final String sourceFilename = source.getFile();
			final int startOfBasename = sourceFilename.indexOf("!") + commonPath.length() + 1;
			final String destinationPath = Utils.getBARDir() + sourceFilename.substring(startOfBasename);

			final Collection<URL> urlList = FileUtils.listContents(source, true, false);
			for (final URL url : urlList) {

				final String urlPath = url.getPath();
				final int baseIndex = urlPath.lastIndexOf("/") + 1;
				final String filename = urlPath.substring(baseIndex);

				if (filename.isEmpty())
					continue;

				File destinationFile = null;
				long bytesCopied = 0;
				try {

					if (verbose)
						logService.info("Copying " + filename + " to " + destinationPath);
					final File destinationDir = new File(destinationPath);
					destinationDir.mkdirs();
					destinationFile = new File(destinationPath, filename);
					if (!destinationFile.exists()) {
						destinationFile.createNewFile();
					} else if (verbose) {
						logService.warn("Existing file at destination will be overwritten");
					}

					final Path to = Paths.get(destinationFile.toURI());
					final CopyOption[] options = new CopyOption[] { StandardCopyOption.REPLACE_EXISTING, };
					final InputStream in = url.openStream();
					bytesCopied = Files.copy(in, to, options);

				} finally {

					if (bytesCopied == 0 || destinationFile == null || !destinationFile.exists())
						exitStatus = ERROR;

					if (verbose) {
						if (exitStatus == ERROR)
							logService.error(filename + " could not be copied");
						else
							logService.info(filename + " copied (" + String.valueOf(bytesCopied) + " bytes)");
					}
				}

			}

		} catch (NullPointerException | IndexOutOfBoundsException | IOException | SecurityException exc) {
			if (verbose)
				exc.printStackTrace();
			exitStatus = ERROR;
		}

		return exitStatus;
	}
 
开发者ID:tferr,项目名称:Scripts,代码行数:73,代码来源:Installer.java


示例17: supportsOpen

import org.scijava.util.FileUtils; //导入依赖的package包/类
@Override
public boolean supportsOpen(final String source) {
	final String ext = FileUtils.getExtension(source).toLowerCase();
	return SUPPORTED_EXTENSIONS.contains(ext);
}
 
开发者ID:imagej,项目名称:imagej-server,代码行数:6,代码来源:DefaultTableIOPlugin.java


示例18: testGenerateAll

import org.scijava.util.FileUtils; //导入依赖的package包/类
@Test
public void testGenerateAll() throws IOException {
	// create a context with a minimal command set
	final PluginIndex pluginIndex = new PluginIndex() {
		@Override
		public void discover() {
			super.discover();
			removeAll(getPlugins(Command.class));
			add(pluginInfo(FileNew.class));
			add(pluginInfo(FileOpen.class));
			add(pluginInfo(FileSave.class));
			add(pluginInfo(FileExit.class));
			add(pluginInfo(Lion.class));
			add(pluginInfo(Tiger.class));
			add(pluginInfo(Bear.class));
		}
	};
	final ArrayList<Class<? extends Service>> classes =
		new ArrayList<Class<? extends Service>>();
	classes.add(AppService.class);
	classes.add(CommandService.class);
	classes.add(MenuService.class);
	final Context context = new Context(classes, pluginIndex);
	final ScriptGenerator scriptGen = new ScriptGenerator(context);
	final File tempDir =
		TestUtils.createTemporaryDirectory("script-generator-");
	final File libDir = new File(tempDir, "lib");
	final File scriptsDir = new File(libDir, "scripts");
	assertTrue(scriptsDir.mkdirs());
	final int returnCode = scriptGen.generateAll(tempDir);
	context.dispose();

	assertEquals(0, returnCode);
	final File imagejDir = new File(scriptsDir, "imagej");
	assertTrue(imagejDir.isDirectory());
	final File fileDir = new File(imagejDir, "File");
	assertTrue(fileDir.isDirectory());
	final File animalsDir = new File(imagejDir, "\ufeffAnimals");
	assertTrue(animalsDir.isDirectory());
	assertTrue(new File(fileDir, "New.py").exists());
	assertTrue(new File(fileDir, "\ufeffOpen.py").exists());
	assertTrue(new File(fileDir, "\ufeff\ufeffSave.py").exists());
	assertTrue(new File(fileDir, "\ufeff\ufeff\ufeffExit.py").exists());
	assertTrue(new File(animalsDir, "Lion.py").exists());
	assertTrue(new File(animalsDir, "\ufeffTiger.py").exists());
	assertTrue(new File(animalsDir, "\ufeff\ufeffBear.py").exists());
	FileUtils.deleteRecursively(tempDir);
}
 
开发者ID:imagej,项目名称:imagej-omero,代码行数:49,代码来源:ScriptGeneratorTest.java



注:本文中的org.scijava.util.FileUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PlayerStatisticIncrementEvent类代码示例发布时间:2022-05-22
下一篇:
Java DocCommentTable类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap