From: James Ahlborn Date: Tue, 13 Jun 2006 14:39:54 +0000 (+0000) Subject: more tweaking to invalid file handling X-Git-Tag: rel_1_1_4~5 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1ed487c0809988afd5546b4f8bdfb7c6a7d376ac;p=jackcess.git more tweaking to invalid file handling git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@53 f203690c-595d-4dc9-a70b-905162fa7fd2 --- diff --git a/src/java/com/healthmarketscience/jackcess/Database.java b/src/java/com/healthmarketscience/jackcess/Database.java index 209173e..d5f12fe 100644 --- a/src/java/com/healthmarketscience/jackcess/Database.java +++ b/src/java/com/healthmarketscience/jackcess/Database.java @@ -177,8 +177,8 @@ public class Database { * @param mdbFile File containing the database */ public static Database open(File mdbFile) throws IOException, SQLException { - if(!JetFormat.mayBeMdbFile(mdbFile)) { - throw new FileNotFoundException("database file is empty or nonexistent"); + if(!mdbFile.exists() || !mdbFile.canRead()) { + throw new FileNotFoundException("given file does not exist: " + mdbFile); } return new Database(openChannel(mdbFile)); } diff --git a/src/java/com/healthmarketscience/jackcess/JetFormat.java b/src/java/com/healthmarketscience/jackcess/JetFormat.java index 0ecfdcd..1ed2134 100644 --- a/src/java/com/healthmarketscience/jackcess/JetFormat.java +++ b/src/java/com/healthmarketscience/jackcess/JetFormat.java @@ -115,22 +115,15 @@ public abstract class JetFormat { public static final JetFormat VERSION_4 = new Jet4Format(); - /** - * @return true if the given file could possibly be a database - * file. - */ - public static boolean mayBeMdbFile(File file) throws IOException - { - // no chance of reading the file format if none of these is true - return(file.exists() && file.canRead() && (file.length() >= 1L)); - } - /** * @return The Jet Format represented in the passed-in file */ public static JetFormat getFormat(FileChannel channel) throws IOException { ByteBuffer buffer = ByteBuffer.allocate(1); int bytesRead = channel.read(buffer, OFFSET_VERSION); + if(bytesRead < 1) { + throw new IOException("Empty database file"); + } buffer.flip(); byte version = buffer.get(); if (version == CODE_VERSION_4) {