-
public interface FileContents
FileContents
objects encapsulate the name and contents of a file. An implementation of this class is used by theFileOpenService
,FileSaveService
, andPersistenceService
.The
FileContents
implementation returned byPersistenceService.get(java.net.URL)
,FileOpenService
, andFileSaveService
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 Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
canRead()
Returns whether the file can be read.boolean
canWrite()
Returns whether the file can be written to.InputStream
getInputStream()
Gets anInputStream
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.String
getName()
Gets the file name as aString
.OutputStream
getOutputStream(boolean overwrite)
Gets anOutputStream
to the file.JNLPRandomAccessFile
getRandomAccessFile(String mode)
Returns aJNLPRandomAccessFile
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
String getName() throws IOException
Gets the file name as aString
.- Returns:
- a string containing the file name.
- Throws:
IOException
- if an I/O exception occurs.
-
getInputStream
InputStream getInputStream() throws IOException
Gets anInputStream
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 anOutputStream
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
- iftrue
, 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 aJNLPRandomAccessFile
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.
-
-