Java.io.File and IndexedDB

104 views
Skip to first unread message

reportm...@gmail.com

unread,
Nov 21, 2022, 9:07:28 PM11/21/22
to TeaVM
Does TeaVM have a way to write persistent files in the local browser cache? I was thinking that reading and writing standard Java files worked using IndexedDB, but I haven’t found any reference to it. Currently, it seems like when I write a file it disappears when I reload the page.

Steve Hannah

unread,
Nov 21, 2022, 11:46:32 PM11/21/22
to reportm...@gmail.com, TeaVM
I used the localforage library to implement the file system API in CodenameOne's js port.  It was quite nice to work with.



On Mon, Nov 21, 2022 at 6:07 PM reportm...@gmail.com <reportm...@gmail.com> wrote:
Does TeaVM have a way to write persistent files in the local browser cache? I was thinking that reading and writing standard Java files worked using IndexedDB, but I haven’t found any reference to it. Currently, it seems like when I write a file it disappears when I reload the page.

--
You received this message because you are subscribed to the Google Groups "TeaVM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to teavm+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/teavm/fbc8c151-3867-4d27-a0d6-33e27c193198n%40googlegroups.com.
--
Steve Hannah
Web Lite Solutions Corp.

Alexey Andreev

unread,
Nov 22, 2022, 3:25:00 AM11/22/22
to TeaVM
Is it so important to use java.io.File in your project? Why you don't just work with IndexedDB directly? java.io.File was not designed to be implemented over IndexedDB and thus you won't get efficient result. TeaVM provides java.io.File implementation for compatibility, i.e. there's already some library that uses java.io.File. I implemented this API to compile javac, which relies on java.io heavily.

Anyway, if for some reason you want to use java.io.File, you can just implement VirtualFileSystem interface over IndexedDB and pass it to VirtualFileSystemProvider.setInstance in the very beginning of your entry point. There are two distinct strategies of writing such implementation:

1. Implement with @Async annotation, all reads/writes will be performed as they are requested by the code. Note that this will provide less efficient bloated code, not only at the points where you use java.io.File API, but on other, unpredictable points of application.
2. Implement without @Async annotation. Read entire FS content from IndexedDB on the very beginning of entry point, use deferred writes to IndexedDB during execution.

вторник, 22 ноября 2022 г. в 03:07:28 UTC+1, reportm...@gmail.com:

Jeff Martin

unread,
Nov 22, 2022, 10:21:05 AM11/22/22
to Steve Hannah, TeaVM
I’ll check that out - thanks for the tip!

I keep hoping to find a solution that would easily let my TeaVM apps save document files to cloud storage on a per user basis, so the user can access from any device and/or share publicly. Even better if it had a path to eventually offer it as a subscription service.

If anyone has any thoughts, experience or even good google search keywords, I would love to hear about it. :-)

jeff

Jeff Martin

unread,
Nov 22, 2022, 10:27:38 AM11/22/22
to Alexey Andreev, TeaVM
You are right - having File/IndexedDB support doesn’t really buy much. I just thought I’d take advantage of it if it was there. In fact, I’ve always worried it was dangerous, because users can be fooled into thinking those files are reliably there, only to have them disappear for various reasons.

jeff


--
You received this message because you are subscribed to a topic in the Google Groups "TeaVM" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/teavm/zYx5s_zOyzU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to teavm+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/teavm/4658231c-d9ac-4ffd-957f-09feee10007cn%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages