本文整理匯總了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;
}
示例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: 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);
}
}
}
示例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);
}
示例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;
}
示例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());
}
}
示例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));
}
示例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();
}
示例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);
}
}
}
示例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;
}
示例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();
}
}
示例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;
}
示例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;
}