Java Code Examples for org.eclipse.core.runtime.FileLocator#openStream()

The following examples show how to use org.eclipse.core.runtime.FileLocator#openStream() . 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: HtmlFolder.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
private static void extractFolder(Bundle bundle, String zipPath)
		throws Exception {
	File dir = getDir(bundle);
	if (dir.exists())
		FileUtils.deleteDirectory(dir);
	dir.mkdirs();
	writeVersion(bundle);
	InputStream zipStream = FileLocator.openStream(bundle,
			new Path(zipPath), false);
	File zipFile = new File(dir, "@temp.zip");
	try (FileOutputStream out = new FileOutputStream(zipFile)) {
		IOUtils.copy(zipStream, out);
	}
	ZipUtil.unpack(zipFile, dir);
	if (!zipFile.delete())
		zipFile.deleteOnExit();
}
 
Example 2
Source File: OmnisharpStreamConnectionProvider.java    From aCute with Eclipse Public License 2.0 5 votes vote down vote up
/**
 *
 * @return path to server, unzipping it if necessary. Can be null is fragment is missing.
 */
private @Nullable File getServer() throws IOException {
	File serverPath = new File(AcutePlugin.getDefault().getStateLocation().toFile(), "omnisharp-roslyn"); //$NON-NLS-1$
	if (!serverPath.exists()) {
		serverPath.mkdirs();
		try (
			InputStream stream = FileLocator.openStream(AcutePlugin.getDefault().getBundle(), new Path("omnisharp-roslyn.tar"), true); //$NON-NLS-1$
			TarArchiveInputStream tarStream = new TarArchiveInputStream(stream);
		) {
			TarArchiveEntry entry = null;
			while ((entry = tarStream.getNextTarEntry()) != null) {
				if (!entry.isDirectory()) {
					File targetFile = new File(serverPath, entry.getName());
					targetFile.getParentFile().mkdirs();
					InputStream in = new BoundedInputStream(tarStream, entry.getSize()); // mustn't be closed
					try (
						FileOutputStream out = new FileOutputStream(targetFile);
					) {
						IOUtils.copy(in, out);
						if (!Platform.OS_WIN32.equals(Platform.getOS())) {
							int xDigit = entry.getMode() % 10;
							targetFile.setExecutable(xDigit > 0, (xDigit & 1) == 1);
							int wDigit = (entry.getMode() / 10) % 10;
							targetFile.setWritable(wDigit > 0, (wDigit & 1) == 1);
							int rDigit = (entry.getMode() / 100) % 10;
							targetFile.setReadable(rDigit > 0, (rDigit & 1) == 1);
						}
					}
				}
			}
		}
	}
	return serverPath;
}
 
Example 3
Source File: JavaScriptPipelineWizard.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected InputStream createInputSource () throws Exception
{
    Type type = this.page.getTypeSelection ();
    if ( type == null )
    {
        type = Type.EMPTY;
    }
    return FileLocator.openStream ( Activator.getDefault ().getBundle (), new Path ( String.format ( "templates/%s", type.getResourceName () ) ), true );
}
 
Example 4
Source File: KickStartNewProjectAction.java    From solidity-ide with Eclipse Public License 1.0 5 votes vote down vote up
protected void createExample(IProject project) {
	Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
	try (InputStream stream = FileLocator.openStream(bundle, new Path("examples/greeter.sol"), false)) {
		IFile file = project.getFile("greeter.sol");
		file.create(stream, true, null);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 5
Source File: RascalBundleManifest.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
private InputStream manifest(Bundle bundle) {
	URL rascalMF = bundle.getResource(META_INF_RASCAL_MF);

	try {
		if (rascalMF != null) {
			return FileLocator.openStream(bundle, new Path(META_INF_RASCAL_MF), false);
		}
	}
	catch (IOException e) {
		// do nothing, it's expected that some bundles do not have RASCAL.MF files
	}
	return null;
}
 
Example 6
Source File: ResourceUtils.java    From http4e with Apache License 2.0 5 votes vote down vote up
public static InputStream getBundleResourceStream( String pluginID, String uri){
   try {
      if (Utils.isIDE()) {
         return FileLocator.openStream(Platform.getBundle(pluginID), new Path(uri), false);
      } else {
         return new FileInputStream(uri);
      }
   } catch (Throwable e) {
      ExceptionHandler.handle(e);
   }
   return null;
}
 
Example 7
Source File: ResourceUtils.java    From http4e with Apache License 2.0 5 votes vote down vote up
public static InputStream getBundleResourceStream2( String pluginID, String uri) throws IOException{
   if (Utils.isIDE()) {
      return FileLocator.openStream(Platform.getBundle(pluginID), new Path(uri), false);
   } else {
      return new FileInputStream(uri);
   }
}
 
Example 8
Source File: GTestRunner.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
private CharSequence readSourceFile(String sourceFile) throws IOException {
		Bundle bundle = getTestBundle();
//		System.out.println("[GTestRunner] Loaded bundle " + bundle.getSymbolicName());
		InputStream is = FileLocator.openStream(bundle, new Path(sourceFile), false);
		Reader reader = new InputStreamReader(is);
		char[] buffer = new char[4096];
		StringBuilder sb = new StringBuilder(buffer.length);
		int count;
		while ((count = reader.read(buffer)) != -1) {
			sb.append(buffer, 0, count);
		}
		reader.close();
		is.close();
		return sb;
	}
 
Example 9
Source File: TestFileCopier.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void copyFileFromBundle(Bundle bundle, IPath sourcePath, IPath targetPath) {
	try {
		InputStream is = FileLocator.openStream(bundle, sourcePath, false);
		createFile(targetPath, is);
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
}
 
Example 10
Source File: CSSMetadataReader.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected InputStream getSchemaStream()
{
	try
	{
		return FileLocator.openStream(CSSCorePlugin.getDefault().getBundle(),
				Path.fromPortableString(METADATA_SCHEMA_XML), false);
	}
	catch (IOException e)
	{
		return this.getClass().getResourceAsStream(METADATA_SCHEMA_XML);
	}
}
 
Example 11
Source File: JSMetadataReader.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected InputStream getSchemaStream()
{
	try
	{
		return FileLocator.openStream(JSCorePlugin.getDefault().getBundle(),
				Path.fromPortableString(JS_METADATA_SCHEMA), false);
	}
	catch (IOException e)
	{
		return getClass().getResourceAsStream(JS_METADATA_SCHEMA);
	}
}
 
Example 12
Source File: VSDocReader.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected InputStream getSchemaStream()
{
	try
	{
		return FileLocator.openStream(JSCorePlugin.getDefault().getBundle(),
				Path.fromPortableString(METADATA_SCHEMA_XML), false);
	}
	catch (IOException e)
	{
		return this.getClass().getResourceAsStream(METADATA_SCHEMA_XML);
	}
}
 
Example 13
Source File: HTMLMetadataReader.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected InputStream getSchemaStream()
{
	try
	{
		return FileLocator.openStream(HTMLPlugin.getDefault().getBundle(),
				Path.fromPortableString(HTML_METADATA_SCHEMA), false);
	}
	catch (IOException e)
	{
		return this.getClass().getResourceAsStream(HTML_METADATA_SCHEMA);
	}
}
 
Example 14
Source File: RcpActivator.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Returns the file found at the specified path as an input stream
 * 
 * @param path
 *            The path to the file to load an input stream for (relative to
 *            the plugin)
 * @return The file found at the specified path as an input stream
 */
public static InputStream getStream(String path) {
	try {
		return FileLocator.openStream(
				plugin.getBundle(), new Path(path), false);
	} catch (final IOException e) {
		return null;
	}
}
 
Example 15
Source File: CreateProjectOperation.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
private static InputStream bundleResource ( final IPath location ) throws IOException
{
    return FileLocator.openStream ( Activator.getDefault ().getBundle (), location, true );
}
 
Example 16
Source File: JavaScriptItemSelectorWizard.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected InputStream createInputSource () throws Exception
{
    return FileLocator.openStream ( Activator.getDefault ().getBundle (), new Path ( "templates/empty.icm_js" ), true );
}