summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/java/com/healthmarketscience/jackcess/Database.java19
-rw-r--r--src/java/com/healthmarketscience/jackcess/JetFormat.java31
-rw-r--r--src/java/com/healthmarketscience/jackcess/UsageMap.java9
3 files changed, 50 insertions, 9 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/Database.java b/src/java/com/healthmarketscience/jackcess/Database.java
index 8609b65..e31cc7d 100644
--- a/src/java/com/healthmarketscience/jackcess/Database.java
+++ b/src/java/com/healthmarketscience/jackcess/Database.java
@@ -370,11 +370,24 @@ public class Database
EMPTY_MDB)), 0, Integer.MAX_VALUE);
return new Database(channel, autoSync);
}
-
- private static FileChannel openChannel(File mdbFile, boolean readOnly)
+
+ /**
+ * Package visible only to support unit tests via DatabaseTest.openChannel().
+ * @param mdbFile file to open
+ * @param readOnly true if read-only
+ * @return a FileChannel on the given file.
+ * @exception FileNotFoundException
+ * if the mode is <tt>"r"</tt> but the given file object does
+ * not denote an existing regular file, or if the mode begins
+ * with <tt>"rw"</tt> but the given file object does not denote
+ * an existing, writable regular file and a new regular file of
+ * that name cannot be created, or if some other error occurs
+ * while opening or creating the file
+ */
+ static FileChannel openChannel(final File mdbFile, final boolean readOnly)
throws FileNotFoundException
{
- String mode = (readOnly ? "r" : "rw");
+ final String mode = (readOnly ? "r" : "rw");
return new RandomAccessFile(mdbFile, mode).getChannel();
}
diff --git a/src/java/com/healthmarketscience/jackcess/JetFormat.java b/src/java/com/healthmarketscience/jackcess/JetFormat.java
index 38b4bc5..afb1804 100644
--- a/src/java/com/healthmarketscience/jackcess/JetFormat.java
+++ b/src/java/com/healthmarketscience/jackcess/JetFormat.java
@@ -52,6 +52,8 @@ public abstract class JetFormat {
private static final byte CODE_VERSION_3 = 0x0;
/** Version code for Jet version 4 */
private static final byte CODE_VERSION_4 = 0x1;
+ /** Version code for Jet version 5 */
+ private static final byte CODE_VERSION_5 = 0x2;
//These constants are populated by this class's constructor. They can't be
//populated by the subclass's constructor because they are final, and Java
@@ -131,10 +133,14 @@ public abstract class JetFormat {
public final Charset CHARSET;
+ public static final JetFormat VERSION_3 = new Jet3Format();
public static final JetFormat VERSION_4 = new Jet4Format();
+ public static final JetFormat VERSION_5 = new Jet5Format();
/**
+ * @param channel the database file.
* @return The Jet Format represented in the passed-in file
+ * @throws IOException if the database file format is unsupported.
*/
public static JetFormat getFormat(FileChannel channel) throws IOException {
ByteBuffer buffer = ByteBuffer.allocate(1);
@@ -144,8 +150,12 @@ public abstract class JetFormat {
}
buffer.flip();
byte version = buffer.get();
- if (version == CODE_VERSION_4) {
+ if (version == CODE_VERSION_3) {
+ return VERSION_3;
+ } else if (version == CODE_VERSION_4) {
return VERSION_4;
+ } else if (version == CODE_VERSION_5) {
+ return VERSION_5;
}
throw new IOException("Unsupported version: " + version);
}
@@ -300,10 +310,14 @@ public abstract class JetFormat {
return _name;
}
- private static final class Jet4Format extends JetFormat {
+ private static class Jet4Format extends JetFormat {
private Jet4Format() {
- super("VERSION_4");
+ this("VERSION_4");
+ }
+
+ private Jet4Format(final String name) {
+ super(name);
}
@Override
@@ -438,4 +452,15 @@ public abstract class JetFormat {
protected Charset defineCharset() { return Charset.forName("UTF-16LE"); }
}
+ private static final class Jet3Format extends Jet4Format {
+ private Jet3Format() {
+ super("VERSION_3");
+ }
+ }
+
+ private static final class Jet5Format extends Jet4Format {
+ private Jet5Format() {
+ super("VERSION_5");
+ }
+ }
}
diff --git a/src/java/com/healthmarketscience/jackcess/UsageMap.java b/src/java/com/healthmarketscience/jackcess/UsageMap.java
index 6495f0c..5e6ec1e 100644
--- a/src/java/com/healthmarketscience/jackcess/UsageMap.java
+++ b/src/java/com/healthmarketscience/jackcess/UsageMap.java
@@ -72,8 +72,11 @@ public class UsageMap
/** the current handler implementation for reading/writing the specific
usage map type. note, this may change over time. */
private Handler _handler;
-
- /**
+
+ /** Error message prefix used when map type is unrecognized. */
+ static final String MSG_PREFIX_UNRECOGNIZED_MAP = "Unrecognized map type: ";
+
+ /**
* @param database database that contains this usage map
* @param tableBuffer Buffer that contains this map's declaration
* @param pageNum Page number that this usage map is contained in
@@ -139,7 +142,7 @@ public class UsageMap
} else if (mapType == MAP_TYPE_REFERENCE) {
_handler = new ReferenceHandler();
} else {
- throw new IOException("Unrecognized map type: " + mapType);
+ throw new IOException(MSG_PREFIX_UNRECOGNIZED_MAP + mapType);
}
}