persolijn

an efficient router for busses
Log | Files | Refs

RandomAccessFileInputStream.java (1150B)


      1 package osm.common;
      2 
      3 import java.io.IOException;
      4 import java.io.InputStream;
      5 import java.io.RandomAccessFile;
      6 
      7 public class RandomAccessFileInputStream extends InputStream {
      8     private final RandomAccessFile file;
      9 
     10     public RandomAccessFileInputStream(RandomAccessFile file) {
     11         this.file = file;
     12     }
     13 
     14     @Override
     15     public int read() throws IOException {
     16         return file.read();
     17     }
     18 
     19     @Override
     20     public int available() throws IOException {
     21         long av = file.length() - file.getFilePointer();
     22         return av < Integer.MAX_VALUE
     23                 ? (int) av
     24                 : Integer.MAX_VALUE;
     25     }
     26 
     27     @Override
     28     public int read(byte[] buffer) throws IOException {
     29         return file.read(buffer);
     30     }
     31 
     32     @Override
     33     public int read(byte[] buffer, int offset, int length) throws IOException {
     34         return file.read(buffer, offset, length);
     35     }
     36 
     37     @Override
     38     public long skip(long size) throws IOException {
     39         long fp = file.getFilePointer();
     40         file.seek(fp + size);
     41         return size;
     42     }
     43 
     44     @Override
     45     public void close() throws IOException {
     46         file.close();
     47     }
     48 }