Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Is there some simple library that helps me in saving, loading, deleting etc. the files? It's not that tricky to implement it myself, but I wonder if there are existing solutions? Just a simple library that already provides easy access to filesystem (preferrably over different operating systems).</p> </blockquote> <p><strong>Java API</strong></p> <p>Well, if what you need to do is really simple, you should be able to achieve your goal with <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html" rel="nofollow noreferrer">java.io.File</a> (delete, check existence, read, write, etc.) and a few stream manipulations with <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileInputStream.html" rel="nofollow noreferrer">FileInputStream</a> and <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileOutputStream.html" rel="nofollow noreferrer">FileOutputStream</a>. </p> <p>You can also throw in Apache <a href="http://commons.apache.org/io/" rel="nofollow noreferrer">commons-io</a> and its handy <a href="http://commons.apache.org/io/api-1.4/org/apache/commons/io/FileUtils.html" rel="nofollow noreferrer">FileUtils</a> for a few more utility functions.</p> <p>Java is independent of the OS. You just need to make sure you use <code>File.pathSeparator</code>, or use the constructor <code>File(File parent, String child)</code> so that you don't need to explicitly mention the separator. </p> <p>The Java file API is relatively high-level to abstract the differences of the many OS. Most of the time it's sufficient. It has some shortcomings only if you need some relatively OS-specific feature which is not in the API, e.g. check the physical size of a file on the disk (not the the logical size), security rights on *nix, free space/quota of the hard drive, etc. </p> <p>Most OS have an internal buffer for file writing/reading. Using <code>FileOutputStream.write</code> and <code>FileOutputStream.flush</code> ensure the data have been sent to the OS, but not necessary written on the disk. The Java API support also this low-level integration to manage these buffering issue (example <a href="http://www.exampledepot.com/egs/java.io/Sync.html" rel="nofollow noreferrer">here</a>) for system such as database.</p> <p>Also both file and directory are abstracted with <code>File</code> and you need to check with <code>isDirectory</code>. This can be confusing, for instance if you have one file <code>x</code>, and one directory <code>/x</code> (I don't remember exactly how to handle this issue, but there is a way).</p> <p><strong>Web service</strong></p> <p>The web service can use either <code>xs:base64Binary</code> to pass the data, or use <a href="https://jax-ws.dev.java.net/guide/Binary_Attachments__MTOM_.html" rel="nofollow noreferrer">MTOM</a> (Message Transmission Optimization Mechanism) if files are large.</p> <p><strong>Transactions</strong></p> <p>Note that the database is transactional and the file system not. So you might have to add a few checks if operations fails and are re-tried. </p> <p>You could go with a complicated design involving some form of distributed transaction (see this <a href="https://stackoverflow.com/questions/2422603/how-to-manage-transaction-for-database-and-file-system-in-jee-environment/2441956#2441956">answer</a>), or try to go with a simpler design that provides the level of robustness that you need. A possible design could be:</p> <ul> <li><em>Update</em>. If the user wants to overwrite a file, you actually create a new one. The level of indirection between the logical file name and the physical file is stored in database. This way you never overwrite a physical file once written, to ensure rollback is consistent.</li> <li><em>Create</em>. Same story when user want to create a file</li> <li><em>Delete</em>. If the user want to delete a file, you do it only in database first. A periodic job polls the file system to identify files which are not listed in database, and removes them. This two-phase deletes ensures that the delete operation can be rolled back. </li> </ul> <p>This is not as robust as writting BLOB in real transactional database, but provide some robustness. You could otherwise have a look at <a href="http://commons.apache.org/transaction/" rel="nofollow noreferrer">commons-transaction</a>, but I feel like the project is dead (2007).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload