This commit is contained in:
RedKale
2016-02-17 11:34:50 +08:00
parent d590bb3b03
commit 5b0c937656
3 changed files with 80 additions and 0 deletions

View File

@@ -94,6 +94,8 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
this.register(InetSocketAddress.class, InetSocketAddressSimpledCoder.instance);
this.register(Pattern.class, PatternSimpledCoder.instance);
this.register(CompletionHandler.class, CompletionHandlerSimpledCoder.instance);
this.register(URL.class, URLSimpledCoder.instance);
this.register(URI.class, URISimpledCoder.instance);
//---------------------------------------------------------
this.register(boolean[].class, BoolArraySimpledCoder.instance);
this.register(byte[].class, ByteArraySimpledCoder.instance);

View File

@@ -0,0 +1,39 @@
/*
* 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 org.redkale.convert.ext;
import java.net.*;
import org.redkale.convert.*;
/**
*
* @author zhangjx
*/
public class URISimpledCoder<R extends Reader, W extends Writer> extends SimpledCoder<R, W, URI> {
public static final URLSimpledCoder instance = new URLSimpledCoder();
@Override
public void convertTo(final Writer out, final URI value) {
if (value == null) {
out.writeNull();
} else {
out.writeString(value.toString());
}
}
@Override
public URI convertFrom(Reader in) {
final String str = in.readString();
if (str == null) return null;
try {
return new URI(str);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}

View File

@@ -0,0 +1,39 @@
/*
* 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 org.redkale.convert.ext;
import java.net.*;
import org.redkale.convert.*;
/**
*
* @author zhangjx
*/
public class URLSimpledCoder<R extends Reader, W extends Writer> extends SimpledCoder<R, W, URL> {
public static final URLSimpledCoder instance = new URLSimpledCoder();
@Override
public void convertTo(final Writer out, final URL value) {
if (value == null) {
out.writeNull();
} else {
out.writeString(value.toString());
}
}
@Override
public URL convertFrom(Reader in) {
final String str = in.readString();
if (str == null) return null;
try {
return new URL(str);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}