diff --git a/src/main/java/org/deepsymmetry/cratedigger/Database.java b/src/main/java/org/deepsymmetry/cratedigger/Database.java index debe11f..43f4f9c 100644 --- a/src/main/java/org/deepsymmetry/cratedigger/Database.java +++ b/src/main/java/org/deepsymmetry/cratedigger/Database.java @@ -1,10 +1,12 @@ package org.deepsymmetry.cratedigger; import io.kaitai.struct.KaitaiStruct; +import io.kaitai.struct.RandomAccessFileKaitaiStream; import org.deepsymmetry.cratedigger.pdb.RekordboxPdb; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.Closeable; import java.io.File; import java.io.IOException; import java.net.InetAddress; @@ -14,7 +16,7 @@ *
Parses rekordbox database export files, providing access to the information they contain.
*/ @SuppressWarnings("WeakerAccess") -public class Database { +public class Database implements Closeable { private static final Logger logger = LoggerFactory.getLogger(Database.class); @@ -31,7 +33,11 @@ public class Database { /** * Construct a database access instance from the specified recordbox export file. * The file can obtained either from the SD or USB media, or directly from a player - * using {@link FileFetcher#fetch(InetAddress, String, String, File)} + * using {@link FileFetcher#fetch(InetAddress, String, String, File)}. + * + * Be sure to call {@link #close()} when you are done using the parsed database + * to close the underlying file or users will be unable to unmount the drive holding + * it until they quit your program. * * @param sourceFile an export.pdb file * @@ -40,7 +46,7 @@ public class Database { @SuppressWarnings("WeakerAccess") public Database(File sourceFile) throws IOException { this.sourceFile = sourceFile; - pdb = RekordboxPdb.fromFile(sourceFile.getAbsolutePath()); + pdb = new RekordboxPdb(new RandomAccessFileKaitaiStream(sourceFile.getAbsolutePath())); final SortedMap