當前位置: 首頁>>代碼示例>>Java>>正文


Java IFile.getContents方法代碼示例

本文整理匯總了Java中org.eclipse.core.resources.IFile.getContents方法的典型用法代碼示例。如果您正苦於以下問題:Java IFile.getContents方法的具體用法?Java IFile.getContents怎麽用?Java IFile.getContents使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.core.resources.IFile的用法示例。


在下文中一共展示了IFile.getContents方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getFileContent

import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
private Map<Integer, String> getFileContent(IFile file) {
	String fileEnding = FileUtil.getLineSeparator(file);
	Map<Integer, String> content = Maps.newHashMap();
	try (BufferedReader reader = new BufferedReader(
			new InputStreamReader(file.getContents(true), file.getCharset()));) {
		String line = reader.readLine();
		int lastLineNumber = 1;
		while (line != null) {
			content.put(lastLineNumber, line + fileEnding);
			line = reader.readLine();
			lastLineNumber++;
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return content;
}
 
開發者ID:Yakindu,項目名稱:solidity-ide,代碼行數:18,代碼來源:SolidityMarkerCreator.java

示例2: generateUniqueJobIdForPastedFiles

import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
private void generateUniqueJobIdForPastedFiles(List<IFile> pastedFileList) {
	for (IFile file : pastedFileList) {
		try(ByteArrayOutputStream outStream = new ByteArrayOutputStream();
				InputStream inputStream=file.getContents()) {
			Container container = (Container) CanvasUtils.INSTANCE.fromXMLToObject(inputStream);
			container.setUniqueJobId(GenerateUniqueJobIdUtil.INSTANCE.generateUniqueJobId());
		CanvasUtils.INSTANCE.fromObjectToXML(container,outStream);
			file.setContents(new ByteArrayInputStream(outStream.toByteArray()), true, false, null);
			

		} catch (CoreException | NoSuchAlgorithmException | IOException exception) {
			logger.warn("Exception while generating unique job id for pasted files.");

		} 
	}
	
}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:18,代碼來源:PasteHandler.java

示例3: createXmlFilesForPastedJobFiles

import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
private void createXmlFilesForPastedJobFiles(List<IFile> pastedFileList) {
	for (IFile file : pastedFileList) {
		try(InputStream inputStream=file.getContents()) {
			Container container = (Container) CanvasUtils.INSTANCE.fromXMLToObject(inputStream);
			IPath path = file.getFullPath().removeFileExtension().addFileExtension(XML);
			IFile xmlFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
			if(xmlFile.exists()){
				int userInput = showErrorMessage(xmlFile,xmlFile.getName()+" already exists.Do you want to replace it?");
				if (userInput == SWT.YES) {
					ConverterUtil.INSTANCE.convertToXML(container, true, xmlFile, null);
				} 
			}
			else {
				ConverterUtil.INSTANCE.convertToXML(container, true, xmlFile, null);
			}

		} catch (CoreException | InstantiationException | IllegalAccessException | InvocationTargetException
				| NoSuchMethodException | IOException exception) {
			logger.error("Error while generating xml files for pasted job files", exception);

		} 
	}
}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:24,代碼來源:PasteHandler.java

示例4: loadBuildProperties

import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
private void loadBuildProperties() {
	String buildPropFilePath = buildPropFilePath();
	IPath bldPropPath = new Path(buildPropFilePath);
	IFile iFile = ResourcesPlugin.getWorkspace().getRoot().getFile(bldPropPath);
	try {
		InputStream reader = iFile.getContents();
		buildProps.load(reader);

	} catch (CoreException | IOException e) {
		MessageDialog.openError(Display.getDefault().getActiveShell(), "Error",
				"Exception occurred while loading build properties from file -\n" + e.getMessage());
	}

	Enumeration<?> propertyNames = buildProps.propertyNames();
	populateTextBoxes(propertyNames);

}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:18,代碼來源:RunConfigDialog.java

示例5: createThisResource

import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
/**
 * Creates {@link N4JSResource} in new {@link ResourceSet}. Created resource has uri of processed xt file and its
 * context. During creation resource factory is obtained dynamically to preserve bindings created by XPECT (see
 * {@link org.eclipse.xpect.xtext.lib.tests.ValidationTestModuleSetup#configure})
 *
 */
@Creates(ThisResource.class)
public XtextResource createThisResource() throws IOException, CoreException {

	Entry<IFile, IProject> file2project = findTestResources();
	IFile xpectFile = file2project.getKey();
	IProject userProject = file2project.getValue();

	ResourceSet resourceSet = resourceSetProvider.get(userProject);
	URI xpectFilePlatformURI = URI.createPlatformResourceURI(xpectFile.getFullPath().toString(),
			ENCODE_PLATFORM_RESOURCE_URIS);

	Injector injector = IXtInjectorProvider.INSTANCE.getInjector(ctx.get(XpectJavaModel.class),
			xpectFilePlatformURI);
	Resource resource = injector.getInstance(IResourceFactory.class).createResource(xpectFilePlatformURI);

	resourceSet.getResources().add(resource);
	InputStream input = xpectFile.getContents();

	try {
		resource.load(input, null);
	} finally {
		if (input != null)
			input.close();
	}
	return (XtextResource) resource;
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:33,代碼來源:N4IDEXpectFileSetup.java

示例6: getArchiveStream

import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
private ZipInputStream getArchiveStream(final URI archiveLocation) throws CoreException, IOException {
	if (archiveLocation.isPlatformResource()) {
		IFile workspaceFile = workspace.getFile(new Path(archiveLocation.toPlatformString(true)));
		return new ZipInputStream(workspaceFile.getContents());
	} else {
		return new ZipInputStream(new URL(archiveLocation.toString()).openStream());
	}

}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:10,代碼來源:EclipseBasedN4JSWorkspace.java

示例7: YuiJsMinifier

import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
public YuiJsMinifier(MinifyBuilder builder, IFile srcFile, IFile destFile, 
		OutputStream out, IEclipsePreferences prefs)
	throws IOException, CoreException {
	super (builder);
	preserveSemicolons = prefs.getBoolean(
			PrefsAccess.preferenceKey(srcFile, MinifyBuilder.YUI_PRESERVE_SEMICOLONS), true);
	disableOptimizations = prefs.getBoolean(
			PrefsAccess.preferenceKey(srcFile, MinifyBuilder.YUI_DISABLE_OPTIMIZATIONS), true);
	outCharset = destFile.exists() ? destFile.getCharset() : srcFile.getCharset();
	writer = new OutputStreamWriter(out, outCharset);
	compressor = new JavaScriptCompressor(new BufferedReader(
			new InputStreamReader(srcFile.getContents(), srcFile.getCharset())), 
			new YuiMinifier.MinifyErrorHandler(srcFile));
}
 
開發者ID:mnlipp,項目名稱:EclipseMinifyBuilder,代碼行數:15,代碼來源:YuiJsMinifier.java

示例8: getStringContent

import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
public static String getStringContent(IFile file) throws CoreException, IOException {
	BufferedReader r = new BufferedReader(new InputStreamReader(file.getContents(), StandardCharsets.UTF_8));     
    String str = null;
    StringBuilder sb = new StringBuilder();
    while ((str = r.readLine()) != null) {
    	sb.append(str+'\n');
    }
	return sb.toString();     
}
 
開發者ID:eclipse,項目名稱:gemoc-studio,代碼行數:10,代碼來源:IFileUtils.java

示例9: stroeFileInWorkspace

import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
private void stroeFileInWorkspace(IFile iFile) {
	InputStream filenputStream = null;
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	if (iFile != null) {
		try {
			filenputStream = iFile.getContents(true);
			if (filenputStream != null) {
				XStream xStream = new XStream();
				Container container = (Container) xStream.fromXML(filenputStream);
				filenputStream.close();
				container = deleteSubjobProperties(container);
				if (container != null) {
					xStream.toXML(container, out);
					if (iFile.exists())
						iFile.setContents(new ByteArrayInputStream(out.toByteArray()), true,	false, null);
				}
			}
		} catch (FileNotFoundException eFileNotFoundException) {
			logger.error("Exception occurred while saving sub-graph into local file-system when editor disposed",
					eFileNotFoundException);
		} catch (IOException ioException) {
			logger.error("Exception occurred while saving sub-graph into local file-system when editor disposed",
					ioException);
		} catch (CoreException coreException) {
			logger.error("Exception occurred while saving sub-graph into local file-system when editor disposed",
					coreException);
		}
	}
}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:30,代碼來源:ELTGraphicalEditor.java

示例10: getStartEndOffsetFromXML

import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
/**
 * Returns character offsets from line numbers from JFace Text Document object.
 */
private static int[] getStartEndOffsetFromXML(final XMLStreamReader streamReader,
    final IFile file, final EventMemento memento, final EventMemento current) {
  final int[] offsetStartEnd = new int[2];
  try {
    String charsetName = streamReader.getCharacterEncodingScheme();
    if (charsetName == null) {
      charsetName = "UTF-8";
    }
    final Scanner scanner = new Scanner(file.getContents(), charsetName);
    final IDocument document = new Document(scanner.useDelimiter("\\A").next());
    scanner.close();

    int start = 0;
    int end = 0;

    final IRegion startRegion = document.getLineInformation(memento.getLineNumber() - 1);
    start = startRegion.getOffset() + memento.getColumnNumber() - 2;
    final IRegion endRegion = document.getLineInformation(current.getLineNumber());
    end = endRegion.getOffset() - 1;

    offsetStartEnd[0] = start;
    offsetStartEnd[1] = end;

  } catch (final BadLocationException e1) {
    // e1.printStackTrace();
    System.out
        .println(e1.toString() + " --> in MarkerFactory's getStartEndOffsetFromXML function");
  } catch (final CoreException e) {
    e.printStackTrace();
  }
  return offsetStartEnd;
}
 
開發者ID:ModelWriter,項目名稱:Tarski,代碼行數:36,代碼來源:MarkerFactory.java

示例11: Source

import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
public Source(IFile file) {
	String seperator = FileUtil.getLineSeparator(file);
	try (BufferedReader reader = new BufferedReader(
			new InputStreamReader(file.getContents(true), file.getCharset()));) {
		String line = reader.readLine();
		while (line != null) {
			content += line + seperator;
			line = reader.readLine();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:Yakindu,項目名稱:solidity-ide,代碼行數:14,代碼來源:Source.java

示例12: getContentForResourceUri

import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
/**
 * Helper method to get the content of an resource at uri. Takes care of the encoding.
 *
 * @param uri
 *            URI to resource
 * @return content as string
 * @throws Exception
 *             in case of io or uri issues
 */
private String getContentForResourceUri(URI uri)
		throws Exception {

	String platformStr = uri.toString().replace("platform:/resource/", "");
	IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(platformStr));

	java.io.InputStream fileStream = file.getContents();

	java.util.Scanner s = new java.util.Scanner(fileStream, file.getCharset());
	s.useDelimiter("\\A");

	String content = s.hasNext() ? s.next() : "";

	fileStream.close();
	s.close();

	return content;
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:28,代碼來源:QuickFixXpectMethod.java

示例13: PgUIDumpLoader

import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
public PgUIDumpLoader(IFile ifile, PgDiffArguments args, IProgressMonitor monitor, int monitoringLevel)
        throws CoreException {
    super(ifile.getContents(), ifile.getLocation().toOSString(), args, monitor, monitoringLevel);
    file = ifile;
}
 
開發者ID:pgcodekeeper,項目名稱:pgcodekeeper,代碼行數:6,代碼來源:PgUIDumpLoader.java


注:本文中的org.eclipse.core.resources.IFile.getContents方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。