42 |
import java.nio.MappedByteBuffer; |
import java.nio.MappedByteBuffer; |
43 |
import java.nio.channels.spi.AbstractInterruptibleChannel; |
import java.nio.channels.spi.AbstractInterruptibleChannel; |
44 |
|
|
45 |
|
/** |
46 |
|
* @author Michael Koch |
47 |
|
* @since 1.4 |
48 |
|
*/ |
49 |
public abstract class FileChannel extends AbstractInterruptibleChannel |
public abstract class FileChannel extends AbstractInterruptibleChannel |
50 |
implements ByteChannel, GatheringByteChannel, ScatteringByteChannel |
implements ByteChannel, GatheringByteChannel, ScatteringByteChannel |
51 |
{ |
{ |
57 |
public static MapMode READ_WRITE = new MapMode(1); |
public static MapMode READ_WRITE = new MapMode(1); |
58 |
public static MapMode PRIVATE = new MapMode(2); |
public static MapMode PRIVATE = new MapMode(2); |
59 |
|
|
60 |
|
/** |
61 |
|
* Initializes the MapMode. |
62 |
|
*/ |
63 |
MapMode(int a) |
MapMode(int a) |
64 |
{ |
{ |
65 |
m = a; |
m = a; |
67 |
|
|
68 |
public String toString() |
public String toString() |
69 |
{ |
{ |
70 |
return ""+m; |
return "" + m; |
71 |
} |
} |
72 |
} |
} |
73 |
|
|
74 |
protected FileChannel() |
/** |
75 |
|
* Initializes the channel. |
76 |
|
*/ |
77 |
|
protected FileChannel () |
78 |
{ |
{ |
79 |
} |
} |
80 |
|
|
81 |
public abstract MappedByteBuffer map(MapMode mode, long position, int size) |
/** |
82 |
|
* Maps the file into the memory. |
83 |
|
* |
84 |
|
* @exception IOException If an error occurs. |
85 |
|
*/ |
86 |
|
public abstract MappedByteBuffer map(MapMode mode, long position, long size) |
87 |
throws IOException; |
throws IOException; |
88 |
|
|
89 |
/** |
/** |
90 |
* Return the size of the file thus far |
* Return the size of the file thus far |
91 |
*/ |
*/ |
92 |
public abstract long size() throws IOException; |
public abstract long size() throws IOException; |
93 |
|
|
94 |
|
/** |
95 |
|
* Writes data to the channel. |
96 |
|
* |
97 |
|
* @exception IOException If an error occurs. |
98 |
|
*/ |
99 |
|
public long write (ByteBuffer[] srcs) throws IOException |
100 |
|
{ |
101 |
|
long result = 0; |
102 |
|
|
103 |
|
for (int i = 0; i < srcs.length; i++) |
104 |
|
{ |
105 |
|
result += write (srcs[i]); |
106 |
|
} |
107 |
|
|
108 |
|
return result; |
109 |
|
} |
110 |
|
|
111 |
|
/** |
112 |
|
* Writes data to the channel. |
113 |
|
*/ |
114 |
public abstract long write(ByteBuffer[] srcs, int offset, int length) |
public abstract long write(ByteBuffer[] srcs, int offset, int length) |
115 |
throws IOException; |
throws IOException; |
116 |
|
|
117 |
|
/** |
118 |
|
* Reads data from the channel. |
119 |
|
*/ |
120 |
public abstract int read(ByteBuffer dst) throws IOException; |
public abstract int read(ByteBuffer dst) throws IOException; |
121 |
protected abstract void implCloseChannel() throws IOException; |
|
122 |
|
/** |
123 |
|
* Closes the channel. |
124 |
|
* |
125 |
|
* This is called from @see close. |
126 |
|
* |
127 |
|
* @exception IOException If an error occurs. |
128 |
|
*/ |
129 |
|
protected abstract void implCloseChannel() throws IOException; |
130 |
|
|
131 |
/* msync with the disk */ |
/** |
132 |
|
* msync with the disk |
133 |
|
*/ |
134 |
public abstract void force(boolean metaData); |
public abstract void force(boolean metaData); |
135 |
} |
} |