This commit is contained in:
@@ -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);
|
||||
|
||||
39
src/org/redkale/convert/ext/URISimpledCoder.java
Normal file
39
src/org/redkale/convert/ext/URISimpledCoder.java
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
39
src/org/redkale/convert/ext/URLSimpledCoder.java
Normal file
39
src/org/redkale/convert/ext/URLSimpledCoder.java
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user