Package org.jdesktop.application
Class LocalStorage
- java.lang.Object
-
- org.jdesktop.application.AbstractBean
-
- org.jdesktop.application.LocalStorage
-
public class LocalStorage extends AbstractBean
Access to per application, per user, local file storage.- Author:
- Hans Muller (Hans.Muller@Sun.COM)
- See Also:
ApplicationContext.getLocalStorage()
,SessionStorage
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
LocalStorage(ApplicationContext context)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
deleteFile(java.lang.String fileName)
Deletes the entry specified by thename
parameter.protected ApplicationContext
getContext()
java.io.File
getDirectory()
Returns the directory where the local storage is locatedlong
getStorageLimit()
Gets the limit of the local storagejava.lang.Object
load(java.lang.String fileName)
Loads the been from the local storagejava.io.InputStream
openInputFile(java.lang.String fileName)
Opens an input stream to read from the entry specified by thename
parameter.java.io.OutputStream
openOutputFile(java.lang.String fileName)
Opens an output stream to write to the entry specified by thename
parameter.java.io.OutputStream
openOutputFile(java.lang.String fileName, boolean append)
Opens an output stream to write to the entry specified by thename
parameter.void
save(java.lang.Object bean, java.lang.String fileName)
Saves thebean
to the local storagevoid
setDirectory(java.io.File directory)
Sets the location of the local storagevoid
setStorageLimit(long storageLimit)
Sets the limit of the lical storage-
Methods inherited from class org.jdesktop.application.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
-
-
-
Constructor Detail
-
LocalStorage
protected LocalStorage(ApplicationContext context)
-
-
Method Detail
-
getContext
protected final ApplicationContext getContext()
-
openInputFile
public java.io.InputStream openInputFile(java.lang.String fileName) throws java.io.IOException
Opens an input stream to read from the entry specified by thename
parameter. If the named entry cannot be opened for reading then aIOException
is thrown.- Parameters:
fileName
- the storage-dependent name- Returns:
- an
InputStream
object - Throws:
java.io.IOException
- if the specified name is invalid, or an input stream cannot be opened
-
openOutputFile
public java.io.OutputStream openOutputFile(java.lang.String fileName) throws java.io.IOException
Opens an output stream to write to the entry specified by thename
parameter. If the named entry cannot be opened for writing then aIOException
is thrown. If the named entry does not exist it can be created. The entry will be recreated if already exists.- Parameters:
fileName
- the storage-dependent name- Returns:
- an
OutputStream
object - Throws:
java.io.IOException
- if the specified name is invalid, or an output stream cannot be opened
-
openOutputFile
public java.io.OutputStream openOutputFile(java.lang.String fileName, boolean append) throws java.io.IOException
Opens an output stream to write to the entry specified by thename
parameter. If the named entry cannot be opened for writing then aIOException
is thrown. If the named entry does not exist it can be created. You can decide whether data will be appended via append parameter.- Parameters:
fileName
- the storage-dependent nameappend
- iftrue
, then bytes will be written to the end of the output entry rather than the beginning- Returns:
- an
OutputStream
object - Throws:
java.io.IOException
- if the specified name is invalid, or an output stream cannot be opened
-
deleteFile
public boolean deleteFile(java.lang.String fileName) throws java.io.IOException
Deletes the entry specified by thename
parameter.- Parameters:
fileName
- the storage-dependent name- Throws:
java.io.IOException
- if the specified name is invalid, or an internal entry cannot be deleted
-
save
public void save(java.lang.Object bean, java.lang.String fileName) throws java.io.IOException
Saves thebean
to the local storage- Parameters:
bean
- the object ot be savedfileName
- the targen file name- Throws:
java.io.IOException
-
load
public java.lang.Object load(java.lang.String fileName) throws java.io.IOException
Loads the been from the local storage- Parameters:
fileName
- name of the file to be read from- Returns:
- loaded object
- Throws:
java.io.IOException
-
getStorageLimit
public long getStorageLimit()
Gets the limit of the local storage- Returns:
- the limit of the local storage
-
setStorageLimit
public void setStorageLimit(long storageLimit)
Sets the limit of the lical storage- Parameters:
storageLimit
- the limit of the lical storage
-
getDirectory
public java.io.File getDirectory()
Returns the directory where the local storage is located- Returns:
- the directory where the local storage is located
-
setDirectory
public void setDirectory(java.io.File directory)
Sets the location of the local storage- Parameters:
directory
- the location of the local storage
-
-