KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > jnlp > FileContents


1 /*
2  * @(#)FileContents.java 1.21 04/03/12
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.jnlp;
9
10 import java.io.InputStream;
11 import java.io.OutputStream;
12 import java.io.File;
13 import java.io.IOException;
14
15 /**
16  * <code>FileContents</code> objects encapsulate the name
17  * and contents of a file. An implementation of this class is
18  * used by the <code>FileOpenService</code>,
19  * <code>FileSaveService</code>, and
20  * <code>PersistenceService</code>.
21  * <p>
22  * The <code>FileContents</code> implementation returned by
23  * {@link PersistenceService#get}, <code>FileOpenService</code>,
24  * and <code>FileSaveService</code> should never truncate a file
25  * if the maximum file length is set to be less that the current
26  * file length.
27  *
28  * @since 1.0
29  *
30  * @see FileOpenService
31  * @see FileSaveService
32  *
33  */

34 public interface FileContents {
35     
36     /**
37      * Gets the file name as a <code>String</code>.
38      *
39      * @return a string containing the file name.
40      *
41      * @throws IOException if an I/O exception occurs.
42      */

43     public String getName() throws IOException;
44     
45     /**
46      * Gets an <code>InputStream</code> from the file.
47      *
48      * @return an InputStream to the file.
49      *
50      * @throws IOException if an I/O exception occurs.
51      */

52     public InputStream getInputStream() throws IOException;
53     
54     /**
55      * Gets an <code>OutputStream</code> to the file. A JNLP
56      * client may implement this interface to return an OutputStream
57      * subclass which restricts the amount of data that can be
58      * written to the stream.
59      *
60      * @return an OutputStream from the file.
61      *
62      * @throws IOException if an I/O exception occurs.
63      */

64     public OutputStream getOutputStream(boolean overwrite) throws IOException;
65     
66     /**
67      * Gets the length of the file.
68      *
69      * @return the length of the file as a long.
70      *
71      * @throws IOException if an I/O exception occurs.
72      */

73     public long getLength() throws IOException;
74     
75     /**
76      * Returns whether the file can be read.
77      *
78      * @return true if the file can be read, false otherwise.
79      *
80      * @throws IOException if an I/O exception occurs.
81      */

82     public boolean canRead() throws IOException;
83     
84     /**
85      * Returns whether the file can be written to.
86      *
87      * @return true if the file can be read, false otherwise.
88      *
89      * @throws IOException if an I/O exception occurs.
90      */

91     public boolean canWrite() throws IOException;
92     
93     /**
94      * Returns a <code>JNLPRandomAccessFile</code> representing a
95      * random access interface to the file's contents.
96      * The mode argument must either be equal to "r" or "rw",
97      * indicating the file is to be opened for input only or for both
98      * input and output, respectively. An IllegalArgumentException
99      * will be thrown if the mode is not equal to "r" or "rw".
100      *
101      * @param mode the access mode.
102      *
103      * @return a JNLPRandomAccessFile.
104      *
105      * @throws IOException if an I/O exception occurs.
106      */

107     public JNLPRandomAccessFile getRandomAccessFile(String mode) throws IOException;
108     
109     /**
110      * Gets the maximum file length for the file,
111      * as set by the creator of this object.
112      *
113      * @return the maximum length of the file.
114      *
115      * @throws IOException if an I/O exception occurs.
116      */

117     public long getMaxLength() throws IOException;
118     
119     /**
120      * Sets the maximum file length for the file. A JNLP client
121      * may enforce restrictions on setting the maximum file length.
122      * A JNLP client should not truncate a file if the maximum file length
123      * is set that is less than the current file size, but it also should
124      * not allow further writes to that file.
125      *
126      * @param maxlength the requested new maximum file length.
127      *
128      * @return the maximum file length that was granted.
129      *
130      * @throws IOException if an I/O exception occurs.
131      */

132     public long setMaxLength(long maxlength) throws IOException;
133     
134 }
135
136
137
138
139
Popular Tags