本文整理了Java中org.eclipse.emf.common.util.URI.createFileURI()
方法的一些代码示例,展示了URI.createFileURI()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。URI.createFileURI()
方法的具体详情如下:
包路径:org.eclipse.emf.common.util.URI
类名称:URI
方法名:createFileURI
[英]Static factory method based on parsing a java.io.File path string. The pathName
is converted into an appropriate form, as follows: platform specific path separators are converted to /
; the path is encoded; and a "file" scheme, if the path is File#isAbsolute(), and, if missing, a leading /
, are added to an absolute path. The result is then parsed the same as if using #createURI(String).
The encoding step escapes all spaces, #
characters, and other characters disallowed in URIs, as well as ?
, which would delimit a path from a query. Decoding is automatically performed by #toFileString, and can be applied to the values returned by other accessors via the static #decode(String) method.
A relative path with a specified device (something like C:myfile.txt
) cannot be expressed as a valid URI. An absolute URI, i.e., one with file:
will only be returned if the pathName
itself is File#isAbsolute(). In other words, a relative path will yield a #isRelative() URI, and in particular on Windows, a path is absolute only if the device is specified, e.g., C:/myfile.text
is absolute but /myfile.text
is relative on Windows though absolute on Unix-style file systems.
[中]基于解析java的静态工厂方法。伊奥。文件路径字符串。pathName
被转换成适当的形式,如下所示:特定于平台的路径分隔符被转换成[$1$];路径被编码;如果路径为file#isAbsolute(),则会向绝对路径添加一个“文件”方案,如果缺少,则会向绝对路径添加一个前导[$2$]。然后像使用#createURI(字符串)一样解析结果。
编码步骤将转义所有空格、#
字符和URI中不允许的其他字符,以及?
,这将从查询中分隔路径。解码由#toFileString自动执行,并可通过静态#decode(String)方法应用于其他访问器返回的值。
与指定设备(例如C:myfile.txt
)的相对路径不能表示为有效的URI。只有当pathName
本身是文件#isAbsolute()时,才会返回绝对URI,即带有file:
的URI。换句话说,相对路径将产生#isRelative()URI,尤其是在Windows上,只有在指定了设备时,路径才是绝对的,例如,C:/myfile.text
是绝对的,但/myfile.text
在Windows上是相对的,尽管在Unix风格的文件系统上是绝对的。
代码示例来源:origin: opensourceBIM/BIMserver
public void writeToEcore(File file) {
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
Resource resource = resourceSet.createResource(URI.createFileURI(file.getAbsolutePath()));
for (EPackage ePackage : packages.values()) {
resource.getContents().add(ePackage);
}
try {
resource.save(null);
} catch (IOException e) {
LOGGER.error("", e);
}
}
代码示例来源:origin: org.eclipse.xtext/builder
public URI getBuilderStateURI() {
File location = getBuilderStateLocation();
if (location == null)
return null;
URI fileURI = URI.createFileURI(location.getAbsolutePath());
return fileURI;
}
代码示例来源:origin: org.wso2.wsdl.validator/wsdl-validator
private URI createURI(String uriString)
{
if (hasProtocol(uriString))
return URI.createURI(uriString);
else
return URI.createFileURI(uriString);
}
代码示例来源:origin: openhab/openhab-core
private URI createURI(String path) {
if (path == null) {
throw new IllegalArgumentException();
}
URI uri = URI.createURI(path);
if (uri.isRelative()) {
URI resolvedURI = URI.createFileURI(new File(path).getAbsolutePath());
return resolvedURI;
}
return uri;
}
代码示例来源:origin: de.dentrassi.eclipse.neoscada.core/org.eclipse.scada.da.server.exec
/**
* Default Constructor
*
* @throws XmlException
* @throws IOException
* @throws ConfigurationException
*/
public Hive () throws IOException, ConfigurationException
{
this ( new XmlConfigurator ( URI.createFileURI ( "configuration.xml" ) ) );
}
代码示例来源:origin: org.jresearch.flexess.models/org.jresearch.flexess.models.uam
/**
* @return resource with security object and package
*/
public static Resource loadSecurityModel(final String securityFile) {
// Get the URI of the model file.
final File secFile = new File(securityFile);
final URI securityFileURI = URI.createFileURI(secFile.getAbsolutePath());
return loadSecurityModel(securityFileURI);
}
代码示例来源:origin: org.eclipse.xtext/org.eclipse.xtext.util
/**
* In contrast to {@link URI#createFileURI(String)}, this appends a trailing path separator. This ensures
* the resulting URI can be used with methods like {@link #isPrefixOf(URI, URI)}, {@link URI#resolve(URI)} and
* {@link URI#deresolve(URI)}
*/
public static URI createFolderURI(File file) {
URI uri = URI.createFileURI(file.getAbsolutePath());
return toFolderURI(uri);
}
代码示例来源:origin: org.wso2.wsdl.validator/wsdl-validator
private static URI createURI(String uriString)
{
if (hasProtocol(uriString))
return URI.createURI(uriString);
else
return URI.createFileURI(uriString);
}
代码示例来源:origin: com.reprezen.genflow/genflow-tests
private URI getRestFileURI(Description description) {
String sampleRestFilePath = getSampleRestName(description);
URI modelURI = URI.createFileURI(Resources.getResource("models/dsl").getFile());
for (String nextSegment : sampleRestFilePath.split("/")) {
modelURI = modelURI.appendSegment(nextSegment);
}
return modelURI;
}
代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.eclipse.e4.ui.workbench
private Resource createResource() {
if (saveAndRestore) {
URI saveLocation = URI.createFileURI(getWorkbenchSaveLocation().getAbsolutePath());
return resourceSetImpl.createResource(saveLocation);
}
return resourceSetImpl.createResource(URI.createURI("workbench.xmi")); //$NON-NLS-1$
}
代码示例来源:origin: de.dentrassi.eclipse.neoscada.core/org.eclipse.scada.da.server.exec
private void processFile ( final File file, final Hive hive ) throws ConfigurationException
{
try
{
final RootType subRoot = parse ( URI.createFileURI ( file.getAbsolutePath () ) );
configure ( subRoot, hive );
}
catch ( final IOException e )
{
throw new ConfigurationException ( "Failed to parse sub xml document: " + file, e );
}
}
代码示例来源:origin: org.eclipse.neoscada.core/org.eclipse.scada.da.server.exec
private void processFile ( final File file, final Hive hive ) throws ConfigurationException
{
try
{
final RootType subRoot = parse ( URI.createFileURI ( file.getAbsolutePath () ) );
configure ( subRoot, hive );
}
catch ( final IOException e )
{
throw new ConfigurationException ( "Failed to parse sub xml document: " + file, e );
}
}
代码示例来源:origin: org.eclipse.xtext/ui
public static URI getUriForPackageFragmentRoot(IPackageFragmentRoot root) {
IResource underlyingResource = root.getResource();
if (underlyingResource == null) {
return URI.createFileURI(root.getPath().toString());
} else {
return URI.createPlatformResourceURI(underlyingResource.getFullPath().toString(), true);
}
}
代码示例来源:origin: de.dentrassi.eclipse.neoscada.ide/org.eclipse.scada.configuration.world.lib
private void processProfile ( final File output ) throws IOException
{
final Profile profile = makeProfile ( this.app );
final File profileFile = new File ( output, this.app.getName () + ".profile.xml" ); //$NON-NLS-1$
final ResourceSet rs = new ResourceSetImpl ();
final Resource r = rs.createResource ( URI.createFileURI ( profileFile.toString () ) );
r.getContents ().add ( EcoreUtil.copy ( profile ) );
final Map<Object, Object> options = new HashMap<> ();
options.put ( XMLResource.OPTION_ENCODING, "UTF-8" ); //$NON-NLS-1$
r.save ( options );
}
代码示例来源:origin: org.eclipse.neoscada.ide/org.eclipse.scada.configuration.world.lib
private void processProfile ( final File output ) throws IOException
{
final Profile profile = makeProfile ( this.app );
final File profileFile = new File ( output, this.app.getName () + ".profile.xml" ); //$NON-NLS-1$
final ResourceSet rs = new ResourceSetImpl ();
final Resource r = rs.createResource ( URI.createFileURI ( profileFile.toString () ) );
r.getContents ().add ( EcoreUtil.copy ( profile ) );
final Map<Object, Object> options = new HashMap<> ();
options.put ( XMLResource.OPTION_ENCODING, "UTF-8" ); //$NON-NLS-1$
r.save ( options );
}
代码示例来源:origin: org.jresearch.flexess.models/org.jresearch.flexess.models.uam
public static void save(final SecurityModel model, final String fileName) throws IOException {
final File file = new File(fileName);
final URI fileURI = URI.createFileURI(file.getAbsolutePath());
final ResourceSet resourceSet = new ResourceSetImpl();
final Resource secResource = resourceSet.createResource(fileURI);
model.setName(getModelName(fileURI));
secResource.getContents().add(model);
save(secResource);
}
代码示例来源:origin: org.eclipse.xtext/org.eclipse.xtext.ide
@Deprecated
private URI deprecatedToBaseDir(final InitializeParams params) {
String _rootPath = params.getRootPath();
boolean _tripleNotEquals = (_rootPath != null);
if (_tripleNotEquals) {
return this._uriExtensions.toUri(this._uriExtensions.toUriString(URI.createFileURI(params.getRootPath())));
}
return null;
}
代码示例来源:origin: org.eclipse.epsilon/epsilon-hutn
private static Ast initialiseAstModel() {
final Ast astModel = AntlrAstFactory.eINSTANCE.createAst();
final ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new EcoreResourceFactoryImpl());
final Resource resource = resourceSet.createResource(URI.createFileURI("default.ecore"));
resource.getContents().add(astModel);
return astModel;
}
代码示例来源:origin: com.reprezen.rapidml/com.reprezen.rapidml
private ZenModel loadDslModel(String path) {
URI uri = URI.createFileURI(path);
return new DslRestModelLoader(new RepreZenXtextResourceSet()).load(uri);
}
代码示例来源:origin: atlanmod/NeoEMF
@Test
void testCreateLocalUriWithUri() throws IOException {
final URI uri = factory.createLocalUri(URI.createFileURI(currentTempFile().getAbsolutePath()));
assertThat(uri.isFile()).isTrue();
assertThat(uri.scheme()).isEqualTo(SCHEME);
assertThat(new File(uri.toFileString())).isEqualTo(currentTempFile());
}
内容来源于网络,如有侵权,请联系作者删除!