本文整理匯總了Java中org.eclipse.core.resources.IFile.setContents方法的典型用法代碼示例。如果您正苦於以下問題:Java IFile.setContents方法的具體用法?Java IFile.setContents怎麽用?Java IFile.setContents使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.core.resources.IFile
的用法示例。
在下文中一共展示了IFile.setContents方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: generateReport
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
public static void generateReport(final DesignModel model, final IFile output, final IProgressMonitor monitor) {
try {
final ByteArrayOutputStream data = new ByteArrayOutputStream();
final OutputStreamWriter writer = new OutputStreamWriter(data);
generateReport(model, writer);
writer.close();
final ByteArrayInputStream source = new ByteArrayInputStream(data.toByteArray());
if (output.exists()) {
output.setContents(source, true, true, monitor);
} else {
output.create(source, true, monitor);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例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.");
}
}
}
示例3: getModelOutputFile
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
public File getModelOutputFile (String outputName) throws CoreException, InterruptedException, FileNotFoundException {
IFile file = ResourceManager.toIFile(sourceFileModel);
IFolder folder = ResourceManager.ensureFolder(file.getProject(), ".gw4eoutput", new NullProgressMonitor());
IFile outfile = folder.getFile(new Path(outputName));
InputStream source = new ByteArrayInputStream("".getBytes());
if (outfile.exists()) {
outfile.setContents(source, IResource.FORCE, new NullProgressMonitor());
} else {
outfile.create(source, IResource.FORCE, new NullProgressMonitor());
}
outfile.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
long max = System.currentTimeMillis() + 15 * 1000;
while (true) {
IFile out = folder.getFile(new Path(outputName));
if (out.exists()) break;
if (System.currentTimeMillis() > max) {
throw new InterruptedException (out.getFullPath() + " does not exist.");
}
Thread.sleep(500);
}
return ResourceManager.toFile(outfile.getFullPath());
}
示例4: setFileContent
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
public static void setFileContent(IProject project, IFile file, String fileContent, IProgressMonitor monitor) throws CoreException
{
if (file.exists())
{
ByteArrayInputStream contentStream = new ByteArrayInputStream(fileContent.getBytes());
try
{
file.setContents(contentStream, true, true, monitor);
}
finally
{
try {
contentStream.close();
} catch (IOException e) {
throw new CoreException(new Status(Status.ERROR, "", "Could not close stream for file " + file.getFullPath(), e));
}
}
}
}
示例5: 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);
}
}
}
示例6: storeEditorInput
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
@Override
public void storeEditorInput() throws IOException, CoreException {
logger.debug("storeEditorInput - Storing IFileEditor input into Ifile");
ByteArrayOutputStream out = new ByteArrayOutputStream();
eltGraphicalEditorInstance.createOutputStream(out);
IFile ifile = ifileEditorInput.getFile();
ifile.setContents(new ByteArrayInputStream(out.toByteArray()),true, false, null);
this.eltGraphicalEditorInstance.getCommandStack().markSaveLocation();
this.eltGraphicalEditorInstance.genrateTargetXml(ifile,null,null);
this.eltGraphicalEditorInstance.setDirty(false);
}
示例7: marshall
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
public void marshall(Debug debug,IFile outPutFile) throws JAXBException, IOException, CoreException{
JAXBContext jaxbContext = JAXBContext.newInstance(Debug.class);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
ByteArrayOutputStream out = new ByteArrayOutputStream();
marshaller.marshal(debug, out);
if (outPutFile.exists())
outPutFile.setContents(new ByteArrayInputStream(out.toByteArray()), true,false, null);
else
outPutFile.create(new ByteArrayInputStream(out.toByteArray()),true, null);
out.close();
}
示例8: writeManifest
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
private void writeManifest(IFile outputFile) throws IOException, CoreException {
if (_manifest != null) { // manifest null means that no update needed.
ByteArrayOutputStream out = new ByteArrayOutputStream();
writeManifest(out);
ByteArrayInputStream is = new ByteArrayInputStream(out.toByteArray());
outputFile.setContents(is, 1, new NullProgressMonitor());
}
}
示例9: save
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
/**
* @param file
* @param content
* @throws CoreException
*/
public static void save(IFile file, String content, IProgressMonitor monitor) throws CoreException {
try {
byte[] source = content.getBytes(Charset.forName("UTF-8"));
if (file.exists()) {
file.setContents(new ByteArrayInputStream(source), IResource.KEEP_HISTORY, monitor);
} else {
file.create(new ByteArrayInputStream(source), true, monitor);
}
} catch (CoreException e) {
System.err.println("XXXXXXX " + file.getFullPath());
throw e;
}
}
示例10: writeInFile
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
public static void writeInFile(IFile file, String contents, IProgressMonitor monitor) throws CoreException, IOException{
InputStream stream = new ByteArrayInputStream(contents.getBytes(("UTF-8")));
if (file.exists()) {
file.setContents(stream, true, true, monitor);
} else {
if(file.getParent() instanceof IFolder && !file.getParent().exists()){
IFolderUtils.create((IFolder) file.getParent(), true, true, monitor);
}
file.create(stream, true, monitor);
}
stream.close();
}
示例11: configureOCCIEExtension
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
private void configureOCCIEExtension(IProgressMonitor monitor) throws CoreException {
IFile manifest = PDEProject.getManifest(project);
String manifestContent = "Manifest-Version: 1.0\n" + "Bundle-ManifestVersion: 2\n" + "Bundle-Name: "
+ project.getName() + "\n" + "Bundle-SymbolicName: " + project.getName() + ";singleton:=true\n"
+ "Bundle-Version: 1.0.0.qualifier\n" + "Bundle-ClassPath: .\n" + "Bundle-Vendor: OCCIware\n" +
// "Bundle-Localization: plugin\n" + // FIXME: require to
// generate plugin.properties
"Bundle-RequiredExecutionEnvironment: JavaSE-1.8\n" + "Bundle-ActivationPolicy: lazy\n"
+ "Require-Bundle: org.eclipse.emf.ecore;visibility:=reexport,\n"
+ " org.eclipse.cmf.occi.core;visibility:=reexport,\n" + " org.eclipse.cmf.occi.core.ui,\n"
+ " org.eclipse.cmf.occi.core.gen.emf.ui\n";
manifest.setContents(new ByteArrayInputStream(manifestContent.getBytes()), true, false, monitor);
IFile pluginXML = PDEProject.getPluginXml(project);
String pluginContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<?eclipse version=\"3.0\"?>\n"
+ "<!--\n" + " Copyright (c) 2015-2017 Obeo, Inria\n"
+ " All rights reserved. This program and the accompanying materials\n"
+ " are made available under the terms of the Eclipse Public License v1.0\n"
+ " which accompanies this distribution, and is available at\n"
+ " http://www.eclipse.org/legal/epl-v10.html\n" + "\n" + " Contributors:\n"
+ " - William Piers <[email protected]>\n" + " - Philippe Merle <[email protected]>\n"
+ " - Faiez Zalila <[email protected]>\n"
+ "-->\n" + "<plugin>\n" + "\n" + " <!-- Register the " + extensionName + " extension. -->\n"
+ " <extension point=\"org.eclipse.cmf.occi.core.occie\">\n" + " <occie scheme=\""
+ extensionScheme + "\" file=\"model/" + extensionName + ".occie\"/>\n" + " </extension>\n" + "\n"
+ " <!-- Define URI mapping. -->\n" + " <extension point=\"org.eclipse.emf.ecore.uri_mapping\">\n"
+ " <mapping source=\"" + extensionScheme.substring(0, extensionScheme.length() - 1)
+ "\" target=\"platform:/plugin/" + project.getName() + "/model/" + extensionName + ".occie\"/>\n"
+ " </extension>\n" + "\n" + " <!-- Register the parser for ." + extensionName + " files. -->\n"
+ " <extension point=\"org.eclipse.emf.ecore.extension_parser\">\n" + " <parser type=\""
+ extensionName + "\" class=\"org.eclipse.cmf.occi.core.util.OCCIResourceFactoryImpl\"/>\n"
+ " </extension>\n" + "\n" + " <!-- Popup menu for converting to an OCCI Configuration file. -->\n"
+ " <extension point=\"org.eclipse.ui.popupMenus\">\n" + " <objectContribution\n"
+ " id=\"" + newProjectPage.getProjectName() + ".contribution\"\n"
+ " nameFilter=\"*." + extensionName + "\"\n"
+ " objectClass=\"org.eclipse.core.resources.IFile\">\n" + " <menu\n"
+ " id=\"org.eclipse.cmf.occi.core.occi-studio.ui.menu\"\n"
+ " label=\"OCCI Studio\"\n" + " path=\"additionsOCCIStudio\">\n"
+ " <separator name=\"group\"/>\n" + " </menu>\n" + " <action\n"
+ " class=\"org.eclipse.cmf.occi.core.ui.popup.actions.ExtensionConfiguration2OCCICAction\"\n"
+ " enablesFor=\"1\"\n" + " id=\"" + newProjectPage.getProjectName()
+ ".ecore2occi\"\n" + " label=\"Convert to an OCCI Configuration File\"\n"
+ " menubarPath=\"org.eclipse.cmf.occi.core.occi-studio.ui.menu/group\">\n"
+ " </action>\n" + " </objectContribution>\n" + " </extension>\n" + "</plugin>\n";
pluginXML.create(new ByteArrayInputStream(pluginContent.getBytes()), true, monitor);
IFile build = PDEProject.getBuildProperties(project);
String buildContent = "# Copyright (c) 2015-2017 Obeo, Inria\n"
+ "# All rights reserved. This program and the accompanying materials\n"
+ "# are made available under the terms of the Eclipse Public License v1.0\n"
+ "# which accompanies this distribution, and is available at\n"
+ "# http://www.eclipse.org/legal/epl-v10.html\n" + "#\n" + "# Contributors:\n"
+ "# - William Piers <[email protected]>\n" + "# - Philippe Merle <[email protected]>\n"
+ "# - Faiez Zalila <[email protected]>\n"
+ "\n" + "source.. = src-gen/\n" + "jars.compile.order = .\n" + "output.. = bin/\n"
+ "bin.includes = .,\\\n" + " model/,\\\n" + " META-INF/,\\\n"
+ " plugin.xml,\\\n" + " plugin.properties\n";
build.setContents(new ByteArrayInputStream(buildContent.getBytes()), true, false, monitor);
}
示例12: testMethodInRequiredClassRenamed
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
@SuppressWarnings({ "resource", "javadoc" })
/**
*
* 01. B requires A, B calls method of A
* 02. method of A is renamed
* 03. B should get error marker at variable statement
* 04. method of A is renamed back
* 05. B should have no error markers
*
* @throws Exception
*/
//@formatter:on
@Test
public void testMethodInRequiredClassRenamed() throws Exception {
final IProject project = createJSProject("testMethodInSuperClassRenamed");
IFolder folder = configureProjectWithXtext(project);
IFolder module1Folder = createFolder(folder, InheritanceTestFiles.module1());
IFolder module2Folder = createFolder(folder, InheritanceTestFiles.module2());
IFile fileA = createTestFile(module1Folder, "A", InheritanceTestFiles.A());
IFile fileB = createTestFile(module2Folder, "B", InheritanceTestFiles.B());
// The value of the local variable a is not used
assertMarkers("File A should only have no errors and exactly one unused variable warning", fileA, 1);
// The value of the local variable b is not used
assertMarkers("File B should only have no errors and exactly one unused variable warning", fileB, 1);
fileA.setContents(new StringInputStream(InheritanceTestFiles.AOtherMethodName().toString()), true, true,
monitor());
waitForAutoBuild();
// The value of the local variable a is not used
assertMarkers("File A with other method name should have no errors and exactly one unused variable warning",
fileA, 1);
// One marker for using the old method name
// Additional marker for: The value of the local variable b is not used
assertMarkers("File B should have errors as using old method name", fileB, 2);
fileA.setContents(new StringInputStream(InheritanceTestFiles.A().toString()), true, true, monitor());
waitForAutoBuild();
// The value of the local variable a is not used
assertMarkers("File A with old method name should have no errors and exactly one unused variable warning",
fileA, 1);
// The value of the local variable b is not used
assertMarkers(
"File B should have no errors and exactly one unused variable warning after changing back to old A",
fileB,
1);
}
示例13: testMutualDependency
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
/**
*
* 01. Brother uses Sister in require statement and as return type of a method, creates a Sister object and invokes method of Sister
* 02. Sister uses Brother in require statement and as return type of a method, creates a Brother object and invokes method of Brother
* 03. Sister method is renamed
* 04. Brother should get error marker at the usage of the old sister method
* 05. Sister should have no error markers (as Brother is not saved yet)
* 06. Sister method is renamed back
* 07. Brother should have no error markers
*/
//@formatter:on
@SuppressWarnings("resource")
@Test
// TODO: while running there is a java.lang.IndexOutOfBoundsException: Index: 2, Size: 0 at at
// org.eclipse.n4js.resource.N4JSResource.getEncodedURI(N4JSResource.java:446)
public void testMutualDependency() throws Exception {
final IProject project = createJSProject("testMutualDependency");
IFolder folder = configureProjectWithXtext(project);
IFolder moduleFolder = createFolder(folder, TestFiles.mutualModuleFolder());
IFile brotherFile = createTestFile(moduleFolder, "Brother", TestFiles.classBrother());
IFile sisterFile = createTestFile(moduleFolder, "Sister", TestFiles.classSister());
IFile childFile = createTestFile(moduleFolder, "Child", TestFiles.classChild());
assertMarkers("brother file should have no errors", brotherFile, 0);
// expected markers
// Variable brother is used before it is declared
assertMarkers("sister file should have one errors", sisterFile, 1);
assertMarkers("child file should have no errors", childFile, 0);
sisterFile.setContents(new StringInputStream(TestFiles.classSisterNew().toString()), true, true, monitor());
waitForAutoBuild();
// expected markers
// Couldn't resolve reference to TMember 'getBrother'. at brother.getSister().getBrother
// Couldn't resolve reference to TMember 'getBrother'. at brother = sister.getBrother;
assertMarkers("brother file should have errors as using old method of sister", brotherFile, 2);
// expected markers
// Variable brother is used before it is declared
// Couldn't resolve reference to TMember 'getBrother'. at brother.getSister().getBrother
// Couldn't resolve reference to TMember 'getBrother'. at var brotherChildAge =
// sister.getBrother().getChild().age;
// Consequential error, not reported anymore:
// --> Couldn't resolve reference to TMember 'getChild'. at var brotherChildAge =
// ... sister.getBrother().getChild().age;
// Consequential error, not reported anymore:
// --> Couldn't resolve reference to TMember 'age'. at var brotherChildAge = sister.getBrother().getChild().age;
// Additional warning: The value of the local variable sister is not used
assertMarkers("new sister file should have errors as calling oldMethod via brother file", sisterFile, 4);
sisterFile.setContents(new StringInputStream(TestFiles.classSister().toString()), true, true, monitor());
waitForAutoBuild();
// expected markers
// Variable brother is used before it is declared
assertMarkers("sister file should have still one error", sisterFile, 1);
assertMarkers("brother file should have no errors anymore", brotherFile, 0);
}
示例14: testMethodInConsumedRoleRenamed
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
@SuppressWarnings({ "resource", "javadoc" })
/**
*
* 01. CRole consumes BRole, BRole consumes ARole
* 02. BRole calls method of ARole, BRole calls method of BRole and a method of ARole
* 03. method of ARole is renamed
* 04. BRole should get error marker at method call
* 05. CRole should get error marker at call of A's method, call to B's method should be ok
* 06. method of ARole is renamed back
* 07. B should have no error markers
* 08. C should have no error markers
*
* @throws Exception
*/
//@formatter:on
@Test
public void testMethodInConsumedRoleRenamed() throws Exception {
final IProject project = createJSProject("testMethodInConsumedRoleRenamed");
IFolder folder = configureProjectWithXtext(project);
IFolder moduleFolder = createFolder(folder, RoleTestFiles.moduleFolder());
IFile fileARole = createTestFile(moduleFolder, "ARole", RoleTestFiles.roleA());
IFile fileBRole = createTestFile(moduleFolder, "BRole", RoleTestFiles.roleB());
IFile fileCRole = createTestFile(moduleFolder, "CRole", RoleTestFiles.roleC());
waitForAutoBuild();
assertMarkers("File A should have no errors", fileARole, 0);
assertMarkers("File B should have no errors", fileBRole, 0);
assertMarkers("File C should have no errors", fileCRole, 0);
fileARole.setContents(new StringInputStream(RoleTestFiles.roleAChanged().toString()), true, true,
monitor());
waitForAutoBuild();
assertMarkers("File A with other method name should have no errors", fileARole, 0);
assertMarkers("File B should have errors as using old method name", fileBRole, 1);
assertMarkers("File C should have errors as using old method name", fileCRole, 1);
fileARole.setContents(new StringInputStream(RoleTestFiles.roleA().toString()), true, true, monitor());
waitForAutoBuild();
assertMarkers("File A with old method name should have no errors", fileARole, 0);
assertMarkers("File B should have exactly one marker after changing back to old A", fileBRole, 0);
assertMarkers("File C should have exactly one marker after changing back to old A", fileCRole, 0);
}
示例15: testConsumedRoleInConsumedRoleInBetweenRemoved
import org.eclipse.core.resources.IFile; //導入方法依賴的package包/類
@SuppressWarnings({ "resource", "javadoc" })
/**
*
* 01. CRole consumes BRole, BRole consumes ARole
* 02. BRole calls method of ARole, BRole calls method of BRole and a method of ARole
* 03. ARole as consumed Role is removed at BRole
* 04. CRole should get error marker at call of A's method, call to B's method should be ok
* 05. methodA is added to BRole
* 06. C should have no error markers
*
* @throws Exception
*/
//@formatter:on
@Test
public void testConsumedRoleInConsumedRoleInBetweenRemoved() throws Exception {
final IProject project = createJSProject("testConsumedRoleInConsumedRoleInBetweenRemoved");
IFolder folder = configureProjectWithXtext(project);
IFolder moduleFolder = createFolder(folder, RoleTestFiles.moduleFolder());
IFile fileARole = createTestFile(moduleFolder, "ARole", RoleTestFiles.roleA());
IFile fileBRole = createTestFile(moduleFolder, "BRole", RoleTestFiles.roleB());
IFile fileCRole = createTestFile(moduleFolder, "CRole", RoleTestFiles.roleC());
waitForAutoBuild();
assertMarkers("File A should have no errors", fileARole, 0);
assertMarkers("File B should have no errors", fileBRole, 0);
assertMarkers("File C should have no errors", fileCRole, 0);
fileBRole.setContents(new StringInputStream(RoleTestFiles.roleBChanged2().toString()), true, true,
monitor());
waitForAutoBuild();
assertMarkers("File A should have no errors", fileARole, 0);
assertMarkers("File B with no A Role consumed should have no errors, one unused import warning.", fileBRole, 1);
assertMarkers("File C should have errors as using non existing method", fileCRole, 1);
fileBRole.setContents(new StringInputStream(RoleTestFiles.roleBChanged3().toString()), true, true, monitor());
waitForAutoBuild();
assertMarkers("File A should have no errors", fileARole, 0);
assertMarkers("File B should have no errors, one unused imports warning", fileBRole, 1);
assertMarkers("File C should have no errors after changing back to B with additional method", fileCRole, 0);
}