org.eclipse.core.internal.resources
Class File

java.lang.Object
  extended by org.eclipse.core.runtime.PlatformObject
      extended by org.eclipse.core.internal.resources.Resource
          extended by org.eclipse.core.internal.resources.File
All Implemented Interfaces:
java.lang.Cloneable, ICoreConstants, IPathRequestor, IEncodedStorage, IFile, IResource, IStorage, org.eclipse.core.runtime.IAdaptable, org.eclipse.core.runtime.jobs.ISchedulingRule

public class File
extends Resource
implements IFile

The standard implementation of IFile.


Field Summary
 
Fields inherited from interface org.eclipse.core.resources.IFile
ENCODING_ISO_8859_1, ENCODING_UNKNOWN, ENCODING_US_ASCII, ENCODING_UTF_16, ENCODING_UTF_16BE, ENCODING_UTF_16LE, ENCODING_UTF_8
 
Fields inherited from interface org.eclipse.core.resources.IResource
ALLOW_MISSING_LOCAL, ALWAYS_DELETE_PROJECT_CONTENT, AVOID_NATURE_CONFIG, BACKGROUND_REFRESH, CHECK_ANCESTORS, DEPTH_INFINITE, DEPTH_ONE, DEPTH_ZERO, DERIVED, FILE, FOLDER, FORCE, HIDDEN, KEEP_HISTORY, NEVER_DELETE_PROJECT_CONTENT, NONE, NULL_STAMP, PROJECT, REPLACE, ROOT, SHALLOW, TEAM_PRIVATE
 
Fields inherited from interface org.eclipse.core.internal.resources.ICoreConstants
CRASH_DETECTED, EMPTY_FILE_STATES, EMPTY_PROJECT_ARRAY, EMPTY_RESOURCE_ARRAY, I_NULL_SYNC_INFO, K_BUILD_LIST, M_CHILDREN_UNKNOWN, M_CONTENT_CACHE, M_DEFAULT_CONTENT_DESCRIPTION, M_DERIVED, M_HIDDEN, M_LINK, M_LOCAL_EXISTS, M_MARKERS_SNAP_DIRTY, M_NO_CONTENT_DESCRIPTION, M_OPEN, M_PHANTOM, M_SYNCINFO_SNAP_DIRTY, M_TEAM_PRIVATE_MEMBER, M_TYPE, M_TYPE_START, M_USED, MINIMUM_FILE_SEGMENT_LENGTH, MINIMUM_FOLDER_SEGMENT_LENGTH, NULL_FLAG, PREF_VERSION, PREF_VERSION_KEY, PROJECT_SEGMENT_LENGTH, REFRESH_ON_STARTUP, WORKSPACE_TREE_VERSION_1, WORKSPACE_TREE_VERSION_2
 
Method Summary
 void appendContents(java.io.InputStream content, boolean force, boolean keepHistory, org.eclipse.core.runtime.IProgressMonitor monitor)
          Appends the entire contents of the given stream to this file.
 void appendContents(java.io.InputStream content, int updateFlags, org.eclipse.core.runtime.IProgressMonitor monitor)
          Appends the entire contents of the given stream to this file.
 IFolder changeToFolder()
          Changes this file to be a folder in the resource tree and returns the newly created folder.
 void create(java.io.InputStream content, boolean force, org.eclipse.core.runtime.IProgressMonitor monitor)
          Creates a new file resource as a member of this handle's parent resource.
 void create(java.io.InputStream content, int updateFlags, org.eclipse.core.runtime.IProgressMonitor monitor)
          Creates a new file resource as a member of this handle's parent resource.
 java.lang.String getCharset()
          Returns the name of a charset to be used when decoding the contents of this file into characters.
 java.lang.String getCharset(boolean checkImplicit)
          Returns the name of a charset to be used when decoding the contents of this file into characters.
 java.lang.String getCharsetFor(java.io.Reader contents)
          Returns the name of a charset to be used to encode the given contents when saving to this file.
 org.eclipse.core.runtime.content.IContentDescription getContentDescription()
          Returns a description for this file's current contents.
 java.io.InputStream getContents()
          Returns an open input stream on the contents of this file.
 java.io.InputStream getContents(boolean force)
          This refinement of the corresponding IStorage method returns an open input stream on the contents of this file.
 int getEncoding()
          Deprecated.  
 IFileState[] getHistory(org.eclipse.core.runtime.IProgressMonitor monitor)
          Returns a list of past states of this file known to this workspace.
 int getType()
          Returns the type of this resource.
 void refreshLocal(int depth, org.eclipse.core.runtime.IProgressMonitor monitor)
          Optimized refreshLocal for files.
 void setCharset(java.lang.String newCharset)
          Deprecated. Replaced by setCharset(String, IProgressMonitor) which is a workspace operation and reports changes in resource deltas.
 void setCharset(java.lang.String newCharset, org.eclipse.core.runtime.IProgressMonitor monitor)
          Sets the charset for this file.
 void setContents(IFileState source, boolean force, boolean keepHistory, org.eclipse.core.runtime.IProgressMonitor monitor)
          Sets the contents of this file to the bytes in the given file state.
 void setContents(IFileState content, int updateFlags, org.eclipse.core.runtime.IProgressMonitor monitor)
          Sets the contents of this file to the bytes in the given file state.
 void setContents(java.io.InputStream content, boolean force, boolean keepHistory, org.eclipse.core.runtime.IProgressMonitor monitor)
          Sets the contents of this file to the bytes in the given input stream.
 void setContents(java.io.InputStream content, int updateFlags, org.eclipse.core.runtime.IProgressMonitor monitor)
          Sets the contents of this file to the bytes in the given input stream.
 long setLocalTimeStamp(long value)
          Sets the local time stamp on disk for this resource.
 void updateMetadataFiles()
          Treat the file specially if it represents a metadata file, which includes: - project description file (.project) - project preferences files (*.prefs) This method is called whenever it is discovered that a file has been modified (added, removed, or changed).
 
Methods inherited from class org.eclipse.core.internal.resources.Resource
accept, accept, accept, accept, checkAccessible, checkCopyRequirements, checkDoesNotExist, checkExists, checkLocal, checkValidPath, clearHistory, contains, convertToPhantom, copy, copy, copy, copy, countResources, createLink, createLink, createMarker, createProxy, delete, delete, delete, deleteMarkers, deleteResource, equals, exists, exists, findExistingResourceVariant, findMarker, findMarkers, findMaxProblemSeverity, getFileExtension, getFlags, getFullPath, getLocalManager, getLocalTimeStamp, getLocation, getLocationURI, getMarker, getModificationStamp, getName, getParent, getPersistentProperties, getPersistentProperty, getProject, getProjectRelativePath, getPropertyManager, getRawLocation, getRawLocationURI, getResourceAttributes, getResourceInfo, getSessionProperties, getSessionProperty, getStore, getTypeString, getWorkspace, hashCode, isAccessible, isConflicting, isDerived, isDerived, isHidden, isHidden, isLinked, isLinked, isLocal, isLocal, isPhantom, isPhantom, isReadOnly, isSynchronized, isTeamPrivateMember, isTeamPrivateMember, isUnderLink, move, move, move, move, move, requestName, requestPath, revertModificationStamp, setDerived, setHidden, setLocal, setPersistentProperty, setReadOnly, setResourceAttributes, setSessionProperty, setTeamPrivateMember, synchronizing, toString, touch
 
Methods inherited from class org.eclipse.core.runtime.PlatformObject
getAdapter
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.eclipse.core.resources.IFile
createLink, createLink, delete, getFullPath, getName, isReadOnly, move
 
Methods inherited from interface org.eclipse.core.resources.IResource
accept, accept, accept, accept, clearHistory, copy, copy, copy, copy, createMarker, createProxy, delete, delete, deleteMarkers, equals, exists, findMarker, findMarkers, findMaxProblemSeverity, getFileExtension, getLocalTimeStamp, getLocation, getLocationURI, getMarker, getModificationStamp, getParent, getPersistentProperties, getPersistentProperty, getProject, getProjectRelativePath, getRawLocation, getRawLocationURI, getResourceAttributes, getSessionProperties, getSessionProperty, getWorkspace, isAccessible, isDerived, isDerived, isHidden, isHidden, isLinked, isLinked, isLocal, isPhantom, isSynchronized, isTeamPrivateMember, isTeamPrivateMember, move, move, move, move, revertModificationStamp, setDerived, setHidden, setLocal, setPersistentProperty, setReadOnly, setResourceAttributes, setSessionProperty, setTeamPrivateMember, touch
 
Methods inherited from interface org.eclipse.core.runtime.jobs.ISchedulingRule
contains, isConflicting
 
Methods inherited from interface org.eclipse.core.runtime.IAdaptable
getAdapter
 

Method Detail

appendContents

public void appendContents(java.io.InputStream content,
                           int updateFlags,
                           org.eclipse.core.runtime.IProgressMonitor monitor)
                    throws org.eclipse.core.runtime.CoreException
Description copied from interface: IFile
Appends the entire contents of the given stream to this file. The stream, which must not be null, will get closed whether this method succeeds or fails.

The FORCE update flag controls how this method deals with cases where the workspace is not completely in sync with the local file system. If FORCE is not specified, the method will only attempt to overwrite a corresponding file in the local file system provided it is in sync with the workspace. This option ensures there is no unintended data loss; it is the recommended setting. However, if FORCE is specified, an attempt will be made to write a corresponding file in the local file system, overwriting any existing one if need be. In either case, if this method succeeds, the resource will be marked as being local (even if it wasn't before).

If this file is non-local then this method will always fail. The only exception is when FORCE is specified and the file exists in the local file system. In this case the file is made local and the given contents are appended.

The KEEP_HISTORY update flag controls whether or not a copy of current contents of this file should be captured in the workspace's local history (properties are not recorded in the local history). The local history mechanism serves as a safety net to help the user recover from mistakes that might otherwise result in data loss. Specifying KEEP_HISTORY is recommended except in circumstances where past states of the files are of no conceivable interest to the user. Note that local history is maintained with each individual project, and gets discarded when a project is deleted from the workspace. This flag is ignored if the file was not previously local.

Update flags other than FORCE and KEEP_HISTORY are ignored.

Prior to modifying the contents of this file, the file modification validator (if provided by the VCM plug-in), will be given a chance to perform any last minute preparations. Validation is performed by calling IFileModificationValidator.validateSave on this file. If the validation fails, then this operation will fail.

This method changes resources; these changes will be reported in a subsequent resource change event, including an indication that this file's content have been changed.

This method is long-running; progress and cancelation are provided by the given progress monitor.

Specified by:
appendContents in interface IFile
Parameters:
content - an input stream containing the new contents of the file
updateFlags - bit-wise or of update flag constants (FORCE and KEEP_HISTORY)
monitor - a progress monitor, or null if progress reporting is not desired
Throws:
org.eclipse.core.runtime.CoreException - if this method fails. Reasons include:
  • This resource does not exist.
  • The corresponding location in the local file system is occupied by a directory.
  • The workspace is not in sync with the corresponding location in the local file system and FORCE is not specified.
  • Resource changes are disallowed during certain types of resource change event notification. See IResourceChangeEvent for more details.
  • The file modification validator disallowed the change.
See Also:
IResourceRuleFactory.modifyRule(IResource)

appendContents

public void appendContents(java.io.InputStream content,
                           boolean force,
                           boolean keepHistory,
                           org.eclipse.core.runtime.IProgressMonitor monitor)
                    throws org.eclipse.core.runtime.CoreException
Description copied from interface: IFile
Appends the entire contents of the given stream to this file.

This is a convenience method, fully equivalent to:

   appendContents(source, (keepHistory ? KEEP_HISTORY : IResource.NONE) | (force ? FORCE : IResource.NONE), monitor);
 

This method changes resources; these changes will be reported in a subsequent resource change event, including an indication that this file's content have been changed.

This method is long-running; progress and cancelation are provided by the given progress monitor.

Specified by:
appendContents in interface IFile
Parameters:
content - an input stream containing the new contents of the file
force - a flag controlling how to deal with resources that are not in sync with the local file system
keepHistory - a flag indicating whether or not to store the current contents in the local history
monitor - a progress monitor, or null if progress reporting is not desired
Throws:
org.eclipse.core.runtime.CoreException - if this method fails. Reasons include:
  • This resource does not exist.
  • The corresponding location in the local file system is occupied by a directory.
  • The workspace is not in sync with the corresponding location in the local file system and force is false.
  • Resource changes are disallowed during certain types of resource change event notification. See IResourceChangeEvent for more details.
  • The file modification validator disallowed the change.
See Also:
IFile.appendContents(java.io.InputStream,int,IProgressMonitor)

changeToFolder

public IFolder changeToFolder()
                       throws org.eclipse.core.runtime.CoreException
Changes this file to be a folder in the resource tree and returns the newly created folder. All related properties are deleted. It is assumed that on disk the resource is already a folder/directory so no action is taken to delete the disk contents.

This method is for the exclusive use of the local resource manager

Throws:
org.eclipse.core.runtime.CoreException

create

public void create(java.io.InputStream content,
                   int updateFlags,
                   org.eclipse.core.runtime.IProgressMonitor monitor)
            throws org.eclipse.core.runtime.CoreException
Description copied from interface: IFile
Creates a new file resource as a member of this handle's parent resource. The resource's contents are supplied by the data in the given stream. This method closes the stream whether it succeeds or fails. If the stream is null then a file is not created in the local file system and the created file resource is marked as being non-local.

The IResource.FORCE update flag controls how this method deals with cases where the workspace is not completely in sync with the local file system. If IResource.FORCE is not specified, the method will only attempt to write a file in the local file system if it does not already exist. This option ensures there is no unintended data loss; it is the recommended setting. However, if IResource.FORCE is specified, this method will attempt to write a corresponding file in the local file system, overwriting any existing one if need be.

The IResource.DERIVED update flag indicates that this resource should immediately be set as a derived resource. Specifying this flag is equivalent to atomically calling IResource.setDerived(boolean) with a value of true immediately after creating the resource.

The IResource.TEAM_PRIVATE update flag indicates that this resource should immediately be set as a team private resource. Specifying this flag is equivalent to atomically calling IResource.setTeamPrivateMember(boolean) with a value of true immediately after creating the resource.

The IResource.HIDDEN update flag indicates that this resource should immediately be set as a hidden resource. Specifying this flag is equivalent to atomically calling IResource.setHidden(boolean) with a value of true immediately after creating the resource.

Update flags other than those listed above are ignored.

This method changes resources; these changes will be reported in a subsequent resource change event, including an indication that the file has been added to its parent.

This method is long-running; progress and cancellation are provided by the given progress monitor.

Specified by:
create in interface IFile
Parameters:
content - an input stream containing the initial contents of the file, or null if the file should be marked as not local
updateFlags - bit-wise or of update flag constants (IResource.FORCE, IResource.DERIVED, and IResource.TEAM_PRIVATE)
monitor - a progress monitor, or null if progress reporting is not desired
Throws:
org.eclipse.core.runtime.CoreException - if this method fails. Reasons include:
  • This resource already exists in the workspace.
  • The parent of this resource does not exist.
  • The project of this resource is not accessible.
  • The parent contains a resource of a different type at the same path as this resource.
  • The name of this resource is not valid (according to IWorkspace.validateName).
  • The corresponding location in the local file system is occupied by a directory.
  • The corresponding location in the local file system is occupied by a file and FORCE is not specified.
  • Resource changes are disallowed during certain types of resource change event notification. See IResourceChangeEvent for more details.
See Also:
IResourceRuleFactory.createRule(IResource)

create

public void create(java.io.InputStream content,
                   boolean force,
                   org.eclipse.core.runtime.IProgressMonitor monitor)
            throws org.eclipse.core.runtime.CoreException
Description copied from interface: IFile
Creates a new file resource as a member of this handle's parent resource.

This is a convenience method, fully equivalent to:

   create(source, (force ? FORCE : IResource.NONE), monitor);
 

This method changes resources; these changes will be reported in a subsequent resource change event, including an indication that the file has been added to its parent.

This method is long-running; progress and cancellation are provided by the given progress monitor.

Specified by:
create in interface IFile
Parameters:
content - an input stream containing the initial contents of the file, or null if the file should be marked as not local
force - a flag controlling how to deal with resources that are not in sync with the local file system
monitor - a progress monitor, or null if progress reporting is not desired
Throws:
org.eclipse.core.runtime.CoreException - if this method fails. Reasons include:
  • This resource already exists in the workspace.
  • The parent of this resource does not exist.
  • The project of this resource is not accessible.
  • The parent contains a resource of a different type at the same path as this resource.
  • The name of this resource is not valid (according to IWorkspace.validateName).
  • The corresponding location in the local file system is occupied by a directory.
  • The corresponding location in the local file system is occupied by a file and force is false.
  • Resource changes are disallowed during certain types of resource change event notification. See IResourceChangeEvent for more details.

getCharset

public java.lang.String getCharset()
                            throws org.eclipse.core.runtime.CoreException
Description copied from interface: IFile
Returns the name of a charset to be used when decoding the contents of this file into characters.

This refinement of the corresponding IEncodedStorage method is a convenience method, fully equivalent to:

   getCharset(true);
 

Note 1: this method does not check whether the result is a supported charset name. Callers should be prepared to handle UnsupportedEncodingException where this charset is used.

Note 2: this method returns a cached value for the encoding that may be out of date if the file is not synchronized with the local file system and the encoding has since changed in the file system.

Specified by:
getCharset in interface IEncodedStorage
Specified by:
getCharset in interface IFile
Returns:
the name of a charset
Throws:
org.eclipse.core.runtime.CoreException - if this method fails. Reasons include:
  • This resource could not be read.
  • This resource is not local.
  • The corresponding location in the local file system is occupied by a directory.
See Also:
IFile.getCharset(boolean), IEncodedStorage.getCharset(), IContainer.getDefaultCharset()

getCharset

public java.lang.String getCharset(boolean checkImplicit)
                            throws org.eclipse.core.runtime.CoreException
Description copied from interface: IFile
Returns the name of a charset to be used when decoding the contents of this file into characters.

If checkImplicit is false, this method will return the charset defined by calling setCharset, provided this file exists, or null otherwise.

If checkImplicit is true, this method uses the following algorithm to determine the charset to be returned:

  1. the charset defined by calling #setCharset, if any, and this file exists, or
  2. the charset automatically discovered based on this file's contents, if one can be determined, or
  3. the default encoding for this file's parent (as defined by IContainer#getDefaultCharset).

Note 1: this method does not check whether the result is a supported charset name. Callers should be prepared to handle UnsupportedEncodingException where this charset is used.

Note 2: this method returns a cached value for the encoding that may be out of date if the file is not synchronized with the local file system and the encoding has since changed in the file system.

Specified by:
getCharset in interface IFile
Returns:
the name of a charset, or null
Throws:
org.eclipse.core.runtime.CoreException - if this method fails. Reasons include:
  • This resource could not be read.
  • This resource is not local.
  • The corresponding location in the local file system is occupied by a directory.
See Also:
IEncodedStorage.getCharset(), IContainer.getDefaultCharset()

getCharsetFor

public java.lang.String getCharsetFor(java.io.Reader contents)
                               throws org.eclipse.core.runtime.CoreException
Description copied from interface: IFile
Returns the name of a charset to be used to encode the given contents when saving to this file. This file does not have to exist. The character stream is not automatically closed.

This method uses the following algorithm to determine the charset to be returned:

  1. if this file exists, the charset returned by IFile#getCharset(false), if one is defined, or
  2. the charset automatically discovered based on the file name and the given contents, if one can be determined, or
  3. the default encoding for the parent resource (as defined by IContainer#getDefaultCharset).

Note: this method does not check whether the result is a supported charset name. Callers should be prepared to handle UnsupportedEncodingException where this charset is used.

Specified by:
getCharsetFor in interface IFile
Parameters:
contents - a character stream containing the contents to be saved into this file
Returns:
the name of a charset
Throws:
org.eclipse.core.runtime.CoreException - if this method fails. Reasons include:
  • The given character stream could not be read.
See Also:
IFile.getCharset(boolean), IContainer.getDefaultCharset()

getContentDescription

public org.eclipse.core.runtime.content.IContentDescription getContentDescription()
                                                                           throws org.eclipse.core.runtime.CoreException
Description copied from interface: IFile
Returns a description for this file's current contents. Returns null if a description cannot be obtained.

Calling this method produces a similar effect as calling getDescriptionFor(getContents(), getName(), IContentDescription.ALL) on IContentTypeManager, but provides better opportunities for improved performance. Therefore, when manipulating IFiles, clients should call this method instead of IContentTypeManager.getDescriptionFor.

Specified by:
getContentDescription in interface IFile
Returns:
a description for this file's current contents, or null
Throws:
org.eclipse.core.runtime.CoreException - if this method fails. Reasons include:
  • This resource does not exist.
  • This resource could not be read.
  • This resource is not local.
  • The workspace is not in sync with the corresponding location in the local file system.
  • The corresponding location in the local file system is occupied by a directory.
See Also:
IContentDescription, IContentTypeMatcher.getDescriptionFor(InputStream, String, QualifiedName[])

getContents

public java.io.InputStream getContents()
                                throws org.eclipse.core.runtime.CoreException
Description copied from interface: IFile
Returns an open input stream on the contents of this file. This refinement of the corresponding IStorage method returns an open input stream on the contents of this file. The client is responsible for closing the stream when finished.

Specified by:
getContents in interface IFile
Specified by:
getContents in interface IStorage
Returns:
an input stream containing the contents of the file
Throws:
org.eclipse.core.runtime.CoreException - if this method fails. Reasons include:
  • This resource does not exist.
  • This resource is not local.
  • The workspace is not in sync with the corresponding location in the local file system.

getContents

public java.io.InputStream getContents(boolean force)
                                throws org.eclipse.core.runtime.CoreException
Description copied from interface: IFile
This refinement of the corresponding IStorage method returns an open input stream on the contents of this file. The client is responsible for closing the stream when finished. If force is true the file is opened and an input stream returned regardless of the sync state of the file. The file is not synchronized with the workspace. If force is false the method fails if not in sync.

Specified by:
getContents in interface IFile
Parameters:
force - a flag controlling how to deal with resources that are not in sync with the local file system
Returns:
an input stream containing the contents of the file
Throws:
org.eclipse.core.runtime.CoreException - if this method fails. Reasons include:
  • This resource does not exist.
  • This resource is not local.
  • The workspace is not in sync with the corresponding location in the local file system and force is false.

getEncoding

public int getEncoding()
                throws org.eclipse.core.runtime.CoreException
Deprecated. 

Description copied from interface: IFile
Returns a constant identifying the character encoding of this file, or ENCODING_UNKNOWN if it could not be determined. The returned constant will be one of the ENCODING_* constants defined on IFile. This method attempts to guess the file's character encoding by analyzing the first few bytes of the file. If no identifying pattern is found at the beginning of the file, ENC_UNKNOWN will be returned. This method will not attempt any complex analysis of the file to make a guess at the encoding that is used.

Specified by:
getEncoding in interface IFile
Returns:
The character encoding of this file
Throws:
org.eclipse.core.runtime.CoreException - if this method fails. Reasons include:
  • This resource does not exist.
  • This resource could not be read.
  • This resource is not local.
  • The corresponding location in the local file system is occupied by a directory.
See Also:
IFile.getEncoding()

getHistory

public IFileState[] getHistory(org.eclipse.core.runtime.IProgressMonitor monitor)
Description copied from interface: IFile
Returns a list of past states of this file known to this workspace. Recently added states first.

This method is long-running; progress and cancellation are provided by the given progress monitor.

Specified by:
getHistory in interface IFile
Parameters:
monitor - a progress monitor, or null if progress reporting is not desired
Returns:
an array of states of this file

getType

public int getType()
Description copied from interface: IResource
Returns the type of this resource. The returned value will be one of FILE, FOLDER, PROJECT, ROOT.

This is a resource handle operation; the resource need not exist in the workspace.

Specified by:
getType in interface IResource
Specified by:
getType in class Resource
Returns:
the type of this resource
See Also:
IResource.FILE, IResource.FOLDER, IResource.PROJECT, IResource.ROOT

refreshLocal

public void refreshLocal(int depth,
                         org.eclipse.core.runtime.IProgressMonitor monitor)
                  throws org.eclipse.core.runtime.CoreException
Optimized refreshLocal for files. This implementation does not block the workspace for the common case where the file exists both locally and on the file system, and is in sync. For all other cases, it defers to the super implementation.

Specified by:
refreshLocal in interface IResource
Overrides:
refreshLocal in class Resource
Parameters:
depth - valid values are DEPTH_ZERO, DEPTH_ONE, or DEPTH_INFINITE
monitor - a progress monitor, or null if progress reporting is not desired
Throws:
org.eclipse.core.runtime.CoreException - if this method fails. Reasons include:
  • Resource changes are disallowed during certain types of resource change event notification. See IResourceChangeEvent for more details.
See Also:
IResource.DEPTH_ZERO, IResource.DEPTH_ONE, IResource.DEPTH_INFINITE, IResourceRuleFactory.refreshRule(IResource)

setContents

public void setContents(IFileState content,
                        int updateFlags,
                        org.eclipse.core.runtime.IProgressMonitor monitor)
                 throws org.eclipse.core.runtime.CoreException
Description copied from interface: IFile
Sets the contents of this file to the bytes in the given file state.

The FORCE update flag controls how this method deals with cases where the workspace is not completely in sync with the local file system. If FORCE is not specified, the method will only attempt to overwrite a corresponding file in the local file system provided it is in sync with the workspace. This option ensures there is no unintended data loss; it is the recommended setting. However, if FORCE is specified, an attempt will be made to write a corresponding file in the local file system, overwriting any existing one if need be. In either case, if this method succeeds, the resource will be marked as being local (even if it wasn't before).

The KEEP_HISTORY update flag controls whether or not a copy of current contents of this file should be captured in the workspace's local history (properties are not recorded in the local history). The local history mechanism serves as a safety net to help the user recover from mistakes that might otherwise result in data loss. Specifying KEEP_HISTORY is recommended except in circumstances where past states of the files are of no conceivable interest to the user. Note that local history is maintained with each individual project, and gets discarded when a project is deleted from the workspace. This flag is ignored if the file was not previously local.

Update flags other than FORCE and KEEP_HISTORY are ignored.

Prior to modifying the contents of this file, the file modification validator (if provided by the VCM plug-in), will be given a chance to perform any last minute preparations. Validation is performed by calling IFileModificationValidator.validateSave on this file. If the validation fails, then this operation will fail.

This method changes resources; these changes will be reported in a subsequent resource change event, including an indication that this file's content have been changed.

This method is long-running; progress and cancellation are provided by the given progress monitor.

Specified by:
setContents in interface IFile
Parameters:
content - a previous state of this resource
updateFlags - bit-wise or of update flag constants (FORCE and KEEP_HISTORY)
monitor - a progress monitor, or null if progress reporting is not desired
Throws:
org.eclipse.core.runtime.CoreException - if this method fails. Reasons include:
  • This resource does not exist.
  • The state does not exist.
  • The corresponding location in the local file system is occupied by a directory.
  • The workspace is not in sync with the corresponding location in the local file system and FORCE is not specified.
  • Resource changes are disallowed during certain types of resource change event notification. See IResourceChangeEvent for more details.
  • The file modification validator disallowed the change.
See Also:
IResourceRuleFactory.modifyRule(IResource)

setContents

public void setContents(java.io.InputStream content,
                        int updateFlags,
                        org.eclipse.core.runtime.IProgressMonitor monitor)
                 throws org.eclipse.core.runtime.CoreException
Description copied from interface: IFile
Sets the contents of this file to the bytes in the given input stream. The stream will get closed whether this method succeeds or fails. If the stream is null then the content is set to be the empty sequence of bytes.

The FORCE update flag controls how this method deals with cases where the workspace is not completely in sync with the local file system. If FORCE is not specified, the method will only attempt to overwrite a corresponding file in the local file system provided it is in sync with the workspace. This option ensures there is no unintended data loss; it is the recommended setting. However, if FORCE is specified, an attempt will be made to write a corresponding file in the local file system, overwriting any existing one if need be. In either case, if this method succeeds, the resource will be marked as being local (even if it wasn't before).

The KEEP_HISTORY update flag controls whether or not a copy of current contents of this file should be captured in the workspace's local history (properties are not recorded in the local history). The local history mechanism serves as a safety net to help the user recover from mistakes that might otherwise result in data loss. Specifying KEEP_HISTORY is recommended except in circumstances where past states of the files are of no conceivable interest to the user. Note that local history is maintained with each individual project, and gets discarded when a project is deleted from the workspace. This flag is ignored if the file was not previously local.

Update flags other than FORCE and KEEP_HISTORY are ignored.

Prior to modifying the contents of this file, the file modification validator (if provided by the VCM plug-in), will be given a chance to perform any last minute preparations. Validation is performed by calling IFileModificationValidator.validateSave on this file. If the validation fails, then this operation will fail.

This method changes resources; these changes will be reported in a subsequent resource change event, including an indication that this file's content have been changed.

This method is long-running; progress and cancellation are provided by the given progress monitor.

Specified by:
setContents in interface IFile
Parameters:
content - an input stream containing the new contents of the file
updateFlags - bit-wise or of update flag constants (FORCE and KEEP_HISTORY)
monitor - a progress monitor, or null if progress reporting is not desired
Throws:
org.eclipse.core.runtime.CoreException - if this method fails. Reasons include:
  • This resource does not exist.
  • The corresponding location in the local file system is occupied by a directory.
  • The workspace is not in sync with the corresponding location in the local file system and FORCE is not specified.
  • Resource changes are disallowed during certain types of resource change event notification. See IResourceChangeEvent for more details.
  • The file modification validator disallowed the change.
See Also:
IResourceRuleFactory.modifyRule(IResource)

setLocalTimeStamp

public long setLocalTimeStamp(long value)
                       throws org.eclipse.core.runtime.CoreException
Description copied from interface: IResource
Sets the local time stamp on disk for this resource. The time must be represented as the number of milliseconds since the epoch (00:00:00 GMT, January 1, 1970). Returns the actual time stamp that was recorded. Due to varying file system timing granularities, the provided value may be rounded or otherwise truncated, so the actual recorded time stamp that is returned may not be the same as the supplied value.

Specified by:
setLocalTimeStamp in interface IResource
Overrides:
setLocalTimeStamp in class Resource
Parameters:
value - a time stamp in milliseconds.
Returns:
a local file system time stamp.
Throws:
org.eclipse.core.runtime.CoreException - if this method fails. Reasons include:
  • This resource does not exist.
  • This resource is not local.
  • This resource is not accessible.
  • Resource changes are disallowed during certain types of resource change event notification. See IResourceChangeEvent for more details.

updateMetadataFiles

public void updateMetadataFiles()
                         throws org.eclipse.core.runtime.CoreException
Treat the file specially if it represents a metadata file, which includes: - project description file (.project) - project preferences files (*.prefs) This method is called whenever it is discovered that a file has been modified (added, removed, or changed).

Throws:
org.eclipse.core.runtime.CoreException

setCharset

public void setCharset(java.lang.String newCharset)
                throws org.eclipse.core.runtime.CoreException
Deprecated. Replaced by setCharset(String, IProgressMonitor) which is a workspace operation and reports changes in resource deltas.

(non-Javadoc)

Specified by:
setCharset in interface IFile
Parameters:
newCharset - a charset name, or null
Throws:
org.eclipse.core.runtime.CoreException - if this method fails. Reasons include:
  • This resource does not exist.
  • An error happened while persisting this setting.
See Also:
IFile.setCharset(String)

setCharset

public void setCharset(java.lang.String newCharset,
                       org.eclipse.core.runtime.IProgressMonitor monitor)
                throws org.eclipse.core.runtime.CoreException
Description copied from interface: IFile
Sets the charset for this file. Passing a value of null will remove the charset setting for this resource.

This method changes resources; these changes will be reported in a subsequent resource change event, including an indication that this file's encoding has changed.

This method is long-running; progress and cancellation are provided by the given progress monitor.

Specified by:
setCharset in interface IFile
Parameters:
newCharset - a charset name, or null
monitor - a progress monitor, or null if progress reporting is not desired
Throws:
org.eclipse.core.runtime.CoreException - if this method fails. Reasons include:
  • This resource does not exist.
  • An error happened while persisting this setting.
  • Resource changes are disallowed during certain types of resource change event notification. See IResourceChangeEvent for more details.
See Also:
IFile.getCharset(), IResourceRuleFactory.charsetRule(IResource)

setContents

public void setContents(java.io.InputStream content,
                        boolean force,
                        boolean keepHistory,
                        org.eclipse.core.runtime.IProgressMonitor monitor)
                 throws org.eclipse.core.runtime.CoreException
Description copied from interface: IFile
Sets the contents of this file to the bytes in the given input stream.

This is a convenience method, fully equivalent to:

   setContents(source, (keepHistory ? KEEP_HISTORY : IResource.NONE) | (force ? FORCE : IResource.NONE), monitor);
 

This method changes resources; these changes will be reported in a subsequent resource change event, including an indication that this file's contents have been changed.

This method is long-running; progress and cancellation are provided by the given progress monitor.

Specified by:
setContents in interface IFile
Parameters:
content - an input stream containing the new contents of the file
force - a flag controlling how to deal with resources that are not in sync with the local file system
keepHistory - a flag indicating whether or not store the current contents in the local history
monitor - a progress monitor, or null if progress reporting is not desired
Throws:
org.eclipse.core.runtime.CoreException - if this method fails. Reasons include:
  • This resource does not exist.
  • The corresponding location in the local file system is occupied by a directory.
  • The workspace is not in sync with the corresponding location in the local file system and force is false.
  • Resource changes are disallowed during certain types of resource change event notification. See IResourceChangeEvent for more details.
  • The file modification validator disallowed the change.
See Also:
IFile.setContents(java.io.InputStream,int,IProgressMonitor)

setContents

public void setContents(IFileState source,
                        boolean force,
                        boolean keepHistory,
                        org.eclipse.core.runtime.IProgressMonitor monitor)
                 throws org.eclipse.core.runtime.CoreException
Description copied from interface: IFile
Sets the contents of this file to the bytes in the given file state.

This is a convenience method, fully equivalent to:

   setContents(source, (keepHistory ? KEEP_HISTORY : IResource.NONE) | (force ? FORCE : IResource.NONE), monitor);
 

This method changes resources; these changes will be reported in a subsequent resource change event, including an indication that this file's content have been changed.

This method is long-running; progress and cancellation are provided by the given progress monitor.

Specified by:
setContents in interface IFile
Parameters:
source - a previous state of this resource
force - a flag controlling how to deal with resources that are not in sync with the local file system
keepHistory - a flag indicating whether or not store the current contents in the local history
monitor - a progress monitor, or null if progress reporting is not desired
Throws:
org.eclipse.core.runtime.CoreException - if this method fails. Reasons include:
  • This resource does not exist.
  • The state does not exist.
  • The corresponding location in the local file system is occupied by a directory.
  • The workspace is not in sync with the corresponding location in the local file system and force is false.
  • Resource changes are disallowed during certain types of resource change event notification. See IResourceChangeEvent for more details.
  • The file modification validator disallowed the change.
See Also:
IFile.setContents(IFileState,int,IProgressMonitor)