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.0
  See Also:
    `FileOpenService`, `FileSaveService`

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `canRead()` Returns whether the file can be read.
    `boolean` | `canWrite()` Returns whether the file can be written to.
    `java.io.InputStream` | `getInputStream()` Gets an `InputStream` from the file.
    `long` | `getLength()` Gets the length of the file.
    `long` | `getMaxLength()` Gets the maximum file length for the file, as set by the creator of this object.
    `java.lang.String` | `getName()` Gets the file name as a `String`.
    `java.io.OutputStream` | `getOutputStream(boolean overwrite)` Gets an `OutputStream` to the file.
    `JNLPRandomAccessFile` | `getRandomAccessFile(java.lang.String mode)` Returns a `JNLPRandomAccessFile` representing a random access interface to the file's contents.
    `long` | `setMaxLength(long maxlength)` Sets the maximum file length for the file.

- - ### Method Detail

    - #### getName

          java.lang.String getName()
                            throws java.io.IOException

      Gets the file name as a `String`.
      Returns:
        a string containing the file name.
      Throws:
        `java.io.IOException` - if an I/O exception occurs.

    - #### getInputStream

          java.io.InputStream getInputStream()
                                      throws java.io.IOException

      Gets an `InputStream` from the file.
      Returns:
        an InputStream to the file.
      Throws:
        `java.io.IOException` - if an I/O exception occurs.

    - #### getOutputStream

          java.io.OutputStream getOutputStream(boolean overwrite)
                                        throws java.io.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.
      Returns:
        an OutputStream from the file.
      Throws:
        `java.io.IOException` - if an I/O exception occurs.

    - #### getLength

          long getLength()
                  throws java.io.IOException

      Gets the length of the file.
      Returns:
        the length of the file as a long.
      Throws:
        `java.io.IOException` - if an I/O exception occurs.

    - #### canRead

          boolean canRead()
                   throws java.io.IOException

      Returns whether the file can be read.
      Returns:
        true if the file can be read, false otherwise.
      Throws:
        `java.io.IOException` - if an I/O exception occurs.

    - #### canWrite

          boolean canWrite()
                    throws java.io.IOException

      Returns whether the file can be written to.
      Returns:
        true if the file can be read, false otherwise.
      Throws:
        `java.io.IOException` - if an I/O exception occurs.

    - #### getRandomAccessFile

          JNLPRandomAccessFile getRandomAccessFile(java.lang.String mode)
                                            throws java.io.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:
        `java.io.IOException` - if an I/O exception occurs.

    - #### getMaxLength

          long getMaxLength()
                     throws java.io.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:
        `java.io.IOException` - if an I/O exception occurs.

    - #### setMaxLength

          long setMaxLength(long maxlength)
                     throws java.io.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:
        `java.io.IOException` - if an I/O exception occurs.

Copyright © 1998, 2015, Oracle and/or its affiliates. All rights reserved.