System.err.println(errmsg);
return;
}
// create chains
int chain = 0;
FSOutputStream fos = null;
for (int i = 0; i < blocks.length; i++) {
LocatedBlock lblock = blocks[i];
DatanodeInfo[] locs = lblock.getLocations();
if (locs == null || locs.length == 0) {
if (fos != null) {
fos.flush();
fos.close();
fos = null;
}
continue;
}
if (fos == null) {
fos = dfs.create(new UTF8(target.toString() + "/" + chain), true);
if (fos != null) chain++;
}
if (fos == null) {
System.err.println(errmsg + ": could not store chain " + chain);
// perhaps we should bail out here...
// return;
continue;
}
// copy the block. It's a pity it's not abstracted from DFSInputStream ...
try {
copyBlock(lblock, fos);
} catch (Exception e) {
e.printStackTrace();
// something went wrong copying this block...
System.err.println(" - could not copy block " + lblock.getBlock().getBlockName() + " to " + target);
fos.flush();
fos.close();
fos = null;
}
}
if (fos != null) fos.close();
System.err.println("\n - moved corrupted file " + file.getPath() + " to /lost+found");
dfs.delete(new UTF8(file.getPath()));
} catch (Exception e) {
e.printStackTrace();
System.err.println(errmsg + ": " + e.getMessage());