xiaodi8 v1.0.0版本的 MD5 值为:6b857c57f508176c5ba1afb422bbb5a9

以下内容为反编译后的 FilePersistenceStrategy.java 源代码,内容仅作参考


package com.thoughtworks.xstream.persistence;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.SingleValueConverter;
import com.thoughtworks.xstream.io.StreamException;
import com.thoughtworks.xstream.io.xml.DomDriver;
import java.io.File;

public class FilePersistenceStrategy extends AbstractFilePersistenceStrategy {
    private final String illegalChars;

    public FilePersistenceStrategy(File file) {
        this(file, new XStream(new DomDriver()));
    }

    protected String escape(String str) {
        StringBuffer stringBuffer = new StringBuffer();
        for (char c2 : str.toCharArray()) {
            if (c2 >= ' ' && this.illegalChars.indexOf(c2) < 0) {
                stringBuffer.append(c2);
            } else {
                stringBuffer.append("%" + Integer.toHexString(c2).toUpperCase());
            }
        }
        return stringBuffer.toString();
    }

    @Override
    protected Object extractKey(String str) {
        String unescape = unescape(str.substring(0, str.length() - 4));
        if ("null@null".equals(unescape)) {
            return null;
        }
        int indexOf = unescape.indexOf(64);
        if (indexOf >= 0) {
            Class realClass = getMapper().realClass(unescape.substring(0, indexOf));
            Converter lookupConverterForType = getConverterLookup().lookupConverterForType(realClass);
            if (lookupConverterForType instanceof SingleValueConverter) {
                return ((SingleValueConverter) lookupConverterForType).fromString(unescape.substring(indexOf + 1));
            }
            throw new StreamException("No SingleValueConverter for type " + realClass.getName() + " available");
        }
        throw new StreamException("Not a valid key: " + unescape);
    }

    @Override
    protected String getName(Object obj) {
        if (obj == null) {
            return "null@null.xml";
        }
        Class<?> cls = obj.getClass();
        Converter lookupConverterForType = getConverterLookup().lookupConverterForType(cls);
        if (lookupConverterForType instanceof SingleValueConverter) {
            return getMapper().serializedClass(cls) + '@' + escape(((SingleValueConverter) lookupConverterForType).toString(obj)) + ".xml";
        }
        throw new StreamException("No SingleValueConverter for type " + cls.getName() + " available");
    }

    @Override
    public boolean isValid(File file, String str) {
        return super.isValid(file, str) && str.indexOf(64) > 0;
    }

    protected String unescape(String str) {
        StringBuffer stringBuffer = new StringBuffer();
        while (true) {
            int indexOf = str.indexOf(37);
            if (indexOf >= 0) {
                stringBuffer.append(str.substring(0, indexOf));
                int i = indexOf + 1;
                int i2 = indexOf + 3;
                stringBuffer.append((char) Integer.parseInt(str.substring(i, i2), 16));
                str = str.substring(i2);
            } else {
                stringBuffer.append(str);
                return stringBuffer.toString();
            }
        }
    }

    public FilePersistenceStrategy(File file, XStream xStream) {
        this(file, xStream, "utf-8", "<>?:/\\\"|*%");
    }

    public FilePersistenceStrategy(File file, XStream xStream, String str, String str2) {
        super(file, xStream, str);
        this.illegalChars = str2;
    }
}