我使用的轉換BinaryFiles(JPEG文件)映射器到一個Hadoop序列文件(HSF):如何從Hadoop序列文件獲取最後修改日期?
public void map(Object key, Text value, Context context)
throws IOException, InterruptedException {
String uri = value.toString().replace(" ", "%20");
Configuration conf = new Configuration();
FSDataInputStream in = null;
try {
FileSystem fs = FileSystem.get(URI.create(uri), conf);
in = fs.open(new Path(uri));
java.io.ByteArrayOutputStream bout = new ByteArrayOutputStream();
byte buffer[] = new byte[1024 * 1024];
while(in.read(buffer, 0, buffer.length) >= 0) {
bout.write(buffer);
}
context.write(value, new BytesWritable(bout.toByteArray()));
我然後有一個第二映射器,其讀取所述HSF,從而:
public class ImagePHashMapper extends Mapper<Text, BytesWritable, Text, Text>{
public void map(Text key, BytesWritable value, Context context) throws IOException,InterruptedException {
//get the PHash for this specific file
String PHashStr;
try {
PHashStr = calculatePhash(value.getBytes());
和calculatePhash是:
static String calculatePhash(byte[] imageData) throws NoSuchAlgorithmException {
//get the PHash for this specific data
//PHash requires inputstream rather than byte array
InputStream is = new ByteArrayInputStream(imageData);
String ph;
try {
ImagePHash ih = new ImagePHash();
ph = ih.getHash(is);
System.out.println ("file: " + is.toString() + " phash: " +ph);
} catch (Exception e) {
e.printStackTrace();
return "Internal error with ImagePHash.getHash";
}
return ph;
這一切工作正常,但我想calculatePhash寫出每個JPEG圖像的最後修改日期。我知道我可以使用file.lastModified()
獲取文件中的最後修改日期,但是有什麼方法可以在map或calculatePhash中獲取此日期嗎?我是Java的noob。 TIA!
添加到關鍵字!現在很明顯。謝謝!! – schoon 2014-11-25 11:19:34