Use collection to store path.getName() string

This commit is contained in:
xingrufei 2021-08-06 21:07:15 +08:00
parent 060af59802
commit ac718c5d80
1 changed files with 5 additions and 1 deletions

View File

@ -23,6 +23,8 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Arrays; import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -331,11 +333,13 @@ public class MapReduceBackupCopyJob implements BackupCopyJob {
private Text getKey(Path path) { private Text getKey(Path path) {
int level = conf.getInt(NUMBER_OF_LEVELS_TO_PRESERVE_KEY, 1); int level = conf.getInt(NUMBER_OF_LEVELS_TO_PRESERVE_KEY, 1);
int count = 0; int count = 0;
Deque<String> paths = new LinkedList<>();
StringBuilder relPath = new StringBuilder(); StringBuilder relPath = new StringBuilder();
while (count++ < level) { while (count++ < level) {
relPath.insert(0, Path.SEPARATOR + path.getName()); paths.addFirst(Path.SEPARATOR + path.getName());
path = path.getParent(); path = path.getParent();
} }
paths.forEach(relPath::append);
return new Text(relPath.toString()); return new Text(relPath.toString());
} }