Package uk.co.sculptor.kflibjava
Class ServerFile
java.lang.Object
uk.co.sculptor.kflibjava.ServerFile
- All Implemented Interfaces:
AutoCloseable
Represents a file on the server, and can be used to get the file status, read, write, modify or create the file.
Note: This class implements theAutoCloseable
interface, meaning that an object may hold resources
(such as file or socket handles) until it is closed. The close() method of an AutoCloseable object is called automatically
when exiting a try-with-resources
block for which the object has been declared in the resource specification header.
This construction ensures prompt release, avoiding resource exhaustion exceptions and errors that may otherwise occur.- Author:
- Marcos Gutierrez Batz
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Enumerator with the mode (text or binary) for opening a file.static enum
Enumerator with the options for opening a file.static enum
Enumerator with the types for opening a file.static enum
Enumerator with the possible seek origins -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close the Server file.void
Method that closes the resources and handles allocated on the server to read/write the file.int
copyFileTo
(ServerFile dstServerFile, EnumSet<Server.CopyOption> options) Copy current file to the destination ServerFile argument.boolean
Get the value at the ServerFile object creation (Server.openServerFile(String)
) or the lastrefreshStatus()
issued.long
Get the value at the ServerFile object creation (Server.openServerFile(String)
) or the lastrefreshStatus()
issued.long
Get the value at the ServerFile object creation (Server.openServerFile(String)
) or the lastrefreshStatus()
issued.long
getDev()
Get the value at the ServerFile object creation (Server.openServerFile(String)
) or the lastrefreshStatus()
issued.Path on the server that represents the file.long
Returns the current offset in this file.int
getInode()
Get the value at the ServerFile object creation (Server.openServerFile(String)
) or the lastrefreshStatus()
issued.Creates and return the InputStream to read the ServerFile.short
getMode()
Get the value at the ServerFile object creation (Server.openServerFile(String)
) or the lastrefreshStatus()
issued.long
Get the value at the ServerFile object creation (Server.openServerFile(String)
) or the lastrefreshStatus()
issued.short
Get the value at the ServerFile object creation (Server.openServerFile(String)
) or the lastrefreshStatus()
issued.Creates and return the OutputStream to write the ServerFile.long
getRDev()
Get the value at the ServerFile object creation (Server.openServerFile(String)
) or the lastrefreshStatus()
issued.long
getSize()
Get the value at the ServerFile object creation (Server.openServerFile(String)
) or the lastrefreshStatus()
issued.void
makePath
(short mode) Create the directory where the ServerFile is located.void
openFile
(ServerFile.OpenType openType, ServerFile.OpenOption openOption) Open the file on the server as a Text file (translated mode), to get the file pointer (fp) as specified on the parameters.void
openFile
(ServerFile.OpenType openType, ServerFile.OpenOption openOption, ServerFile.OpenMode openMode) Open the file on the server, to get the file pointer (fp) as specified on the parameters.void
Get the remote file status.void
seek
(long pos) Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.void
seek
(long pos, ServerFile.SeekOrigin seekOrigin) Sets the file-pointer offset, measured from the seekOrigin specified, at which the next read or write occurs.
-
Method Details
-
close
Close the Server file.- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
- Any error received by writing/reading the socket.KfException
- Any error on the KfServer protocol.
-
closeFile
Method that closes the resources and handles allocated on the server to read/write the file.- Throws:
IOException
- Any error received by writing/reading the socket.KfException
- Any error on the KfServer protocol.
-
copyFileTo
public int copyFileTo(ServerFile dstServerFile, EnumSet<Server.CopyOption> options) throws IOException, KfException Copy current file to the destination ServerFile argument. Both files must be closed and will be left closed.- Parameters:
dstServerFile
- ServerFile where to copy the information.options
- Copy options- Returns:
- return 0 if the file is not copied or 1 otherwise.
- Throws:
IOException
- Any error received by writing/reading the socket.KfException
- Any error on the KfServer protocol.
-
fileExists
public boolean fileExists()Get the value at the ServerFile object creation (Server.openServerFile(String)
) or the lastrefreshStatus()
issued.- Returns:
- true if the file exists.
-
getAccessTime
public long getAccessTime()Get the value at the ServerFile object creation (Server.openServerFile(String)
) or the lastrefreshStatus()
issued.- Returns:
- The file access time.
-
getCreateTime
public long getCreateTime()Get the value at the ServerFile object creation (Server.openServerFile(String)
) or the lastrefreshStatus()
issued.- Returns:
- The file create time.
-
getDev
public long getDev()Get the value at the ServerFile object creation (Server.openServerFile(String)
) or the lastrefreshStatus()
issued.- Returns:
- ID of device containing File.
- Since:
- Sculptor Version 6.2.0
-
getFileName
Path on the server that represents the file.- Returns:
- The file name.
-
getFilePointer
Returns the current offset in this file.- Returns:
- The current offset in the file (when is opened)
- Throws:
IOException
- Any error received by writing/reading the socket.KfException
- Any error on the KfServer protocol.
-
getInode
public int getInode()Get the value at the ServerFile object creation (Server.openServerFile(String)
) or the lastrefreshStatus()
issued.- Returns:
- The file inode number.
- Since:
- Sculptor Version 6.2.0
-
getInputStream
Creates and return the InputStream to read the ServerFile. The file must be previously open with a read mode.- Returns:
- the inputStream
- Throws:
KfException
- Any error on the KfServer protocol.
-
getMode
public short getMode()Get the value at the ServerFile object creation (Server.openServerFile(String)
) or the lastrefreshStatus()
issued.- Returns:
- The file mode.
-
getModifyTime
public long getModifyTime()Get the value at the ServerFile object creation (Server.openServerFile(String)
) or the lastrefreshStatus()
issued.- Returns:
- The file modify time.
-
getNumLinks
public short getNumLinks()Get the value at the ServerFile object creation (Server.openServerFile(String)
) or the lastrefreshStatus()
issued.- Returns:
- The number of hard links.
- Since:
- Sculptor Version 6.2.0
-
getOutputStream
Creates and return the OutputStream to write the ServerFile. The file must be previously open with a write mode.- Returns:
- the outputStream
- Throws:
KfException
- Any error on the KfServer protocol.
-
getRDev
public long getRDev()Get the value at the ServerFile object creation (Server.openServerFile(String)
) or the lastrefreshStatus()
issued.- Returns:
- ID of device containing File (if special).
- Since:
- Sculptor Version 6.2.0
-
getSize
public long getSize()Get the value at the ServerFile object creation (Server.openServerFile(String)
) or the lastrefreshStatus()
issued.- Returns:
- The file size.
-
makePath
Create the directory where the ServerFile is located.- Parameters:
mode
- Unix type of permissions used to create directories with.- Throws:
IOException
- Any error received by writing/reading the socket.KfException
- Any error on the KfServer protocol.
-
openFile
public void openFile(ServerFile.OpenType openType, ServerFile.OpenOption openOption) throws IOException, KfException Open the file on the server as a Text file (translated mode), to get the file pointer (fp) as specified on the parameters.- Parameters:
openType
- Open the file as specified byServerFile.OpenType
Read/Write type.openOption
- Open the file as specified byServerFile.OpenOption
option.- Throws:
IOException
- If an I/O error occurs when using the socket.KfException
- Any error on the KfServer protocol or parameters.
-
openFile
public void openFile(ServerFile.OpenType openType, ServerFile.OpenOption openOption, ServerFile.OpenMode openMode) throws IOException, KfException Open the file on the server, to get the file pointer (fp) as specified on the parameters.- Parameters:
openType
- Open the file as specified byServerFile.OpenType
Read/Write type.openOption
- Open the file as specified byServerFile.OpenOption
option.openMode
- Open the file as specified byServerFile.OpenMode
mode.- Throws:
IOException
- If an I/O error occurs when using the socket.KfException
- Any error on the KfServer protocol or parameters.
-
refreshStatus
Get the remote file status. There is no need for the file to be opened.- Throws:
IOException
- If an I/O error occurs when using the socket.KfException
- Any error on the KfServer protocol or parameters.
-
seek
Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.- Parameters:
pos
- the offset position, measured in bytes from the beginning of the file, at which to set the file pointer.- Throws:
IOException
- If an I/O error occurs when using the socket.KfException
- Any error on the KfServer protocol or parameters.
-
seek
Sets the file-pointer offset, measured from the seekOrigin specified, at which the next read or write occurs.- Parameters:
pos
- The offset position, measured in bytes from the beginning of the file, at which to set the file pointer.seekOrigin
- Initial position.- Throws:
IOException
- If an I/O error occurs when using the socket.KfException
- Any error on the KfServer protocol or parameters.
-