1 | /* |
2 | * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0, |
3 | * and the EPL 1.0 (http://h2database.com/html/license.html). |
4 | * Initial Developer: H2 Group |
5 | */ |
6 | package org.h2.store.fs; |
7 | |
8 | import java.io.IOException; |
9 | import java.nio.ByteBuffer; |
10 | import java.nio.MappedByteBuffer; |
11 | import java.nio.channels.FileChannel; |
12 | import java.nio.channels.FileLock; |
13 | import java.nio.channels.ReadableByteChannel; |
14 | import java.nio.channels.WritableByteChannel; |
15 | |
16 | /** |
17 | * The base class for file implementations. |
18 | */ |
19 | public abstract class FileBase extends FileChannel { |
20 | |
21 | @Override |
22 | public abstract long size() throws IOException; |
23 | |
24 | @Override |
25 | public abstract long position() throws IOException; |
26 | |
27 | @Override |
28 | public abstract FileChannel position(long newPosition) throws IOException; |
29 | |
30 | @Override |
31 | public abstract int read(ByteBuffer dst) throws IOException; |
32 | |
33 | @Override |
34 | public abstract int write(ByteBuffer src) throws IOException; |
35 | |
36 | @Override |
37 | public synchronized int read(ByteBuffer dst, long position) |
38 | throws IOException { |
39 | long oldPos = position(); |
40 | position(position); |
41 | int len = read(dst); |
42 | position(oldPos); |
43 | return len; |
44 | } |
45 | |
46 | @Override |
47 | public synchronized int write(ByteBuffer src, long position) |
48 | throws IOException { |
49 | long oldPos = position(); |
50 | position(position); |
51 | int len = write(src); |
52 | position(oldPos); |
53 | return len; |
54 | } |
55 | |
56 | @Override |
57 | public abstract FileChannel truncate(long size) throws IOException; |
58 | |
59 | @Override |
60 | public void force(boolean metaData) throws IOException { |
61 | // ignore |
62 | } |
63 | |
64 | @Override |
65 | protected void implCloseChannel() throws IOException { |
66 | // ignore |
67 | } |
68 | |
69 | @Override |
70 | public FileLock lock(long position, long size, boolean shared) |
71 | throws IOException { |
72 | throw new UnsupportedOperationException(); |
73 | } |
74 | |
75 | @Override |
76 | public MappedByteBuffer map(MapMode mode, long position, long size) |
77 | throws IOException { |
78 | throw new UnsupportedOperationException(); |
79 | } |
80 | |
81 | @Override |
82 | public long read(ByteBuffer[] dsts, int offset, int length) |
83 | throws IOException { |
84 | throw new UnsupportedOperationException(); |
85 | } |
86 | |
87 | @Override |
88 | public long transferFrom(ReadableByteChannel src, long position, long count) |
89 | throws IOException { |
90 | throw new UnsupportedOperationException(); |
91 | } |
92 | |
93 | @Override |
94 | public long transferTo(long position, long count, WritableByteChannel target) |
95 | throws IOException { |
96 | throw new UnsupportedOperationException(); |
97 | } |
98 | |
99 | @Override |
100 | public FileLock tryLock(long position, long size, boolean shared) |
101 | throws IOException { |
102 | throw new UnsupportedOperationException(); |
103 | } |
104 | |
105 | @Override |
106 | public long write(ByteBuffer[] srcs, int offset, int length) |
107 | throws IOException { |
108 | throw new UnsupportedOperationException(); |
109 | } |
110 | |
111 | } |