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) throws IOException {
79 throw new NonWritableChannelException();
80 }
81
82 @Override
83 public void force(boolean metaData) throws IOException {
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 throws IOException
97 {
98 throw new NonWritableChannelException();
99 }
100
101 @Override
102 public int write(ByteBuffer src, long position) throws IOException {
103 throw new NonWritableChannelException();
104 }
105
106
107 @Override
108 public int write(ByteBuffer src) throws IOException {
109 throw new NonWritableChannelException();
110 }
111
112 @Override
113 public long write(ByteBuffer[] srcs, int offset, int length)
114 throws IOException
115 {
116 throw new NonWritableChannelException();
117 }
118
119 @Override
120 public MappedByteBuffer map(MapMode mode, long position, long size)
121 throws IOException
122 {
123 throw new UnsupportedOperationException();
124 }
125
126 @Override
127 public FileLock lock(long position, long size, boolean shared)
128 throws IOException
129 {
130 throw new UnsupportedOperationException();
131 }
132
133 @Override
134 public FileLock tryLock(long position, long size, boolean shared)
135 throws IOException
136 {
137 throw new UnsupportedOperationException();
138 }
139
140 @Override
141 protected void implCloseChannel() throws IOException {
142 _delegate.close();
143 }
144 }