Tôi đang sử dụng một ánh xạ có thể chuyển đổi BinaryFiles (JPEG) cho một chuỗi file Hadoop (HSF):Làm cách nào để có được ngày sửa đổi cuối cùng từ một Tệp chuỗi 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()));
sau đó tôi có một ánh xạ thứ hai mà đọc HSF, như sau:
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());
và calculatePhash là:
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;
Tất cả đều hoạt động tốt, nhưng tôi muốn calculPhash ghi lại ngày sửa đổi cuối cùng của jpeg. Tôi biết tôi có thể sử dụng file.lastModified()
để có được ngày sửa đổi cuối cùng trong một tập tin nhưng có cách nào để có được điều này trong bản đồ hoặc calculPhash? Tôi là một noob ở Java. TIA!
Thêm mã vào khóa! Vì vậy, rõ ràng bây giờ. Cảm ơn!! – schoon