-
public interface FileContentsFileContentsobjects encapsulate the name and contents of a file. An implementation of this class is used by theFileOpenService,FileSaveService, andPersistenceService.The
FileContentsimplementation returned byPersistenceService.get(java.net.URL),FileOpenService, andFileSaveServiceshould 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 booleancanRead()Returns whether the file can be read.booleancanWrite()Returns whether the file can be written to.InputStreamgetInputStream()Gets anInputStreamfrom the file.longgetLength()Gets the length of the file.longgetMaxLength()Gets the maximum file length for the file, as set by the creator of this object.StringgetName()Gets the file name as aString.OutputStreamgetOutputStream(boolean overwrite)Gets anOutputStreamto the file.JNLPRandomAccessFilegetRandomAccessFile(String mode)Returns aJNLPRandomAccessFilerepresenting a random access interface to the file's contents.longsetMaxLength(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 anInputStreamfrom the file.- Returns:
- an InputStream to the file.
- Throws:
IOException- if an I/O exception occurs.
-
getOutputStream
OutputStream getOutputStream(boolean overwrite) throws IOException
Gets anOutputStreamto 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 IOExceptionGets 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 IOExceptionReturns 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 IOExceptionReturns 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 aJNLPRandomAccessFilerepresenting 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 IOExceptionGets 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 IOExceptionSets 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.
-
-