saker.build Documentation TaskDoc JavaDoc Packages
public abstract class SakerFileBase implements SakerFile
Base implementation for the SakerFile interface.

This abstract class provides the basic implementation for the functionality of SakerFile and is the basis of the in-memory file hierarchy for the build system. Clients should extend this instead of implementing SakerFile directly.

This class holds a reference to the enclosing parent directory, and has a backing field name for the file name.

The class manages the implicit synchronization behaviour described in SakerFile.

Subclasses are required to implement the functionality required for retrieving the content descriptor, and the functionality to retrieve the actual contents of the file. It is recommended that subclasses override getEfficientOpeningMethods() along with the appropriate content retrieval methods.

Fields
protected final String
The name of the file.
Constructors
public
Creates a new instance with the given file name.
Methods
public final ByteArrayRegion
Gets the raw contents of the file as a byte array.
public final String
Gets the contents of the file as a String.
public int
Gets the efficient opening methods flag of this file.
public final String
Gets the name of the file.
public final SakerDirectory
Gets the parent of this file.
public final SakerPath
Gets the path of this file.
public final ByteSource
Opens a ByteSource to the contents of the file.
public final InputStream
Opens an InputStream to the contents of the file.
public final void
Removes this file from its parent.
public final void
Synchronizes the contents of this file with the file system.
public final void
Synchronizes the contents of this file to the target file system location.
public void
Synchronizing implementation for persisting the contents of this file to the target file system location.
public boolean
synchronizeImpl(ProviderHolderPathKey pathkey, ByteSink additionalwritestream)
Overloaded synchronizing method with additional output stream to write the contents to.
public final String
Returns a string representation of the object.
public final void
Writes the contents to the parameter stream.
protected final String name
The name of the file.
Creates a new instance with the given file name.
nameThe file name.
NullPointerExceptionIf the file name is null.
InvalidPathFormatExceptionIf the file name is invalid.
public final ByteArrayRegion getBytes() throws IOException
Overridden from: SakerFile
Gets the raw contents of the file as a byte array.

This method implicitly synchronizes the contents of the file, unless SakerFile.getEfficientOpeningMethods() reports otherwise.

It is recommended to use TaskExecutionUtilities.getBytes(SakerFile) instead of calling this method directly.

The raw contents of the file.
IOExceptionIn case of I/O error.
public final String getContent() throws IOException
Overridden from: SakerFile
Gets the contents of the file as a String.

The default implementation converts the raw byte contents of the file is to string by decoding it as UTF-8 encoded data.

This method implicitly synchronizes the contents of the file, unless SakerFile.getEfficientOpeningMethods() reports otherwise.

It is recommended to use TaskExecutionUtilities.getContent(SakerFile) instead of calling this method directly.

The file contents as string.
IOExceptionIn case of I/O error.
Overridden from: SakerFile
Gets the efficient opening methods flag of this file.

An opening method is considered (performance-wise) efficient if it generally takes less resources (time and memory) to call the appropriate content method instead of trying to employ caching to the disk.

If an opening method is reported as efficient, then the implicit synchronizations will not take place specified by the documentation of SakerFile interface.

If an opening method is not reported as efficient, then calling content retrieval methods which do not end with Impl will check if the file system already has the contents of this file persisted, and will read the contents from there if it has. If not, then the contents will be synchronized with to the disk, and the contents will be retrieved in the most efficient manner. (This manner depends on the nature of the opening method.)

The default implementation returns SakerFile.OPENING_METHODS_NONE.

The efficient opening methods.
public final String getName()
Overridden from: FileHandle
Gets the name of the file.

The name of the file should be considered final and not change during the lifetime of the object.

The name may not be null, empty, "." or "..", must not contain slash characters ('/', '\\'), and must not contain the colon (':') and semicolon (';') characters.

Note that in some cases the above restriction may be violated, when root directories need to be represented. They will have a name according to the root path name they represent. I.e. They can be "/", or drive names in "drive:" format. These root directories cannot be added to other directories.

The file name.
public final SakerDirectory getParent()
Overridden from: SakerFile
Gets the parent of this file.

The parent of a file can change during the lifetime of an object.

The parent of this file.
public final SakerPath getSakerPath()
Overridden from: SakerFile
Gets the path of this file.

The path of this file is based on its parent path, appended with its name. If the file has no parent, then a relative path will be returned with a single path name which is the name of this file.

The path identifies the synchronization location of this file based on the current path configuration.

The path of this file.
public final ByteSource openByteSource() throws IOException
Overridden from: SakerFile
Opens a ByteSource to the contents of the file.

This method implicitly synchronizes the contents of the file, unless SakerFile.getEfficientOpeningMethods() reports otherwise.

It is recommended to use TaskExecutionUtilities.openByteSource(SakerFile) instead of calling this method directly.

The opened input.
IOExceptionIn caes of I/O error.
public final InputStream openInputStream() throws IOException
Overridden from: SakerFile
Opens an InputStream to the contents of the file.

This method implicitly synchronizes the contents of the file, unless SakerFile.getEfficientOpeningMethods() reports otherwise.

It is recommended to use TaskExecutionUtilities.openInputStream(SakerFile) instead of calling this method directly.

The opened input.
IOExceptionIn case of I/O error.
public final void remove()
Overridden from: SakerFile
Removes this file from its parent.

Calling this is a no-op if the file has no current parent.

public final void synchronize() throws IOException
Overridden from: SakerFile
Synchronizes the contents of this file with the file system.

The synchronization algorithm is described in the documentation of SakerFile interface.

IOExceptionIn case of I/O error or if the file doesn't have a parent.
public final void synchronize(ProviderHolderPathKey pathkey) throws IOException
Overridden from: SakerFile
Synchronizes the contents of this file to the target file system location.

The synchronization algorithm is described in the documentation of SakerFile interface.

File implementations generally should not override this method, but SakerFile.synchronizeImpl(ProviderHolderPathKey).

pathkeyThe target location of the synchronization.
IOExceptionIn case of I/O error.
Overridden from: SakerFile
Synchronizing implementation for persisting the contents of this file to the target file system location.

This method will not check if the contents of the disk have been changes in relation to this file, but will always persist it to the given location.

Subclasses should implement this method to persist its contents to the location specified by the parameter.

If subclasses override this method, they must override SakerFile.synchronizeImpl(ProviderHolderPathKey, ByteSink) as well. (They can just simply call SakerFile.synchronizeImpl(ProviderHolderPathKey) and return false.)

Subclasses should set any posix file permissions there are associated with the file during synchronization.

pathkeyThe target location of the synchronization.
IOExceptionIn case of I/O error.
public boolean synchronizeImpl(ProviderHolderPathKey pathkey, ByteSink additionalwritestream) throws SecondaryStreamException, IOException
Overridden from: SakerFile
Overloaded synchronizing method with additional output stream to write the contents to.

This method will not check if the contents of the disk have been changes in relation to this file, but will always persist it to the given location.

This method exists for performance optimization. Subclasses should override this method and attempt to concurrently persist the contents of the file to the target location and write the contents to the additional stream.

Subclasses must not throw an IOException if the writing to the additional stream failed, but rethrow them as a SecondaryStreamException. If a SecondaryStreamException is thrown, the synchronization is going to be considered as successful, and only the writing to the secondary stream is considered as failure. If an IOException is thrown, both stream writings is considered to be failed.

The implementations are not required to handle concurrent writing. This method should return true if it was able to concurrently synchronize and write the contents to the additional stream. The PriorityMultiplexOutputStream utility class can help implementations in implementing this functionality.

Overriding this method will improve the overall synchronization performance.

If subclasses override this method, they must override SakerFile.synchronizeImpl(ProviderHolderPathKey) as well.

Subclasses should set any posix file permissions there are associated with the file during synchronization.

pathkeyThe target location of the synchronization.
additionalwritestreamThe additional stream to write the contents to.
true if the contents of the file was successfully written to the additional stream.
SecondaryStreamExceptionIn case of I/O error during writing to the additional stream.
IOExceptionIn case of I/O error during synchronization.
public final String toString()
Overridden from: Object
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 
a string representation of the object.
public final void writeTo(OutputStream os) throws IOException
Overridden from: SakerFile
Writes the contents to the parameter stream.

The method implementations mustn't close the argument output.

This method implicitly synchronizes the contents of the file, unless SakerFile.getEfficientOpeningMethods() reports otherwise.

It is recommended to use TaskExecutionUtilities.writeTo(SakerFile, OutputStream) instead of calling this method directly.

IOExceptionIn case of I/O error.