public class FileAccessZip extends FileRemoteAccessor
Modifier and Type | Class and Description |
---|---|
(package private) static class |
FileAccessZip.FileZipData |
(package private) static class |
FileAccessZip.FileZipInputStream
A wrapper class for the returned InputStream.
|
FileRemoteAccessor.FileWalkerThread
Modifier and Type | Field and Description |
---|---|
private static FileAccessZip |
instance |
static int |
version
Version, history and license.
|
mEventConsumed, mEventConsumerException, mEventConsumFinished, mEventDonotRelinquish, mMaskReservedHere
Constructor and Description |
---|
FileAccessZip() |
Modifier and Type | Method and Description |
---|---|
void |
abortAll()
Abort currently running and saved copy, check etc. actions.
|
void |
activate()
Activates working of the devide, thread starting, communication establishing etc.
|
void |
close() |
void |
close(FileRemote file) |
java.lang.String |
cmd(boolean bWait,
FileRemoteCmdEventData co,
EventWithDst<FileRemoteProgressEvData,?> evBack)
Common form of a command with the file.
|
java.lang.CharSequence |
completeFilePath(java.lang.CharSequence sPath)
Returns a unique absolute path for the file regarding maybe tmp, home, environment variables etc.
|
void |
copyChecked(FileRemote fileSrc,
java.lang.String pathDst,
java.lang.String nameModification,
int mode,
FileRemoteWalkerCallback callbackUser,
FileRemoteProgressEvData timeOrderProgress)
Copies all files which are checked before.
|
boolean |
createNewFile(FileRemote file,
EventWithDst<FileRemoteProgressEvData,?> evBack) |
boolean |
delete(FileRemote file,
EventWithDst<FileRemoteProgressEvData,?> evBack)
Try to delete the file.
|
EventThread_ifc |
evThread()
This operation should return that thread, which is associated to this consumer.
|
static FileRemote |
examineZipFile(FileRemote fileZip)
It examines a zip file.
|
java.util.List<java.io.File> |
getChildren(FileRemote file,
java.io.FileFilter filter)
Gets files and sub directories of a directory.
|
static FileAccessZip |
getInstance()
Returns the singleton instance of this class.
|
java.lang.CharSequence |
getStateInfo() |
boolean |
isLocalFileSystem()
Creates or prepares a CmdEvent to send to the correct destination.
|
boolean |
mkdir(FileRemote file,
boolean subdirs,
EventWithDst<FileRemoteProgressEvData,?> evBack) |
java.io.InputStream |
openInputStream(FileRemote file,
long passPhase)
Returns an opened InputStream with the Zip entry.
|
java.io.OutputStream |
openOutputStream(FileRemote file,
long passPhase)
Returns an opened InputStream with the Zip entry.
|
java.nio.channels.ReadableByteChannel |
openRead(FileRemote file,
long passPhase) |
java.nio.channels.WritableByteChannel |
openWrite(FileRemote file,
long passPhase) |
int |
processEvent(java.util.EventObject ev)
This routine should be overwritten from the user to processes an event.
|
void |
refreshFileProperties(FileRemote file,
EventWithDst<FileRemoteProgressEvData,?> evBack)
Gets the properties of the file from the physical file.
|
void |
search(FileRemote fileSrc,
byte[] search,
FileRemoteWalkerCallback callbackUser,
FileRemoteProgressEvData timeOrderProgress)
Search in all files.
|
boolean |
setLastModified(FileRemote file,
long time) |
void |
XXXrefreshFilePropertiesAndChildren(FileRemote file,
FileRemoteProgressEvData callback) |
cmdFile
public static final int version
examineZipFile(FileRemote)
if the file is faulty. It outputs an error hint
on System.err.println(). Better (TODO) FileNotFoundException.
openInputStream(FileRemote, long)
returns an opened stream and opens the ZipFile therefore.
To close the ZipFile the returned InputStream is wrapped to detect the close() invocation of the InputStream.
examineZipFile(FileRemote)
.
It opens and closes the Zipfile after building FileRemote instances for the entries. Elsewhere the ZipFile remains open
and it hangs on system till the application is closed.
TODO: Does openRead works?
FileRemoteAccessor
. Support files in zip-File
private static FileAccessZip instance
public static FileAccessZip getInstance()
public java.lang.CharSequence completeFilePath(java.lang.CharSequence sPath)
FileFunctions#absolutePath(String, File)
to fulfill all.completeFilePath
in class FileRemoteAccessor
path
- given pathpublic static FileRemote examineZipFile(FileRemote fileZip)
FileRemote
instances are created, one for each zip file entry.
The zipfile itself will be opened and closed after them.
The returned FileRemote refers all Zipfile entries as children and the zipfile itself as parent.
Any FileRemote which represents a ZipEntry contains a FileAccessZip.FileZipData
instance referred in the
FileRemote.oFile
association. Reading the content of an entry should re-open the ZipFile.fileZip
- The zip file itself (in file system).public void close()
close
in class FileRemoteAccessor
public void close(FileRemote file) throws java.io.IOException
java.io.IOException
public void refreshFileProperties(FileRemote file, EventWithDst<FileRemoteProgressEvData,?> evBack)
FileRemoteAccessor
refreshFileProperties
in class FileRemoteAccessor
file
- the destination file object.public void XXXrefreshFilePropertiesAndChildren(FileRemote file, FileRemoteProgressEvData callback)
public java.util.List<java.io.File> getChildren(FileRemote file, java.io.FileFilter filter)
FileRemoteAccessor
File
access methods to get the children of this file.getChildren
in class FileRemoteAccessor
file
- parent directory.filter
- maybe a filterpublic boolean createNewFile(FileRemote file, EventWithDst<FileRemoteProgressEvData,?> evBack) throws java.io.IOException
createNewFile
in class FileRemoteAccessor
java.io.IOException
public boolean mkdir(FileRemote file, boolean subdirs, EventWithDst<FileRemoteProgressEvData,?> evBack)
mkdir
in class FileRemoteAccessor
subdirs
- true then create all necessary dirs on the pathevBack
- It will be called on any directory which was made, to update the local instance of FileRemote.public boolean delete(FileRemote file, EventWithDst<FileRemoteProgressEvData,?> evBack)
FileRemoteAccessor
delete
in class FileRemoteAccessor
public void copyChecked(FileRemote fileSrc, java.lang.String pathDst, java.lang.String nameModification, int mode, FileRemoteWalkerCallback callbackUser, FileRemoteProgressEvData timeOrderProgress)
FileRemoteAccessor
copyChecked
in class FileRemoteAccessor
fileSrc
- dir or file as root for copy to the given pathDstpathDst
- String given destination for the copynameModification
- Modification for each name. null then no modification. TODOmode
- One of the bits FileRemote.modeCopyCreateYes
etc.callbackUser
- Maybe null, elsewhere on every directory and file which is finished to copy a callback is invoked.timeOrderProgress
- may be null, to show the progress of copy.public void search(FileRemote fileSrc, byte[] search, FileRemoteWalkerCallback callbackUser, FileRemoteProgressEvData timeOrderProgress)
FileRemoteAccessor
search
in class FileRemoteAccessor
fileSrc
- dir or file as root for search the given byte[]callbackUser
- Maybe null, elsewhere on every directory and file which is finished to copy a callback is invoked.timeOrderProgress
- may be null, to show the progress of copy.public java.nio.channels.ReadableByteChannel openRead(FileRemote file, long passPhase)
openRead
in class FileRemoteAccessor
public java.io.InputStream openInputStream(FileRemote file, long passPhase)
FileAccessZip.FileZipInputStream
.
Normally more as one InputStream can be used with one ZipFile. This routine creates a ZipFile instance
only for this one entry.openInputStream
in class FileRemoteAccessor
FileRemoteAccessor.openInputStream(org.vishia.fileRemote.FileRemote, long)
public java.io.OutputStream openOutputStream(FileRemote file, long passPhase)
FileAccessZip.FileZipInputStream
.
Normally more as one InputStream can be used with one ZipFile. This routine creates a ZipFile instance
only for this one entry.openOutputStream
in class FileRemoteAccessor
FileRemoteAccessor.openInputStream(org.vishia.fileRemote.FileRemote, long)
public java.nio.channels.WritableByteChannel openWrite(FileRemote file, long passPhase)
openWrite
in class FileRemoteAccessor
public boolean isLocalFileSystem()
FileRemoteAccessor
isLocalFileSystem
in class FileRemoteAccessor
public java.lang.CharSequence getStateInfo()
getStateInfo
in class FileRemoteAccessor
public boolean setLastModified(FileRemote file, long time)
setLastModified
in class FileRemoteAccessor
public void abortAll()
FileRemoteAccessor
abortAll
in class FileRemoteAccessor
public void activate()
FileRemoteAccessor
activate
in class FileRemoteAccessor
public EventThread_ifc evThread()
EventConsumer
public int processEvent(java.util.EventObject ev)
EventConsumer
EventConsumer.mEventConsumed
or StateSimple.mEventConsumed
: The event is designated as consumed.
If not set, the event should applied on other EventConsumer.processEvent(EventObject)
operations,
for example for other states if possible
EventConsumer.mEventDonotRelinquish
or StateSimple.mEventDonotRelinquish
: The event should not be relinquished
by the manager of the events (EventTimerThread), it will be relinquished later in the application after completion detection.
It means the application (user) declares itself responsible for relinquish. See EventWithDst.relinquish()
.
#mEventConsumerFinished
: The task which should be organized by the event is finished.
This bit is especially used to designate a TimeOrder
as finished for usage, quest in TimeOrder#awaitExecution(int, int)
.
Note that a task can need some more events or other conditions, this bit should be set on the last expected event
in the return value of EventConsumer.processEvent(EventObject)
. For example if a copy of a file tree is finished,
or the graphic implementation is completely built.
EventConsumer.mEventConsumerException
: The execution of EventConsumer.processEvent(EventObject)
has thrown an error,
which is caught in the calling environment in EventTimerThread
.
How to deal with this information - the application is responsible to, the problem should be logged or debugged.
StateSimple
.
ev
- The event. It contains some data. The type of the event is not specified here. Any events
can be processed.EventConsumer.mEventConsumed
or EventConsumer.mEventDonotRelinquish
etc. see list above.
This value is forwarded to EventSource.notifyConsumed(int)
and can be evaluated by the application
in the calling thread or in any other thread which have access to implementation of EventSource
.public java.lang.String cmd(boolean bWait, FileRemoteCmdEventData co, EventWithDst<FileRemoteProgressEvData,?> evBack)
FileRemoteAccessor
cmd
in class FileRemoteAccessor
bWait
- true then wait for fulfill. If it is a local file (depends on FileRemote.device()
,
then the execution is immediately done in the same thread.
If it is especially a file on a remote device only able to reach via communication
( for example on an embedded device), the operation should wait for success.co
- Command description. It is the payload of an command event.evBack
- prepared event for back information or also for progress.
The event knows a destination where the back event is processed.
If this argument is null, no back information will be sent. This is sensible if bWait is true,
and if the caller can check what is happen.
Hint: Usual an instance of FileRemoteProgressEventConsumer
can be used to execute the event,
and also to wait for success on user level.