Modified: hadoop/core/trunk/src/java/org/apache/hadoop/io/MapFile.java
URL: 
http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/io/MapFile.java?rev=618347&r1=618346&r2=618347&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/io/MapFile.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/io/MapFile.java Mon Feb  4 
09:54:35 2008
@@ -246,12 +246,31 @@
     /** Construct a map reader for the named map using the named comparator.*/
     public Reader(FileSystem fs, String dirName, WritableComparator 
comparator, Configuration conf)
       throws IOException {
+      this(fs, dirName, comparator, conf, true);
+    }
+    
+    /**
+     * Hook to allow subclasses to defer opening streams until further
+     * initialization is complete.
+     * @see #createDataFileReader(FileSystem, Path, Configuration)
+     */
+    protected Reader(FileSystem fs, String dirName,
+        WritableComparator comparator, Configuration conf, boolean open)
+      throws IOException {
+      
+      if (open) {
+        open(fs, dirName, comparator, conf);
+      }
+    }
+    
+    protected synchronized void open(FileSystem fs, String dirName,
+        WritableComparator comparator, Configuration conf) throws IOException {
       Path dir = new Path(dirName);
       Path dataFile = new Path(dir, DATA_FILE_NAME);
       Path indexFile = new Path(dir, INDEX_FILE_NAME);
 
       // open the data
-      this.data = new SequenceFile.Reader(fs, dataFile,  conf);
+      this.data = createDataFileReader(fs, dataFile, conf);
       this.firstPosition = data.getPosition();
 
       if (comparator == null)
@@ -261,6 +280,15 @@
 
       // open the index
       this.index = new SequenceFile.Reader(fs, indexFile, conf);
+    }
+
+    /**
+     * Override this method to specialize the type of
+     * [EMAIL PROTECTED] SequenceFile.Reader} returned.
+     */
+    protected SequenceFile.Reader createDataFileReader(FileSystem fs,
+        Path dataFile, Configuration conf) throws IOException {
+      return new SequenceFile.Reader(fs, dataFile,  conf);
     }
 
     private void readIndex() throws IOException {

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/io/SequenceFile.java
URL: 
http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/io/SequenceFile.java?rev=618347&r1=618346&r2=618347&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/io/SequenceFile.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/io/SequenceFile.java Mon Feb  
4 09:54:35 2008
@@ -1391,11 +1391,20 @@
                    long length, Configuration conf, boolean tempReader) 
     throws IOException {
       this.file = file;
-      this.in = fs.open(file, bufferSize);
+      this.in = openFile(fs, file, bufferSize, length);
       this.conf = conf;
       seek(start);
       this.end = in.getPos() + length;
       init(tempReader);
+    }
+
+    /**
+     * Override this method to specialize the type of
+     * [EMAIL PROTECTED] FSDataInputStream} returned.
+     */
+    protected FSDataInputStream openFile(FileSystem fs, Path file,
+        int bufferSize, long length) throws IOException {
+      return fs.open(file, bufferSize);
     }
     
     private Decompressor getPooledOrNewDecompressor() {


Reply via email to