Class ServerFile

java.lang.Object
uk.co.sculptor.kflibjava.ServerFile
All Implemented Interfaces:
AutoCloseable

public class ServerFile extends Object implements 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 the AutoCloseable 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
  • Method Details

    • close

      public void close() throws IOException, KfException
      Close the Server file.
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol.
    • closeFile

      public void closeFile() throws IOException, KfException
      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 last refreshStatus() issued.
      Returns:
      true if the file exists.
    • getAccessTime

      public long getAccessTime()
      Get the value at the ServerFile object creation (Server.openServerFile(String)) or the last refreshStatus() issued.
      Returns:
      The file access time.
    • getCreateTime

      public long getCreateTime()
      Get the value at the ServerFile object creation (Server.openServerFile(String)) or the last refreshStatus() issued.
      Returns:
      The file create time.
    • getDev

      public long getDev()
      Get the value at the ServerFile object creation (Server.openServerFile(String)) or the last refreshStatus() issued.
      Returns:
      ID of device containing File.
      Since:
      Sculptor Version 6.2.0
    • getFileName

      public String getFileName()
      Path on the server that represents the file.
      Returns:
      The file name.
    • getFilePointer

      public long getFilePointer() throws IOException, KfException
      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 last refreshStatus() issued.
      Returns:
      The file inode number.
      Since:
      Sculptor Version 6.2.0
    • getInputStream

      public InputStream getInputStream() throws KfException
      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 last refreshStatus() issued.
      Returns:
      The file mode.
    • getModifyTime

      public long getModifyTime()
      Get the value at the ServerFile object creation (Server.openServerFile(String)) or the last refreshStatus() issued.
      Returns:
      The file modify time.
    • getNumLinks

      public short getNumLinks()
      Get the value at the ServerFile object creation (Server.openServerFile(String)) or the last refreshStatus() issued.
      Returns:
      The number of hard links.
      Since:
      Sculptor Version 6.2.0
    • getOutputStream

      public OutputStream getOutputStream() throws KfException
      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 last refreshStatus() 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 last refreshStatus() issued.
      Returns:
      The file size.
    • makePath

      public void makePath(short mode) throws IOException, KfException
      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 by ServerFile.OpenType Read/Write type.
      openOption - Open the file as specified by ServerFile.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 by ServerFile.OpenType Read/Write type.
      openOption - Open the file as specified by ServerFile.OpenOption option.
      openMode - Open the file as specified by ServerFile.OpenMode mode.
      Throws:
      IOException - If an I/O error occurs when using the socket.
      KfException - Any error on the KfServer protocol or parameters.
    • refreshStatus

      public void refreshStatus() throws IOException, KfException
      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

      public void seek(long pos) throws IOException, KfException
      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

      public void seek(long pos, ServerFile.SeekOrigin seekOrigin) throws IOException, KfException
      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.