मैं एक Hadoop अनुक्रम फ़ाइल के लिए एक नक्शाकार कि धर्मान्तरित BinaryFiles (JPEG) का उपयोग कर रहा (HSF):मुझे हडोप अनुक्रम फ़ाइल से अंतिम संशोधित दिनांक कैसे प्राप्त हो सकता है?
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()
का उपयोग कर सकता हूं लेकिन क्या इसे मानचित्र या गणना में लाने का कोई तरीका है? मैं जावा पर एक नोब हूँ। TIA!
इसे कुंजी में जोड़ें! तो अब स्पष्ट है। धन्यवाद!! – schoon