Module java.jnlp
Package javax.jnlp

Interface FileContents


  • public interface FileContents
    FileContents objects encapsulate the name and contents of a file. An implementation of this class is used by the FileOpenService, FileSaveService, and PersistenceService.

    The FileContents implementation returned by PersistenceService.get(java.net.URL), FileOpenService, and FileSaveService should never truncate a file if the maximum file length is set to be less that the current file length.

    Since:
    1.4.2
    See Also:
    FileOpenService, FileSaveService
    • Method Detail

      • getName

        String getName()
                throws IOException
        Gets the file name as a String.
        Returns:
        a string containing the file name.
        Throws:
        IOException - if an I/O exception occurs.
      • getInputStream

        InputStream getInputStream()
                            throws IOException
        Gets an InputStream from the file.
        Returns:
        an InputStream to the file.
        Throws:
        IOException - if an I/O exception occurs.
      • getOutputStream

        OutputStream getOutputStream​(boolean overwrite)
                              throws IOException
        Gets an OutputStream to the file. A JNLP client may implement this interface to return an OutputStream subclass which restricts the amount of data that can be written to the stream.
        Parameters:
        overwrite - if true, then bytes will be written to the beginning of the file rather than the end
        Returns:
        an OutputStream from the file.
        Throws:
        IOException - if an I/O exception occurs.
      • getLength

        long getLength()
                throws IOException
        Gets the length of the file.
        Returns:
        the length of the file as a long.
        Throws:
        IOException - if an I/O exception occurs.
      • canRead

        boolean canRead()
                 throws IOException
        Returns whether the file can be read.
        Returns:
        true if the file can be read, false otherwise.
        Throws:
        IOException - if an I/O exception occurs.
      • canWrite

        boolean canWrite()
                  throws IOException
        Returns whether the file can be written to.
        Returns:
        true if the file can be read, false otherwise.
        Throws:
        IOException - if an I/O exception occurs.
      • getRandomAccessFile

        JNLPRandomAccessFile getRandomAccessFile​(String mode)
                                          throws IOException
        Returns a JNLPRandomAccessFile representing a random access interface to the file's contents. The mode argument must either be equal to "r" or "rw", indicating the file is to be opened for input only or for both input and output, respectively. An IllegalArgumentException will be thrown if the mode is not equal to "r" or "rw".
        Parameters:
        mode - the access mode.
        Returns:
        a JNLPRandomAccessFile.
        Throws:
        IOException - if an I/O exception occurs.
      • getMaxLength

        long getMaxLength()
                   throws IOException
        Gets the maximum file length for the file, as set by the creator of this object.
        Returns:
        the maximum length of the file.
        Throws:
        IOException - if an I/O exception occurs.
      • setMaxLength

        long setMaxLength​(long maxlength)
                   throws IOException
        Sets the maximum file length for the file. A JNLP client may enforce restrictions on setting the maximum file length. A JNLP client should not truncate a file if the maximum file length is set that is less than the current file size, but it also should not allow further writes to that file.
        Parameters:
        maxlength - the requested new maximum file length.
        Returns:
        the maximum file length that was granted.
        Throws:
        IOException - if an I/O exception occurs.