I (HSF) bir Hadoop Dizi Dosyasına BinaryFiles (JPEG) dönüştüren bir mapper kullanıyorum:Son değiştirilme tarihini Hadoop Sekans Dosyasından nasıl alabilirim?
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()));
Sonra HSF okur ikinci bir mapper var, böylece:
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());
ve calculatePhash geçerli:
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;
Bu, tüm iyi çalışır, ancak calculatePhash her JPEG en son değiştirilme tarihini yazmak istiyorum. Ben dosyasındaki son değiştirilme tarihi almak için file.lastModified()
kullanabilir ama harita veya calculatePhash birinde bu almak için herhangi bir yolu yoktur biliyoruz? Java'da noob var. TIA!
anahtarına ekleyin! Şimdi çok açık. Teşekkürler!! – schoon