2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
8 import TransactionalIO.core.Wrapper;
9 import TransactionalIO.exceptions.AbortedException;
11 import java.io.FileNotFoundException;
12 import java.io.IOException;
13 import java.io.RandomAccessFile;
19 public class SpecialTransactionalFile{
21 RandomAccessFile raFile;
23 public SpecialTransactionalFile(File arg0, String arg1) throws FileNotFoundException {
24 raFile = new RandomAccessFile(arg0, arg1);
27 public SpecialTransactionalFile(String arg0, String arg1) throws FileNotFoundException {
28 raFile = new RandomAccessFile(arg0, arg1);
32 private void checkConsisteny(){
33 // System.out.println(Thread.currentThread());
34 Transaction me = Thread.getTransaction();
36 SpecialLock.getSpecialLock().unlock(me);
37 throw new AbortedException();
39 if (me != SpecialLock.getSpecialLock().getOwnerTransaction()){
40 // System.out.println("trying to lock " + Thread.currentThread());
41 SpecialLock.getSpecialLock().lock(me);
42 // System.out.println("locked " + Thread.currentThread());
46 SpecialLock.getSpecialLock().unlock(me);
47 throw new AbortedException();
53 public void close() throws IOException {
59 public long getFilePointer() throws IOException {
61 return raFile.getFilePointer();
65 public long length() throws IOException {
67 return raFile.length();
71 public int read() throws IOException {
77 public int read(byte[] arg0, int arg1, int arg2) throws IOException {
79 return raFile.read(arg0, arg1, arg2);
83 public int read(byte[] arg0) throws IOException {
85 return raFile.read(arg0);
89 public void seek(long arg0) throws IOException {
95 public void setLength(long arg0) throws IOException {
97 raFile.setLength(arg0);
101 public int skipBytes(int arg0) throws IOException {
103 return raFile.skipBytes(arg0);
107 public void write(int arg0) throws IOException {
113 public void write(byte[] arg0) throws IOException {
119 public void write(byte[] arg0, int arg1, int arg2) throws IOException {
121 raFile.write(arg0, arg1, arg2);
124 public final void writeInt(int integer) throws IOException{
126 raFile.writeInt(integer);
129 public final int readInt() throws IOException{
131 return raFile.readInt();
134 public final void writeBoolean(boolean bool) throws IOException{
136 raFile.writeBoolean(bool);
139 public final boolean readBoolean() throws IOException{
141 return raFile.readBoolean();
144 public final void writeUTF(String val) throws IOException{
146 raFile.writeUTF(val);
149 public final String readUTF() throws IOException{
151 return raFile.readUTF();
154 public final void writeShort(short val) throws IOException{
156 raFile.writeShort(val);
159 public final short readShort() throws IOException{
161 return raFile.readShort();
164 public final void writeByte(byte arg0) throws IOException{
166 raFile.writeByte(arg0);
169 public final byte readByte() throws IOException{
171 return raFile.readByte();
174 public final void writeChar(int val) throws IOException{
176 raFile.writeChar(val);
179 public final char readChar() throws IOException{
181 return raFile.readChar();
184 public final void writeBytes(String val) throws IOException{
186 raFile.writeBytes(val);
189 public final void writeLong(long val) throws IOException{
191 raFile.writeLong(val);
194 public final long readLong() throws IOException{
196 return raFile.readLong();
199 public final void writeDouble(double arg0) throws IOException{
201 raFile.writeDouble(arg0);
204 public final double readDouble() throws IOException{
206 return raFile.readDouble();
209 public final void writeFloat(float val) throws IOException{
211 raFile.writeFloat(val);
214 public final float readFloat() throws IOException{
216 return raFile.readFloat();