All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hprose.io.unserialize.PatternUnserializer Maven / Gradle / Ivy

/**********************************************************\
|                                                          |
|                          hprose                          |
|                                                          |
| Official WebSite: http://www.hprose.com/                 |
|                   http://www.hprose.org/                 |
|                                                          |
\**********************************************************/
/**********************************************************\
 *                                                        *
 * PatternUnserializer.java                               *
 *                                                        *
 * Pattern unserializer class for Java.                   *
 *                                                        *
 * LastModified: Aug 3, 2016                              *
 * Author: Ma Bingyao                   *
 *                                                        *
\**********************************************************/

package hprose.io.unserialize;

import static hprose.io.HproseTags.TagEmpty;
import static hprose.io.HproseTags.TagString;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.regex.Pattern;

public final class PatternUnserializer extends BaseUnserializer {

    public final static PatternUnserializer instance = new PatternUnserializer();

    @Override
    public Pattern unserialize(Reader reader, int tag, Type type) throws IOException {
        switch (tag) {
            case TagString: return Pattern.compile(ReferenceReader.readString(reader));
            case TagEmpty: return null;
        }
        return super.unserialize(reader, tag, type);
    }

    public Pattern read(Reader reader) throws IOException {
        return read(reader, Pattern.class);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy