1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.healthmarketscience.jackcess.util;
18
19 import java.io.IOException;
20 import java.nio.ByteBuffer;
21 import java.nio.MappedByteBuffer;
22 import java.nio.channels.FileChannel;
23 import java.nio.channels.FileLock;
24 import java.nio.channels.NonWritableChannelException;
25 import java.nio.channels.ReadableByteChannel;
26 import java.nio.channels.WritableByteChannel;
27 import com.healthmarketscience.jackcess.Database;
28
29
30
31
32
33
34
35
36
37
38 public class ReadOnlyFileChannel extends FileChannel
39 {
40 private final FileChannel _delegate;
41
42 public ReadOnlyFileChannel(FileChannel delegate) {
43 _delegate = delegate;
44 }
45
46 @Override
47 public int read(ByteBuffer dst) throws IOException {
48 return _delegate.read(dst);
49 }
50
51 @Override
52 public long read(ByteBuffer[] dsts, int offset, int length) throws IOException {
53 return _delegate.read(dsts, offset, length);
54 }
55
56 @Override
57 public int read(ByteBuffer dst, long position) throws IOException {
58 return _delegate.read(dst, position);
59 }
60
61 @Override
62 public long position() throws IOException {
63 return _delegate.position();
64 }
65
66 @Override
67 public FileChannel position(long newPosition) throws IOException {
68 _delegate.position(newPosition);
69 return this;
70 }
71
72 @Override
73 public long size() throws IOException {
74 return _delegate.size();
75 }
76
77 @Override
78 public FileChannel truncate(long size) {
79 throw new NonWritableChannelException();
80 }
81
82 @Override
83 public void force(boolean metaData) {
84
85 }
86
87 @Override
88 public long transferTo(long position, long count, WritableByteChannel target)
89 throws IOException
90 {
91 return _delegate.transferTo(position, count, target);
92 }
93
94 @Override
95 public long transferFrom(ReadableByteChannel src, long position, long count)
96 {
97 throw new NonWritableChannelException();
98 }
99
100 @Override
101 public int write(ByteBuffer src, long position) {
102 throw new NonWritableChannelException();
103 }
104
105
106 @Override
107 public int write(ByteBuffer src) {
108 throw new NonWritableChannelException();
109 }
110
111 @Override
112 public long write(ByteBuffer[] srcs, int offset, int length)
113 {
114 throw new NonWritableChannelException();
115 }
116
117 @Override
118 public MappedByteBuffer map(MapMode mode, long position, long size)
119 {
120 throw new UnsupportedOperationException();
121 }
122
123 @Override
124 public FileLock lock(long position, long size, boolean shared)
125 {
126 throw new UnsupportedOperationException();
127 }
128
129 @Override
130 public FileLock tryLock(long position, long size, boolean shared)
131 {
132 throw new UnsupportedOperationException();
133 }
134
135 @Override
136 protected void implCloseChannel() throws IOException {
137 _delegate.close();
138 }
139 }