本文整理汇总了Java中com.alibaba.dubbo.common.utils.IOUtils类的典型用法代码示例。如果您正苦于以下问题:Java IOUtils类的具体用法?Java IOUtils怎么用?Java IOUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IOUtils类属于com.alibaba.dubbo.common.utils包,在下文中一共展示了IOUtils类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRouter
import com.alibaba.dubbo.common.utils.IOUtils; //导入依赖的package包/类
public Router getRouter(URL url) {
try {
// File URL 转换成 其它Route URL,然后Load
// file:///d:/path/to/route.js?router=script ==> script:///d:/path/to/route.js?type=js&rule=<file-content>
String protocol = url.getParameter(Constants.ROUTER_KEY, ScriptRouterFactory.NAME); // 将原类型转为协议
String type = null; // 使用文件后缀做为类型
String path = url.getPath();
if (path != null) {
int i = path.lastIndexOf('.');
if (i > 0) {
type = path.substring(i + 1);
}
}
String rule = IOUtils.read(new FileReader(new File(url.getAbsolutePath())));
URL script = url.setProtocol(protocol).addParameter(Constants.TYPE_KEY, type).addParameterAndEncoded(Constants.RULE_KEY, rule);
return routerFactory.getRouter(script);
} catch (IOException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
示例2: joinExchange
import com.alibaba.dubbo.common.utils.IOUtils; //导入依赖的package包/类
public ExchangePeer joinExchange(URL url, ExchangeHandler handler) throws RemotingException {
ExchangePeer peer = super.join(url, handler);
try {
String full = url.toFullString();
String[] lines = IOUtils.readLines(file);
for (String line : lines) {
if (full.equals(line)) {
return peer;
}
}
IOUtils.appendLines(file, new String[] {full});
} catch (IOException e) {
throw new RemotingException(new InetSocketAddress(NetUtils.getLocalHost(), 0), getUrl().toInetSocketAddress(), e.getMessage(), e);
}
return peer;
}
示例3: leave
import com.alibaba.dubbo.common.utils.IOUtils; //导入依赖的package包/类
@Override
public void leave(URL url) throws RemotingException {
super.leave(url);
try {
String full = url.toFullString();
String[] lines = IOUtils.readLines(file);
List<String> saves = new ArrayList<String>();
for (String line : lines) {
if (full.equals(line)) {
return;
}
saves.add(line);
}
IOUtils.appendLines(file, saves.toArray(new String[0]));
} catch (IOException e) {
throw new RemotingException(new InetSocketAddress(NetUtils.getLocalHost(), 0), getUrl().toInetSocketAddress(), e.getMessage(), e);
}
}
示例4: join
import com.alibaba.dubbo.common.utils.IOUtils; //导入依赖的package包/类
public Peer join(URL url, ChannelHandler handler) throws RemotingException {
Peer peer = super.join(url, handler);
try {
String full = url.toFullString();
String[] lines = IOUtils.readLines(file);
for (String line : lines) {
if (full.equals(line)) {
return peer;
}
}
IOUtils.appendLines(file, new String[] {full});
} catch (IOException e) {
throw new RemotingException(new InetSocketAddress(NetUtils.getLocalHost(), 0), getUrl().toInetSocketAddress(), e.getMessage(), e);
}
return peer;
}
示例5: unzip
import com.alibaba.dubbo.common.utils.IOUtils; //导入依赖的package包/类
/**
* unzip.
*
* @param bytes compressed byte array.
* @return byte uncompressed array.
* @throws IOException
*/
public static byte[] unzip(byte[] bytes) throws IOException
{
UnsafeByteArrayInputStream bis = new UnsafeByteArrayInputStream(bytes);
UnsafeByteArrayOutputStream bos = new UnsafeByteArrayOutputStream();
InputStream is = new InflaterInputStream(bis);
try
{
IOUtils.write(is, bos);
return bos.toByteArray();
}
finally
{
is.close();
bis.close();
bos.close();
}
}
示例6: getRouter
import com.alibaba.dubbo.common.utils.IOUtils; //导入依赖的package包/类
public Router getRouter(URL url) {
try {
// File URL 转换成 其它Route URL,然后Load
// file:///d:/path/to/route.js?router=script ==> script:///d:/path/to/route.js?type=js&rule=<file-content>
String protocol = url.getParameter(Constants.ROUTER_KEY, ScriptRouterFactory.NAME); // 将原类型转为协议
String type = null; // 使用文件后缀做为类型
String path = url.getPath();
if (path != null) {
int i = path.lastIndexOf('.');
if (i > 0) {
type = path.substring(i + 1);
}
}
String rule = IOUtils.read(new FileReader(new File(url.getAbsolutePath())));
URL script = url.setProtocol(protocol).addParameter(Constants.TYPE_KEY, type).addParameterAndEncoded(Constants.RULE_KEY, rule);
return routerFactory.getRouter(script);
} catch (IOException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}