HADOOP-12967. Remove FileUtil#copyMerge. Contributed by Brahma Reddy Battula.
This commit is contained in:
parent
1e6f92977d
commit
da614ca5dc
|
@ -23,7 +23,6 @@ import java.net.InetAddress;
|
|||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -381,47 +380,6 @@ public class FileUtil {
|
|||
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
/** Copy all files in a directory to one output file (merge). */
|
||||
public static boolean copyMerge(FileSystem srcFS, Path srcDir,
|
||||
FileSystem dstFS, Path dstFile,
|
||||
boolean deleteSource,
|
||||
Configuration conf, String addString) throws IOException {
|
||||
dstFile = checkDest(srcDir.getName(), dstFS, dstFile, false);
|
||||
|
||||
if (!srcFS.getFileStatus(srcDir).isDirectory())
|
||||
return false;
|
||||
|
||||
OutputStream out = dstFS.create(dstFile);
|
||||
|
||||
try {
|
||||
FileStatus contents[] = srcFS.listStatus(srcDir);
|
||||
Arrays.sort(contents);
|
||||
for (int i = 0; i < contents.length; i++) {
|
||||
if (contents[i].isFile()) {
|
||||
InputStream in = srcFS.open(contents[i].getPath());
|
||||
try {
|
||||
IOUtils.copyBytes(in, out, conf, false);
|
||||
if (addString!=null)
|
||||
out.write(addString.getBytes("UTF-8"));
|
||||
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
out.close();
|
||||
}
|
||||
|
||||
|
||||
if (deleteSource) {
|
||||
return srcFS.delete(srcDir, true);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/** Copy local files to a FileSystem. */
|
||||
public static boolean copy(File src,
|
||||
FileSystem dstFS, Path dst,
|
||||
|
|
|
@ -19,11 +19,9 @@ package org.apache.hadoop.fs;
|
|||
|
||||
import org.junit.*;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetAddress;
|
||||
|
@ -49,7 +47,6 @@ import org.apache.hadoop.util.StringUtils;
|
|||
import org.apache.tools.tar.TarEntry;
|
||||
import org.apache.tools.tar.TarOutputStream;
|
||||
|
||||
import javax.print.attribute.URISyntax;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
@ -526,61 +523,6 @@ public class TestFileUtil {
|
|||
validateAndSetWritablePermissions(false, ret);
|
||||
}
|
||||
|
||||
@Test (timeout = 30000)
|
||||
public void testCopyMergeSingleDirectory() throws IOException {
|
||||
setupDirs();
|
||||
boolean copyMergeResult = copyMerge("partitioned", "tmp/merged");
|
||||
Assert.assertTrue("Expected successful copyMerge result.", copyMergeResult);
|
||||
File merged = new File(TEST_DIR, "tmp/merged");
|
||||
Assert.assertTrue("File tmp/merged must exist after copyMerge.",
|
||||
merged.exists());
|
||||
BufferedReader rdr = new BufferedReader(new FileReader(merged));
|
||||
|
||||
try {
|
||||
Assert.assertEquals("Line 1 of merged file must contain \"foo\".",
|
||||
"foo", rdr.readLine());
|
||||
Assert.assertEquals("Line 2 of merged file must contain \"bar\".",
|
||||
"bar", rdr.readLine());
|
||||
Assert.assertNull("Expected end of file reading merged file.",
|
||||
rdr.readLine());
|
||||
}
|
||||
finally {
|
||||
rdr.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls FileUtil.copyMerge using the specified source and destination paths.
|
||||
* Both source and destination are assumed to be on the local file system.
|
||||
* The call will not delete source on completion and will not add an
|
||||
* additional string between files.
|
||||
* @param src String non-null source path.
|
||||
* @param dst String non-null destination path.
|
||||
* @return boolean true if the call to FileUtil.copyMerge was successful.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private boolean copyMerge(String src, String dst)
|
||||
throws IOException {
|
||||
Configuration conf = new Configuration();
|
||||
FileSystem fs = FileSystem.getLocal(conf);
|
||||
final boolean result;
|
||||
|
||||
try {
|
||||
Path srcPath = new Path(TEST_ROOT_DIR, src);
|
||||
Path dstPath = new Path(TEST_ROOT_DIR, dst);
|
||||
boolean deleteSource = false;
|
||||
String addString = null;
|
||||
result = FileUtil.copyMerge(fs, srcPath, fs, dstPath, deleteSource, conf,
|
||||
addString);
|
||||
}
|
||||
finally {
|
||||
fs.close();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that getDU is able to handle cycles caused due to symbolic links
|
||||
* and that directory sizes are not added to the final calculated size
|
||||
|
|
Loading…
Reference in New Issue