|
@@ -18,10 +18,15 @@
|
|
|
package org.apache.hadoop.hdfs.server.datanode;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.FileNotFoundException;
|
|
|
import java.io.IOException;
|
|
|
|
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
|
import org.apache.hadoop.hdfs.protocol.Block;
|
|
|
+import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
|
|
|
+import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsDatasetSpi;
|
|
|
+import org.apache.hadoop.hdfs.server.datanode.fsdataset.LengthInputStream;
|
|
|
|
|
|
/** Provide utility methods for Datanode. */
|
|
|
@InterfaceAudience.Private
|
|
@@ -114,4 +119,20 @@ public class DatanodeUtil {
|
|
|
DataStorage.BLOCK_SUBDIR_PREFIX + d2;
|
|
|
return new File(root, path);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return the FileInputStream for the meta data of the given block.
|
|
|
+ * @throws FileNotFoundException
|
|
|
+ * if the file not found.
|
|
|
+ * @throws ClassCastException
|
|
|
+ * if the underlying input stream is not a FileInputStream.
|
|
|
+ */
|
|
|
+ public static FileInputStream getMetaDataInputStream(
|
|
|
+ ExtendedBlock b, FsDatasetSpi<?> data) throws IOException {
|
|
|
+ final LengthInputStream lin = data.getMetaDataInputStream(b);
|
|
|
+ if (lin == null) {
|
|
|
+ throw new FileNotFoundException("Meta file for " + b + " not found.");
|
|
|
+ }
|
|
|
+ return (FileInputStream)lin.getWrappedStream();
|
|
|
+ }
|
|
|
}
|