This commit is contained in:
地平线
2015-07-01 08:40:21 +08:00
parent 11628e1724
commit a45cab34ba
2 changed files with 40 additions and 0 deletions

View File

@@ -16,6 +16,7 @@ import java.net.*;
import static com.wentch.redkale.convert.ext.InetAddressSimpledCoder.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
/**
*
@@ -87,6 +88,7 @@ public abstract class Factory<R extends Reader, W extends Writer> {
this.register(Class.class, TypeSimpledCoder.instance);
this.register(InetSocketAddress.class, InetSocketAddressSimpledCoder.instance);
this.register(InetSocketAddress.class, InetSocketAddressSimpledCoder.instance);
this.register(Pattern.class, PatternSimpledCoder.instance);
//---------------------------------------------------------
this.register(boolean[].class, BoolArraySimpledCoder.instance);
this.register(byte[].class, ByteArraySimpledCoder.instance);

View File

@@ -0,0 +1,38 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.wentch.redkale.convert.ext;
import com.wentch.redkale.convert.*;
import java.util.regex.*;
/**
*
* @author zhangjx
* @param <R>
* @param <W>
*/
public class PatternSimpledCoder<R extends Reader, W extends Writer> extends SimpledCoder<R, W, Pattern> {
public static final PatternSimpledCoder instance = new PatternSimpledCoder();
@Override
public void convertTo(W out, Pattern value) {
if (value == null) {
out.writeNull();
} else {
out.writeString(value.flags() + "," + value.pattern());
}
}
@Override
public Pattern convertFrom(R in) {
String value = in.readString();
if (value == null) return null;
int pos = value.indexOf(',');
return Pattern.compile(value.substring(pos + 1), Integer.parseInt(value.substring(0, pos)));
}
}