NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Re: creating temporary files that can be made permanent

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Platform Users
View previous topic :: View next topic  
Author Message
Tim Dudgeon
Posted via mailing list.





PostPosted: Tue Aug 19, 2008 2:51 pm    Post subject: Re: creating temporary files that can be made permanent Reply with quote

Tom,

yes, that would be one approach, but my files are potentially very
large, so using memory file system would not be good.

I think my only option is to use a temp file, but copy it to a new
standard one (and renaming them appropriately) if the the user decides
to make it permanent.

But I was just wondering whether there is a better approach.


Tim



Tom Wheeler wrote:
Quote:
On Tue, Aug 19, 2008 at 8:53 AM, Tim Dudgeon
<tdudgeon@informaticsmatters.com> wrote:
Quote:
I have a need to create a file that will be discarded when my NB platform
based app closes, but with the option that the user can make the file
permanament, in which case they will not be deleted.

Hi Tim,

One way would be to create the file in a memory-based filesystem and
then copy it over to a different location if the user wishes to keep
it. You may find Tonny Kohar's blog post about the memory filesystem
helpful:

http://blogs.kiyut.com/tonny/2007/09/01/netbeans-platform-and-memory-file-system/

Back to top
Tim Dudgeon
Posted via mailing list.





PostPosted: Tue Aug 19, 2008 5:38 pm    Post subject: Re: creating temporary files that can be made permanent Reply with quote

Hi Wade,

yes, something like that should do the trick.
Thanks.

Tim

Wade Chandler wrote:
Quote:
You could just make a simple cleanup routine and register a Runnable hook with the JVM or use the module close hooks. Basically it would just be a map or a list which you can add files. You can have a simple registrable interface:
class TempFileManager {
File createTempFile(String,String)
void makeTempPermanent(File)
void makePermanentTemp(File)
void delete(File)
void addFile(File)
void removeFile(File)
void deleteTempFiles()
TempFileManager getDefault();//can use services and lookup perhaps to make this dynamic and overridable
}

and deleteTempFiles is called from a shutdown hook and just iterates over all its current temp files. Create temp file mimics what File.createTempFile does and adds the files by default to the map or list of temp files. makeTempPermanent simply removes the File from the map or list. I suppose if you had a map you could easily add other methods which might be useful such as isFileTemporary(File) and things of that nature. A class doing this might take you a few hours to write at most, and should solve all your issues relatively simple. You may want to think through what temporary and permanent means though. Maybe you create them all in a permanent location and then just remove the real temp ones at the end, or you create them in the java.io.tmp (System.getProperty) and then move the permane
nt files to another permanent location on shutdown, however if you cross file system boundaries (disk level that is) then a move will be expensive, but if not such disk
boundary is crossed it will be inexpensive, but using a move scheme will require another map, but that should be small in memory relatively speaking.

Wade

==================
Wade Chandler, CCE
Software Engineer and Developer, Certified Forensic Computer Examiner, NetBeans Dream Team Member, and NetBeans Board Member
http://www.certified-computer-examiner.com
http://wiki.netbeans.org/wiki/view/NetBeansDreamTeam
http://www.netbeans.org



----- Original Message ----
Quote:
From: Tom Wheeler <tomwheel@gmail.com>
To: dev@openide.netbeans.org
Sent: Tuesday, August 19, 2008 10:02:51 AM
Subject: Re: [openide-dev] creating temporary files that can be made permanent

On Tue, Aug 19, 2008 at 8:53 AM, Tim Dudgeon
wrote:
Quote:
I have a need to create a file that will be discarded when my NB platform
based app closes, but with the option that the user can make the file
permanament, in which case they will not be deleted.
Hi Tim,

One way would be to create the file in a memory-based filesystem and
then copy it over to a different location if the user wishes to keep
it. You may find Tonny Kohar's blog post about the memory filesystem
helpful:

http://blogs.kiyut.com/tonny/2007/09/01/netbeans-platform-and-memory-file-system/


--
Tom Wheeler
http://www.tomwheeler.com/

Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Platform Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo