1 2 3 4 package net.nutch.io; 5 6 import java.io.*; 7 import net.nutch.fs.*; 8 import net.nutch.util.*; 9 10 11 public class ArrayFile extends MapFile { 12 13 protected ArrayFile() {} 15 16 public static class Writer extends MapFile.Writer { 17 private LongWritable count = new LongWritable(0); 18 19 20 public Writer(NutchFileSystem nfs, String file, Class valClass) throws IOException { 21 super(nfs, file, LongWritable.class, valClass); 22 } 23 24 25 public synchronized void append(Writable value) throws IOException { 26 super.append(count, value); count.set(count.get()+1); } 29 } 30 31 32 public static class Reader extends MapFile.Reader { 33 private LongWritable key = new LongWritable(); 34 35 36 public Reader(NutchFileSystem nfs, String file) throws IOException { 37 super(nfs, file); 38 } 39 40 41 public synchronized void seek(long n) throws IOException { 42 key.set(n); 43 seek(key); 44 } 45 46 47 public synchronized Writable next(Writable value) throws IOException { 48 return next(key, value) ? value : null; 49 } 50 51 54 public synchronized long key() throws IOException { 55 return key.get(); 56 } 57 58 59 public synchronized Writable get(long n, Writable value) 60 throws IOException { 61 key.set(n); 62 return get(key, value); 63 } 64 } 65 66 } 67 | Popular Tags |