Initial commit
This commit is contained in:
197
sources/com/thoughtworks/xstream/io/path/Path.java
Normal file
197
sources/com/thoughtworks/xstream/io/path/Path.java
Normal file
@@ -0,0 +1,197 @@
|
||||
package com.thoughtworks.xstream.io.path;
|
||||
|
||||
import com.thoughtworks.xstream.core.util.FastStack;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class Path {
|
||||
private static final Path DOT = new Path(new String[]{"."});
|
||||
private final String[] chunks;
|
||||
private transient String pathAsString;
|
||||
private transient String pathExplicit;
|
||||
|
||||
public Path(String str) {
|
||||
ArrayList arrayList = new ArrayList();
|
||||
this.pathAsString = str;
|
||||
int i = 0;
|
||||
while (true) {
|
||||
int indexOf = str.indexOf(47, i);
|
||||
if (indexOf == -1) {
|
||||
arrayList.add(normalize(str, i, str.length()));
|
||||
String[] strArr = new String[arrayList.size()];
|
||||
arrayList.toArray(strArr);
|
||||
this.chunks = strArr;
|
||||
return;
|
||||
}
|
||||
arrayList.add(normalize(str, i, indexOf));
|
||||
i = indexOf + 1;
|
||||
}
|
||||
}
|
||||
|
||||
private int depthOfPathDivergence(String[] strArr, String[] strArr2) {
|
||||
int min = Math.min(strArr.length, strArr2.length);
|
||||
for (int i = 0; i < min; i++) {
|
||||
if (!strArr[i].equals(strArr2[i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
private String normalize(String str, int i, int i2) {
|
||||
if (i2 - i > 3) {
|
||||
int i3 = i2 - 3;
|
||||
if (str.charAt(i3) == '[' && str.charAt(i2 - 2) == '1' && str.charAt(i2 - 1) == ']') {
|
||||
this.pathAsString = null;
|
||||
return str.substring(i, i3);
|
||||
}
|
||||
}
|
||||
return str.substring(i, i2);
|
||||
}
|
||||
|
||||
public Path apply(Path path) {
|
||||
FastStack fastStack = new FastStack(16);
|
||||
int i = 0;
|
||||
while (true) {
|
||||
String[] strArr = this.chunks;
|
||||
if (i >= strArr.length) {
|
||||
break;
|
||||
}
|
||||
fastStack.push(strArr[i]);
|
||||
i++;
|
||||
}
|
||||
int i2 = 0;
|
||||
while (true) {
|
||||
String[] strArr2 = path.chunks;
|
||||
if (i2 >= strArr2.length) {
|
||||
break;
|
||||
}
|
||||
String str = strArr2[i2];
|
||||
if (str.equals("..")) {
|
||||
fastStack.pop();
|
||||
} else if (!str.equals(".")) {
|
||||
fastStack.push(str);
|
||||
}
|
||||
i2++;
|
||||
}
|
||||
String[] strArr3 = new String[fastStack.size()];
|
||||
for (int i3 = 0; i3 < strArr3.length; i3++) {
|
||||
strArr3[i3] = (String) fastStack.get(i3);
|
||||
}
|
||||
return new Path(strArr3);
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof Path)) {
|
||||
return false;
|
||||
}
|
||||
Path path = (Path) obj;
|
||||
if (this.chunks.length != path.chunks.length) {
|
||||
return false;
|
||||
}
|
||||
int i = 0;
|
||||
while (true) {
|
||||
String[] strArr = this.chunks;
|
||||
if (i >= strArr.length) {
|
||||
return true;
|
||||
}
|
||||
if (!strArr[i].equals(path.chunks[i])) {
|
||||
return false;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public String explicit() {
|
||||
char charAt;
|
||||
if (this.pathExplicit == null) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
for (int i = 0; i < this.chunks.length; i++) {
|
||||
if (i > 0) {
|
||||
stringBuffer.append('/');
|
||||
}
|
||||
String str = this.chunks[i];
|
||||
stringBuffer.append(str);
|
||||
int length = str.length();
|
||||
if (length > 0 && (charAt = str.charAt(length - 1)) != ']' && charAt != '.') {
|
||||
stringBuffer.append("[1]");
|
||||
}
|
||||
}
|
||||
this.pathExplicit = stringBuffer.toString();
|
||||
}
|
||||
return this.pathExplicit;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int i = 543645643;
|
||||
int i2 = 0;
|
||||
while (true) {
|
||||
String[] strArr = this.chunks;
|
||||
if (i2 >= strArr.length) {
|
||||
return i;
|
||||
}
|
||||
i = (i * 29) + strArr[i2].hashCode();
|
||||
i2++;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAncestor(Path path) {
|
||||
if (path == null || path.chunks.length < this.chunks.length) {
|
||||
return false;
|
||||
}
|
||||
int i = 0;
|
||||
while (true) {
|
||||
String[] strArr = this.chunks;
|
||||
if (i >= strArr.length) {
|
||||
return true;
|
||||
}
|
||||
if (!strArr[i].equals(path.chunks[i])) {
|
||||
return false;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public Path relativeTo(Path path) {
|
||||
int depthOfPathDivergence = depthOfPathDivergence(this.chunks, path.chunks);
|
||||
String[] strArr = new String[(this.chunks.length + path.chunks.length) - (depthOfPathDivergence * 2)];
|
||||
int i = depthOfPathDivergence;
|
||||
int i2 = 0;
|
||||
while (i < this.chunks.length) {
|
||||
strArr[i2] = "..";
|
||||
i++;
|
||||
i2++;
|
||||
}
|
||||
while (true) {
|
||||
String[] strArr2 = path.chunks;
|
||||
if (depthOfPathDivergence >= strArr2.length) {
|
||||
break;
|
||||
}
|
||||
strArr[i2] = strArr2[depthOfPathDivergence];
|
||||
depthOfPathDivergence++;
|
||||
i2++;
|
||||
}
|
||||
return i2 == 0 ? DOT : new Path(strArr);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if (this.pathAsString == null) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
for (int i = 0; i < this.chunks.length; i++) {
|
||||
if (i > 0) {
|
||||
stringBuffer.append('/');
|
||||
}
|
||||
stringBuffer.append(this.chunks[i]);
|
||||
}
|
||||
this.pathAsString = stringBuffer.toString();
|
||||
}
|
||||
return this.pathAsString;
|
||||
}
|
||||
|
||||
public Path(String[] strArr) {
|
||||
this.chunks = strArr;
|
||||
}
|
||||
}
|
111
sources/com/thoughtworks/xstream/io/path/PathTracker.java
Normal file
111
sources/com/thoughtworks/xstream/io/path/PathTracker.java
Normal file
@@ -0,0 +1,111 @@
|
||||
package com.thoughtworks.xstream.io.path;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class PathTracker {
|
||||
private int capacity;
|
||||
private Path currentPath;
|
||||
private Map[] indexMapStack;
|
||||
private String[] pathStack;
|
||||
private int pointer;
|
||||
|
||||
public PathTracker() {
|
||||
this(16);
|
||||
}
|
||||
|
||||
private void resizeStacks(int i) {
|
||||
String[] strArr = new String[i];
|
||||
Map[] mapArr = new Map[i];
|
||||
int min = Math.min(this.capacity, i);
|
||||
System.arraycopy(this.pathStack, 0, strArr, 0, min);
|
||||
System.arraycopy(this.indexMapStack, 0, mapArr, 0, min);
|
||||
this.pathStack = strArr;
|
||||
this.indexMapStack = mapArr;
|
||||
this.capacity = i;
|
||||
}
|
||||
|
||||
public int depth() {
|
||||
return this.pointer;
|
||||
}
|
||||
|
||||
public Path getPath() {
|
||||
if (this.currentPath == null) {
|
||||
int i = this.pointer;
|
||||
String[] strArr = new String[i + 1];
|
||||
strArr[0] = "";
|
||||
int i2 = -i;
|
||||
while (true) {
|
||||
i2++;
|
||||
if (i2 > 0) {
|
||||
break;
|
||||
}
|
||||
strArr[this.pointer + i2] = peekElement(i2);
|
||||
}
|
||||
this.currentPath = new Path(strArr);
|
||||
}
|
||||
return this.currentPath;
|
||||
}
|
||||
|
||||
public String peekElement() {
|
||||
return peekElement(0);
|
||||
}
|
||||
|
||||
public void popElement() {
|
||||
Map[] mapArr = this.indexMapStack;
|
||||
int i = this.pointer;
|
||||
mapArr[i] = null;
|
||||
this.pathStack[i] = null;
|
||||
this.currentPath = null;
|
||||
this.pointer = i - 1;
|
||||
}
|
||||
|
||||
public void pushElement(String str) {
|
||||
int i = this.pointer + 1;
|
||||
int i2 = this.capacity;
|
||||
if (i >= i2) {
|
||||
resizeStacks(i2 * 2);
|
||||
}
|
||||
String[] strArr = this.pathStack;
|
||||
int i3 = this.pointer;
|
||||
strArr[i3] = str;
|
||||
Map map = this.indexMapStack[i3];
|
||||
if (map == null) {
|
||||
map = new HashMap();
|
||||
this.indexMapStack[this.pointer] = map;
|
||||
}
|
||||
if (map.containsKey(str)) {
|
||||
map.put(str, new Integer(((Integer) map.get(str)).intValue() + 1));
|
||||
} else {
|
||||
map.put(str, new Integer(1));
|
||||
}
|
||||
this.pointer++;
|
||||
this.currentPath = null;
|
||||
}
|
||||
|
||||
public PathTracker(int i) {
|
||||
this.capacity = Math.max(1, i);
|
||||
int i2 = this.capacity;
|
||||
this.pathStack = new String[i2];
|
||||
this.indexMapStack = new Map[i2];
|
||||
}
|
||||
|
||||
public String peekElement(int i) {
|
||||
int i2 = this.pointer;
|
||||
if (i < (-i2) || i > 0) {
|
||||
throw new ArrayIndexOutOfBoundsException(i);
|
||||
}
|
||||
int i3 = (i2 + i) - 1;
|
||||
int intValue = ((Integer) this.indexMapStack[i3].get(this.pathStack[i3])).intValue();
|
||||
if (intValue <= 1) {
|
||||
return this.pathStack[i3];
|
||||
}
|
||||
StringBuffer stringBuffer = new StringBuffer(this.pathStack[i3].length() + 6);
|
||||
stringBuffer.append(this.pathStack[i3]);
|
||||
stringBuffer.append('[');
|
||||
stringBuffer.append(intValue);
|
||||
stringBuffer.append(']');
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
package com.thoughtworks.xstream.io.path;
|
||||
|
||||
import com.liulishuo.filedownloader.model.FileDownloadModel;
|
||||
import com.thoughtworks.xstream.converters.ErrorWriter;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
|
||||
import com.thoughtworks.xstream.io.ReaderWrapper;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class PathTrackingReader extends ReaderWrapper {
|
||||
private final PathTracker pathTracker;
|
||||
|
||||
public PathTrackingReader(HierarchicalStreamReader hierarchicalStreamReader, PathTracker pathTracker) {
|
||||
super(hierarchicalStreamReader);
|
||||
this.pathTracker = pathTracker;
|
||||
pathTracker.pushElement(getNodeName());
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.ReaderWrapper, com.thoughtworks.xstream.io.HierarchicalStreamReader, com.thoughtworks.xstream.converters.ErrorReporter
|
||||
public void appendErrors(ErrorWriter errorWriter) {
|
||||
errorWriter.add(FileDownloadModel.PATH, this.pathTracker.getPath().toString());
|
||||
super.appendErrors(errorWriter);
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.ReaderWrapper, com.thoughtworks.xstream.io.HierarchicalStreamReader
|
||||
public void moveDown() {
|
||||
super.moveDown();
|
||||
this.pathTracker.pushElement(getNodeName());
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.ReaderWrapper, com.thoughtworks.xstream.io.HierarchicalStreamReader
|
||||
public void moveUp() {
|
||||
super.moveUp();
|
||||
this.pathTracker.popElement();
|
||||
}
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
package com.thoughtworks.xstream.io.path;
|
||||
|
||||
import com.thoughtworks.xstream.io.AbstractWriter;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
||||
import com.thoughtworks.xstream.io.WriterWrapper;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class PathTrackingWriter extends WriterWrapper {
|
||||
private final boolean isNameEncoding;
|
||||
private final PathTracker pathTracker;
|
||||
|
||||
public PathTrackingWriter(HierarchicalStreamWriter hierarchicalStreamWriter, PathTracker pathTracker) {
|
||||
super(hierarchicalStreamWriter);
|
||||
this.isNameEncoding = hierarchicalStreamWriter.underlyingWriter() instanceof AbstractWriter;
|
||||
this.pathTracker = pathTracker;
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.WriterWrapper, com.thoughtworks.xstream.io.HierarchicalStreamWriter
|
||||
public void endNode() {
|
||||
super.endNode();
|
||||
this.pathTracker.popElement();
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.WriterWrapper, com.thoughtworks.xstream.io.HierarchicalStreamWriter
|
||||
public void startNode(String str) {
|
||||
this.pathTracker.pushElement(this.isNameEncoding ? ((AbstractWriter) this.wrapped.underlyingWriter()).encodeNode(str) : str);
|
||||
super.startNode(str);
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.WriterWrapper, com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriter
|
||||
public void startNode(String str, Class cls) {
|
||||
this.pathTracker.pushElement(this.isNameEncoding ? ((AbstractWriter) this.wrapped.underlyingWriter()).encodeNode(str) : str);
|
||||
super.startNode(str, cls);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user