【发布时间】:2014-07-07 22:45:13
【问题描述】:
我正在开发一个 Hadoop 应用程序来处理 DICOM 文件。 这些文件分布在 HDFS 上。
我正在使用修改后的 RecordReader,它读取整个文件并将其内容作为键值对发出。记录阅读器工作正常。
文件的所有文件数据都在ByteWritable值中。 我已经检查过了,数据完全等于原始文件。 因此,inputContent 具有与原始文件相同的值。
将 ByteWritable 转换为字节数组后,我无法将其转换为流并生成新的 DICOM 图像 - 使用 imageJ api - 及其内容。
我怎样才能使用这个 API 做到这一点?
以下代码示例:
public void inputTester()
{
DICOM image;
Configuration testConf = new Configuration(false);
/* Reads the local file system */
testConf.set("fs.default.name", "file:///");
File testFile = new File("path/to/dicom/file");
Path path = new Path(testFile.getAbsoluteFile().toURI());
FileSplit split = new FileSplit(path, 0, testFile.length(), null);
InputFormat inputFormat = ReflectionUtils.newInstance(WholeFileInputFormat.class, testConf);
TaskAttemptContext context = new TaskAttemptContextImpl(testConf, new TaskAttemptID());
try
{
RecordReader reader = inputFormat.createRecordReader(split, context);
while (reader.nextKeyValue())
{
/* get the bytes array */
BytesWritable inputBytesWritable = (BytesWritable) reader.getCurrentValue();
byte[] inputContent = inputBytesWritable.getBytes();
InputStream is = new ByteArrayInputStream(inputContent);
image = new DICOM(is);
}
}
catch (Exception e)
{
}
}
}
【问题讨论】: