com.alibaba.dubbo.common.utils.IOUtils Java Examples
The following examples show how to use
com.alibaba.dubbo.common.utils.IOUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileGroup.java From dubbox with Apache License 2.0 | 6 votes |
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; }
Example #2
Source File: FileExchangeGroup.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
@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); } }
Example #3
Source File: FileRouterFactory.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Override public Router getRouter(URL url) { try { // Transform File URL into Script Route URL, and 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); // Replace original protocol (maybe 'file') with 'script' String type = null; // Use file suffix to config script type, e.g., js, groovy ... 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()))); boolean runtime = url.getParameter(Constants.RUNTIME_KEY, false); URL script = url.setProtocol(protocol).addParameter(Constants.TYPE_KEY, type).addParameter(Constants.RUNTIME_KEY, runtime).addParameterAndEncoded(Constants.RULE_KEY, rule); return routerFactory.getRouter(script); } catch (IOException e) { throw new IllegalStateException(e.getMessage(), e); } }
Example #4
Source File: FileGroup.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
@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); } }
Example #5
Source File: Bytes.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
/** * 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(); } }
Example #6
Source File: FileRouterFactory.java From dubbo3 with Apache License 2.0 | 6 votes |
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); } }
Example #7
Source File: FileRouterFactory.java From dubbox with Apache License 2.0 | 6 votes |
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); } }
Example #8
Source File: FileExchangeGroup.java From dubbox with Apache License 2.0 | 6 votes |
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; }
Example #9
Source File: FileExchangeGroup.java From dubbox with Apache License 2.0 | 6 votes |
@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); } }
Example #10
Source File: FileGroup.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
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; }
Example #11
Source File: FileGroup.java From dubbox with Apache License 2.0 | 6 votes |
@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); } }
Example #12
Source File: Bytes.java From dubbox with Apache License 2.0 | 6 votes |
/** * 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(); } }
Example #13
Source File: FileRouterFactory.java From dubbox with Apache License 2.0 | 6 votes |
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); } }
Example #14
Source File: FileExchangeGroup.java From dubbox with Apache License 2.0 | 6 votes |
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; }
Example #15
Source File: FileExchangeGroup.java From dubbox with Apache License 2.0 | 6 votes |
@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); } }
Example #16
Source File: FileGroup.java From dubbox with Apache License 2.0 | 6 votes |
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; }
Example #17
Source File: FileGroup.java From dubbox with Apache License 2.0 | 6 votes |
@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); } }
Example #18
Source File: Bytes.java From dubbox with Apache License 2.0 | 6 votes |
/** * 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(); } }
Example #19
Source File: FileGroup.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@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); } }
Example #20
Source File: FileExchangeGroup.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
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; }
Example #21
Source File: FileRouterFactory.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
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); } }
Example #22
Source File: Bytes.java From dubbox with Apache License 2.0 | 6 votes |
/** * 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(); } }
Example #23
Source File: FileGroup.java From dubbox with Apache License 2.0 | 6 votes |
@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); } }
Example #24
Source File: FileGroup.java From dubbox with Apache License 2.0 | 6 votes |
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; }
Example #25
Source File: FileExchangeGroup.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@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); } }
Example #26
Source File: FileRouterFactory.java From dubbox with Apache License 2.0 | 6 votes |
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); } }
Example #27
Source File: FileExchangeGroup.java From dubbox with Apache License 2.0 | 6 votes |
@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); } }
Example #28
Source File: FileExchangeGroup.java From dubbox with Apache License 2.0 | 6 votes |
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; }
Example #29
Source File: FileExchangeGroup.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
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; }
Example #30
Source File: FileGroup.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Override 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; }