aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2018-12-31 14:58:03 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2018-12-31 14:58:03 +0000
commit55531bcd0502dde1fea00957a1b4ec3f32b1e7f8 (patch)
tree3ddc55b907b927dd8ad3b0e1cea1ec677759f3bd /src
parent4b11b375e8b01600edba55b1d296a43f512ad08a (diff)
downloadjackcess-55531bcd0502dde1fea00957a1b4ec3f32b1e7f8.tar.gz
jackcess-55531bcd0502dde1fea00957a1b4ec3f32b1e7f8.zip
fix channel open options for new files
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/jdk8@1257 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java16
-rw-r--r--src/test/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java2
2 files changed, 12 insertions, 6 deletions
diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java
index c005651..1db1c3b 100644
--- a/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java
+++ b/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java
@@ -204,9 +204,13 @@ public class DatabaseImpl implements Database, DateTimeContext
/** read-only channel access mode */
public static final OpenOption[] RO_CHANNEL_OPTS =
{StandardOpenOption.READ};
- /** read/write channel access mode */
+ /** read/write channel access mode for existing files */
public static final OpenOption[] RW_CHANNEL_OPTS =
{StandardOpenOption.READ, StandardOpenOption.WRITE};
+ /** read/write/create channel access mode for new files */
+ public static final OpenOption[] RWC_CHANNEL_OPTS =
+ {StandardOpenOption.READ, StandardOpenOption.WRITE,
+ StandardOpenOption.CREATE};
/** Name of the system object that is the parent of all tables */
private static final String SYSTEM_OBJECT_NAME_TABLES = "Tables";
@@ -388,7 +392,7 @@ public class DatabaseImpl implements Database, DateTimeContext
readOnly |= !Files.isWritable(mdbFile);
// open file channel
- channel = openChannel(mdbFile, readOnly);
+ channel = openChannel(mdbFile, readOnly, false);
closeChannel = true;
}
@@ -459,7 +463,7 @@ public class DatabaseImpl implements Database, DateTimeContext
boolean closeChannel = false;
if(channel == null) {
- channel = openChannel(mdbFile, false);
+ channel = openChannel(mdbFile, false, true);
closeChannel = true;
}
@@ -494,10 +498,12 @@ public class DatabaseImpl implements Database, DateTimeContext
* that name cannot be created, or if some other error occurs
* while opening or creating the file
*/
- static FileChannel openChannel(Path mdbFile, boolean readOnly)
+ static FileChannel openChannel(
+ Path mdbFile, boolean readOnly, boolean create)
throws IOException
{
- OpenOption[] opts = (readOnly ? RO_CHANNEL_OPTS : RW_CHANNEL_OPTS);
+ OpenOption[] opts = (readOnly ? RO_CHANNEL_OPTS :
+ (create ? RWC_CHANNEL_OPTS : RW_CHANNEL_OPTS));
return FileChannel.open(mdbFile, opts);
}
diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java
index 36ab9bd..66c8a71 100644
--- a/src/test/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java
+++ b/src/test/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java
@@ -194,7 +194,7 @@ public class JetFormatTest extends TestCase {
for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) {
final FileChannel channel = DatabaseImpl.openChannel(
- testDB.dbFile.toPath(), false);
+ testDB.dbFile.toPath(), false, false);
try {
JetFormat fmtActual = JetFormat.getFormat(channel);