A class that manages state transitions for files on a {@link FileSystem}.
Primarily this is meant to manage file renaming through various states. There are four distinct states; NEW, OPEN, CLOSED, and INVALID (represented by {@link State}) and are defined as follows.
State | Description |
---|---|
NEW | The initial state. The file has not yet been {@link #open()}ed. The only valid action is to open the file. |
OPEN | The file is open (i.e. {@link #open()} has been called) and an{@link OutputStream} is outstanding. The only valid action is to close thefile. |
CLOSED | The file has been closed (i.e. {@link #close()} has been called). Nofurther action can be performed on this instance of {@link PathManager}. A future improvement would be to support append here. |
INVALID | An error has occurred and no further action is possible. Any state can transition to INVALID. A future improvement would be to support recovery from this state. Currently this is not possible. |
When in the NEW state, no file exists. The user is expected to call {@link #open()}. On open, the file is created with an open file
path name. This is {@code baseDirectory + File.separator + fileName + PathManager.openExtension}and should indicate to of the file system that this file is currently in use and should be avoided (if they desire consistency). When the developer is done writing data to the file's {@link OutputStream}, they should call {@link #close()}. This will transition to the CLOSED state and commit the file by renaming it (i.e. removing the {@link PathManager} .openExtension).
It is possible to understand what state the file is in by calling {@link #getState()} and what the current {@link Path} is by using either{@link #getOpenPath()} or {@link #getClosedPath()}, respectively.
|
|