}
}
}
private void copyToLocal(Path archivePath, Path local) throws IOException {
HarReader harReader = new HarReader(archivePath, conf);
FileSystem localFS = FileSystem.getLocal(conf);
FileSystem fs = archivePath.getFileSystem(conf);
if (!localFS.getFileStatus(local).isDir()) {
throw new IOException("Path " + local + " is not a directory");
}
try {
while (harReader.hasNext()) {
HarStatus harStatus = harReader.getNext();
String harPath = harStatus.getName();
// skip top level dir
if (harPath.equals(Path.SEPARATOR)) {
continue;
}
String relativePath = harPath.substring(1);
Path output = new Path(local, relativePath);
if (harStatus.isDir()) {
localFS.mkdirs(output);
} else {
OutputStream outputStream = null;
FSDataInputStream inputStream = null;
try {
outputStream = localFS.create(output);
Path partFile = new Path(archivePath, harStatus.getPartName());
inputStream = new HarFSDataInputStream(fs, partFile,
harStatus.getStartIndex(), harStatus.getLength(), conf.getInt("io.file.buffer.size", 4096));
IOUtils.copyBytes(inputStream, outputStream, conf);
} finally {
if (outputStream != null) {
outputStream.close();
}
}
}
}
} finally {
if (harReader != null) {
harReader.close();
}
}
}