当前位置: 首页>>代码示例>>Java>>正文


Java FileUtil类代码示例

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


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

示例1: JavaSnippet

import org.knime.core.util.FileUtil; //导入依赖的package包/类
/**
 * Create a new snippet.
 */
public JavaSnippet() {
	m_fields = new JavaSnippetFields();
	File tempDir;
	try {
		tempDir = FileUtil.createTempDir("knime_javasnippet");
	} catch (IOException ex) {
		NodeLogger.getLogger(getClass()).error(
				"Could not create temporary directory for Java Snippet: "
						+ ex.getMessage(), ex);
		// use the standard temp directory instead
		tempDir = new File(KNIMEConstants.getKNIMETempDir());
	}
	m_tempClassPathDir = tempDir;
	m_uid = createID();
}
 
开发者ID:pavloff-de,项目名称:spark4knime,代码行数:19,代码来源:JavaSnippet.java

示例2: toFile

import org.knime.core.util.FileUtil; //导入依赖的package包/类
/** Convert file location to File. Also accepts file in URL format
 * (e.g. local drop files as URL).
 * @param location The location string.
 * @return The file to the location
 * @throws InvalidSettingsException if argument is null, empty or the file
 * does not exist.
 */
public static final File toFile(final String location) throws InvalidSettingsException {
    CheckUtils.checkSetting(StringUtils.isNotEmpty(location), "Invalid (empty) jar file location");
    File result;
    URL url = null;
    try {
        url = new URL(location);
    } catch (MalformedURLException mue) {
    }
    if (url != null) {
        result = FileUtil.getFileFromURL(url);
    } else {
        result = new File(location);
    }
    CheckUtils.checkSetting(result != null && result.exists(),
            "Can't read file \"%s\"; invalid class path", location);
    return result;
}
 
开发者ID:pavloff-de,项目名称:spark4knime,代码行数:25,代码来源:JavaSnippetUtil.java

示例3: readBlob

import org.knime.core.util.FileUtil; //导入依赖的package包/类
protected DataCell readBlob(ResultSet m_result,int index0) throws SQLException,IOException
	{

       InputStream is = m_result.getBinaryStream(index0);
       if (m_result.wasNull() || is == null) {
           return DataType.getMissingCell();
       } else {
           InputStreamReader reader = new InputStreamReader(is);
           StringWriter writer = new StringWriter();
           FileUtil.copy(reader, writer);
           reader.close();
           writer.close();
           return new StringCell(writer.toString());
       }

}
 
开发者ID:lindenb,项目名称:knime4bio,代码行数:17,代码来源:AbstractSqlNodeModel.java

示例4: getSparkContext

import org.knime.core.util.FileUtil; //导入依赖的package包/类
/**
 * Create new SparkContext if not already created and cache it for next use.
 * 
 * @see SPARK-2243 Only one SparkContext may be running in this JVM. To
 *      ignore this error, set spark.driver.allowMultipleContexts = true
 * @param master
 *            <code>String</code> to connect to
 * @throws NullPointerException
 *             If master is null
 * @return <code>SparkContext</code>
 */
public static synchronized JavaSparkContext getSparkContext(String master) {
	if (sparkContext == null) {
		if (master == null) {
			throw new NullPointerException("Master should be not null");
		}
		if (System.getProperty("hadoop.home.dir") == null) {
			try {
				// some operations need Apache Hadoop
				// HADOOP_HOME is set if not exists
				System.setProperty(
						"hadoop.home.dir",
						FileUtil.getFileFromURL(
								FileLocator.toFileURL(FileLocator.find(
										Platform.getBundle("de.pavloff.spark4knime"),
										new Path("hadoop"), null)))
								.getPath().toString());
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		SparkConf conf = new SparkConf().setMaster(master)
				.setAppName("KnimeSparkApplication")
				// need to overwrite JSnippet classes
				.set("spark.files.overwrite", "true");
		sparkContext = new JavaSparkContext(conf);
	}
	return sparkContext;
}
 
开发者ID:pavloff-de,项目名称:spark4knime,代码行数:40,代码来源:SparkContexter.java

示例5: onJarURLAdd

import org.knime.core.util.FileUtil; //导入依赖的package包/类
@SuppressWarnings("null")
private void onJarURLAdd() {
    DefaultListModel<String> model = (DefaultListModel<String>)m_addJarList.getModel();
    Set<String> hash = new HashSet<>(Collections.list(model.elements()));
    String input = "knime://knime.workflow/example.jar";
    boolean valid;
    do {
        input = JOptionPane.showInputDialog(this, "Enter a \"knime:\" URL to a JAR file", input);
        if (StringUtils.isEmpty(input)) {
            valid = true;
        } else {
            URL url;
            try {
                url = new URL(input);
                File file = FileUtil.getFileFromURL(url);
                CheckUtils.checkArgument(file != null, "Could not resolve to local file");
                CheckUtils.checkArgument(file.exists(),
                    "File does not exists; location resolved to\n%s", file.getAbsolutePath());
                valid = true;
            } catch (MalformedURLException | IllegalArgumentException mfe) {
                JOptionPane.showMessageDialog(this, "Invalid URL\n" + mfe.getMessage(),
                    "Error parsing URL", JOptionPane.ERROR_MESSAGE);
                valid = false;
                continue;
            }
        }
    } while (!valid);
    if (!StringUtils.isEmpty(input) && hash.add(input)) {
        model.addElement(input);
    }
}
 
开发者ID:pavloff-de,项目名称:spark4knime,代码行数:32,代码来源:JarListPanel.java

示例6: PluginFileTemplateRepositoryProvider

import org.knime.core.util.FileUtil; //导入依赖的package包/类
/**
 * @param symbolicName
 *            the name of the bundle like "org.nime.jsnipptes"
 * @param relativePath
 *            the path to the repositories base folder, i.e. "/jsnippes"
 */
public PluginFileTemplateRepositoryProvider(final String symbolicName,
		final String relativePath) {
	try {
		Bundle bundle = Platform.getBundle(symbolicName);
		URL url = FileLocator.find(bundle, new Path(relativePath), null);
		m_file = FileUtil.getFileFromURL(FileLocator.toFileURL(url));
	} catch (Exception e) {
		logger.error("Cannot locate jsnippet templates in path "
				+ symbolicName + " of the bundle " + relativePath + ".", e);
	}
}
 
开发者ID:pavloff-de,项目名称:spark4knime,代码行数:18,代码来源:PluginFileTemplateRepositoryProvider.java

示例7: createJSnippetJarFile

import org.knime.core.util.FileUtil; //导入依赖的package包/类
/**
 * Give jar file with all *.class files returned by
 * getManipulators(ALL_CATEGORY).
 * 
 * @return file object of a jar file with all compiled manipulators
 * @throws IOException
 *             if jar file cannot be created
 */
private static File createJSnippetJarFile() throws IOException {
	File jarFile = FileUtil.createTempFile("jsnippet", ".jar", new File(
			KNIMEConstants.getKNIMETempDir()), true);
	JarOutputStream jar = new JarOutputStream(new FileOutputStream(jarFile));

	Collection<Object> classes = new ArrayList<Object>();
	classes.add(AbstractJSnippet.class);
	classes.add(Abort.class);
	classes.add(Cell.class);
	classes.add(ColumnException.class);
	classes.add(FlowVariableException.class);
	classes.add(Type.class);
	classes.add(TypeException.class);
	classes.add(NodeLogger.class);
	classes.add(KNIMEConstants.class);

	// create tree structure for classes
	DefaultMutableTreeNode root = createTree(classes);
	try {
		createJar(root, jar, null);
	} finally {
		jar.close();
	}

	return jarFile;
}
 
开发者ID:pavloff-de,项目名称:spark4knime,代码行数:35,代码来源:JavaSnippet.java

示例8: createJar

import org.knime.core.util.FileUtil; //导入依赖的package包/类
private static void createJar(final DefaultMutableTreeNode node,
		final JarOutputStream jar, final String path) throws IOException {
	Object o = node.getUserObject();
	if (o instanceof String) {
		// folders must end with a "/"
		String subPath = null == path ? "" : (path + (String) o + "/");
		if (path != null) {
			JarEntry je = new JarEntry(subPath);
			jar.putNextEntry(je);
			jar.flush();
			jar.closeEntry();
		}
		for (int i = 0; i < node.getChildCount(); i++) {
			DefaultMutableTreeNode child = (DefaultMutableTreeNode) node
					.getChildAt(i);
			createJar(child, jar, subPath);
		}
	} else {
		Class<?> cl = (Class<?>) o;
		String className = cl.getSimpleName();
		className = className.concat(".class");
		JarEntry entry = new JarEntry(path + className);
		jar.putNextEntry(entry);

		ClassLoader loader = cl.getClassLoader();
		InputStream inStream = loader.getResourceAsStream(cl.getName()
				.replace('.', '/') + ".class");

		FileUtil.copy(inStream, jar);
		inStream.close();
		jar.flush();
		jar.closeEntry();

	}
}
 
开发者ID:pavloff-de,项目名称:spark4knime,代码行数:36,代码来源:JavaSnippet.java

示例9: createJSnippetJarFileForSpark

import org.knime.core.util.FileUtil; //导入依赖的package包/类
/**
 * Creates a jar from JSnippet for Spark executor
 * 
 * @param snippetLoader
 * @throws IOException
 * @throws ClassNotFoundException
 * 
 * @author Oleg Pavlov, University of Heidelberg
 */
@SuppressWarnings("unchecked")
private void createJSnippetJarFileForSpark(ClassLoader snippetLoader)
		throws IOException, ClassNotFoundException {
	if (m_snippetJarFile == null) {
		m_snippetJarFile = FileUtil.createTempFile("jsnippetForSpark-",
				".jar", m_tempClassPathDir, true);
	}
	JarOutputStream jar = new JarOutputStream(new FileOutputStream(
			m_snippetJarFile));
	File[] classes = m_tempClassPathDir.listFiles(new FilenameFilter() {
		@Override
		public boolean accept(File dir, String name) {
			return name.endsWith(".class");
		}
	});

	try {
		for (File f : classes) {
			String fileName = f.getName();
			JarEntry entry = new JarEntry(fileName);
			jar.putNextEntry(entry);

			String className = fileName.substring(0,
					fileName.lastIndexOf("."));
			Class<? extends AbstractJSnippet> o = (Class<? extends AbstractJSnippet>) snippetLoader
					.loadClass(className);
			Class<?> cl = (Class<?>) o;

			ClassLoader loader = cl.getClassLoader();
			InputStream inStream = loader.getResourceAsStream(className
					.replace('.', '/') + ".class");

			FileUtil.copy(inStream, jar);
			inStream.close();
			jar.flush();
			jar.closeEntry();
		}
	} finally {
		jar.close();
	}

	JavaSparkContext sc = SparkContexter.getSparkContext(null);
	sc.addJar(m_snippetJarFile.getPath());
}
 
开发者ID:pavloff-de,项目名称:spark4knime,代码行数:54,代码来源:JavaSnippet.java

示例10: finalize

import org.knime.core.util.FileUtil; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
protected void finalize() throws Throwable {
	FileUtil.deleteRecursively(m_tempClassPathDir);
	super.finalize();
}
 
开发者ID:pavloff-de,项目名称:spark4knime,代码行数:9,代码来源:JavaSnippet.java

示例11: getFile

import org.knime.core.util.FileUtil; //导入依赖的package包/类
public static File getFile(String fileName) throws InvalidPathException, MalformedURLException {
	return FileUtil.getFileFromURL(FileUtil.toURL(fileName));
}
 
开发者ID:SiLeBAT,项目名称:BfROpenLab,代码行数:4,代码来源:KnimeUtils.java


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