首页 文章 精选 留言 我的

精选列表

搜索[SDD模式],共10000篇文章
优秀的个人博客,低调大师

实时计算Flink - 独享模式 - Batch(试用)- 创建源表 —— 创建CSV源表

本页目录 创建CSV源表 WITH参数 创建CSV源表 Blink可以将CSV格式文件作为源表读入,进行计算,CSV需要定义的DDL如下: create table csv_source( id varchar, name varchar ) with ( type ='csv', path = 'hdfs://hdfsroot/csvpath/test.csv', ... ); WITH参数 通用配置: 参数 注释说明 备注 path 文件路径 文件路径可以是oss/hdfs fieldDelim 列分隔符 默认为’,’,支持Java风格的字符串转义 lineDelim 行分隔符 默认为’\n’,支持Java风格的字符串转义 charset 字符集 默认为UTF-8 emptyColumnAsNull 空列不全 是否将空列补为null timezone 时区 默认时区UTC firstLineAsHeader 是否将第一行作为列名 默认false quoteCharacter csv里面如果string的field里包含列分隔符,可以用这个quote character包起来 例如:1,”1,2”,3,quotaCharacter为’”‘ 本文转自实时计算—— 创建CSV源表

优秀的个人博客,低调大师

成本和性能兼得,ECS推出t5实例无性能约束模式

如果你是阿里云突发性能实例的使用者,或者正打算入手一款入门级云主机,你是否注意到在2018杭州云栖大会弹性计算平台技术专场上提到的新款突发性能实例 – t5无性能约束实例? 无性能约束是什么概念?先来看看当时现场的介绍图: 简而言之,对于突发性能实例来说,在性能负载大于基线时会消耗积分(当然,反之性能负载小于基线时会积累积分),当积分消耗完后,t5标准实例的性能会被限制在基线。而t5无性能约束实例可以通过预支积分,或者付费的方式,继续维持系统性能,相当于信用卡版本的t5实例,灵活度更高,对突发场景的适应性更好,说是成本和性能兼得完全合适。 现在我们来看看这个“信用卡版本t5”怎么玩: 小A购买了一台1核1G的t5,规格:ecs.t5-lc1m1.small,安装Linux系统。 实例创建后,小A会获取初始CPU积分30分,在实例启动时,小A

优秀的个人博客,低调大师

【Android架构】基于MVP模式的Retrofit2+RXjava封装之文件下载(二)

上篇中我们介绍了基于MVP的Retrofit2+RXjava封装,还没有看的点击这里,这一篇我们来说说文件下载的实现。 首先,我们先在ApiServer定义好调用的接口 @GET Observable<ResponseBody> downloadFile(@Url String fileUrl); 接着定义一个接口,下载成功后用来回调 public interface FileView extends BaseView { void onSuccess(File file); } 接着是Observer,建议与处理普通接口的Observer区分处理 public abstract class FileObsever extends BaseObserver<ResponseBody> { private String path; public FileObsever(BaseView view, String path) { super(view); this.path = path; } @Override protected void onStart() { } @Override public void onComplete() { } @Override public void onSuccess(ResponseBody o) { } @Override public void onError(String msg) { } @Override public void onNext(ResponseBody o) { File file = FileUtil.saveFile(path, o); if (file != null && file.exists()) { onSuccess(file); } else { onErrorMsg("file is null or file not exists"); } } @Override public void onError(Throwable e) { onErrorMsg(e.toString()); } public abstract void onSuccess(File file); public abstract void onErrorMsg(String msg); } FileUtil 注:如果需要写入文件的进度,可以在将这段方法放在onNext中,在FileObsever这个类写个方法,然后回调。 public static File saveFile(String filePath, ResponseBody body) { InputStream inputStream = null; OutputStream outputStream = null; File file = null; try { if (filePath == null) { return null; } file = new File(filePath); if (file == null || !file.exists()) { file.createNewFile(); } long fileSize = body.contentLength(); long fileSizeDownloaded = 0; byte[] fileReader = new byte[4096]; inputStream = body.byteStream(); outputStream = new FileOutputStream(file); while (true) { int read = inputStream.read(fileReader); if (read == -1) { break; } outputStream.write(fileReader, 0, read); fileSizeDownloaded += read; } outputStream.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } return file; } 下来是FilePresenter public class FilePresenter extends BasePresenter<FileView> { public FilePresenter(FileView baseView) { super(baseView); } public void downFile(String url, final String path) { addDisposable(apiServer.downloadFile(url), new FileObsever(baseView, path) { @Override public void onSuccess(File file) { if (file != null && file.exists()) { baseView.onSuccess(file); } else { baseView.showError("file is null"); } } @Override public void onErrorMsg(String msg) { baseView.showError(msg); } }); } } 最后在Activity中调用 private void downFile() { String url = "http://download.sdk.mob.com/apkbus.apk"; String state = Environment.getExternalStorageState(); if (state.equals(Environment.MEDIA_MOUNTED)) {// 检查是否有存储卡 dir = Environment.getExternalStorageDirectory() + "/ceshi/"; File dirFile = new File(dir); if (!dirFile.exists()) { dirFile.mkdirs(); } } presenter.downFile(url, dir + "app-debug.apk"); } 就在我以为万事大吉的时候,APP崩溃了,错误信息如下: [图片上传失败...(image-39e2a7-1532052138950)] 原来是加入日志监听器,会导致每次都把整个文件加载到内存,那我们就去掉这个 修改FilePresenter#downFile如下: public void downFile(String url, final String path) { OkHttpClient client = new OkHttpClient.Builder().build(); Retrofit retrofit = new Retrofit.Builder().client(client) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .baseUrl("https://wawa-api.vchangyi.com/").build(); apiServer = retrofit.create(ApiServer.class); addDisposable(apiServer.downloadFile(url), new FileObsever(baseView, path) { @Override public void onSuccess(File file) { if (file != null && file.exists()) { baseView.onSuccess(file); } else { baseView.showError("file is null"); } } @Override public void onErrorMsg(String msg) { baseView.showError(msg); } }); } 这次倒是下载成功了,不过官方建议10M以上的文件用Streaming标签,我们加上Streaming标签试试 修改ApiServer @Streaming @GET /** * 大文件官方建议用 @Streaming 来进行注解,不然会出现IO异常,小文件可以忽略不注入 */ Observable<ResponseBody> downloadFile(@Url String fileUrl); 这次又崩溃了,错误信息如下: [图片上传失败...(image-fc8c28-1532052138951)] 这是怎么回事,我们网络请求是在子线程啊。无奈之下只得翻翻官方文档,原来使用该注解表示响应用字节流的形式返回.如果没使用该注解,默认会把数据全部载入到内存中。我们可以在主线程中处理写入文件(不建议),但不能在主线程中处理字节流。所以,我们需要将处理字节流、写入文件都放在子线程中。 于是,修改FilePresenter#downFile如下: OkHttpClient client = new OkHttpClient.Builder().build(); Retrofit retrofit = new Retrofit.Builder().client(client) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .baseUrl("https://wawa-api.vchangyi.com/").build(); apiServer = retrofit.create(ApiServer.class); apiServer .downloadFile(url) .map(new Function<ResponseBody, String>() { @Override public String apply(ResponseBody body) throws Exception { File file = FileUtil.saveFile(path, body); return file.getPath(); } }).subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribeWith(new FileObserver(baseView) { @Override public void onSuccess(File file) { baseView.onSuccess(file); } @Override public void onError(String msg) { baseView.showError(msg); } }); 这样,下载文件算是完成了,好像还缺点什么?对,缺个下载进度,还记得拦截器吗,我们可以从这里入手: public class ProgressResponseBody extends ResponseBody { private ResponseBody responseBody; private BufferedSource bufferedSource; private ProgressListener progressListener; public ProgressResponseBody(ResponseBody responseBody, ProgressListener progressListener) { this.responseBody = responseBody; this.progressListener = progressListener; } @Nullable @Override public MediaType contentType() { return responseBody.contentType(); } @Override public long contentLength() { return responseBody.contentLength(); } @Override public BufferedSource source() { if (bufferedSource == null) { bufferedSource = Okio.buffer(source(responseBody.source())); } return bufferedSource; } private Source source(Source source) { return new ForwardingSource(source) { long totalBytesRead = 0L; @Override public long read(Buffer sink, long byteCount) throws IOException { long bytesRead = super.read(sink, byteCount); totalBytesRead += bytesRead; progressListener.onProgress(responseBody.contentLength(), totalBytesRead); return bytesRead; } }; } public interface ProgressListener { void onProgress(long totalSize, long downSize); } } 在BaseView 中定义接口,个人建议放在BaseView 中,在BaseActivity中实现BaseView,方便复用 /** * 下载进度 * * @param totalSize * @param downSize */ void onProgress(long totalSize, long downSize); 再次修改FilePresenter#downFile如下: public void downFile(final String url, final String path) { OkHttpClient client = new OkHttpClient.Builder() .addNetworkInterceptor(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Response response = chain.proceed(chain.request()); return response.newBuilder().body(new ProgressResponseBody(response.body(), new ProgressResponseBody.ProgressListener() { @Override public void onProgress(long totalSize, long downSize) { baseView.onProgress(totalSize, downSize); } })).build(); } }).build(); Retrofit retrofit = new Retrofit.Builder().client(client) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .baseUrl("https://wawa-api.vchangyi.com/").build(); apiServer = retrofit.create(ApiServer.class); apiServer .downloadFile(url) .map(new Function<ResponseBody, String>() { @Override public String apply(ResponseBody body) throws Exception { File file = FileUtil.saveFile(path, body); return file.getPath(); } }).subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribeWith(new FileObserver(baseView) { @Override public void onSuccess(File file) { baseView.onSuccess(file); } @Override public void onError(String msg) { baseView.showError(msg); } }); } 至此,使用Retrofit下载文件暂时告一段落。 你的认可,是我坚持更新博客的动力,如果觉得有用,就请点个赞,谢谢 项目源码

优秀的个人博客,低调大师

技巧:防范代码的 finalizer() 漏洞 一种预防创建无效类的模式

本文原作者:Neil D. Masson, Java 支持工程师, IBM (本人在拜读过程中添加了自己的一些理解。) 原文地址:http://www.ibm.com/developerworks/cn/java/j-fv/index.html?ca=drs- 简介:您的 Java 代码有可能会因终结操作带来的漏洞而易受到攻击,了解这一漏洞是如何起作用的,并学习如何通过修改代码来防止此类攻击。 在使用终结器 (finalizer) 来创建对象时,其可能会给 Java 代码带来漏洞。该漏洞是使用终结器来恢复对象的著名技术的一种变体。当包含finalize()方法的对象变得无法访问时,它会被放入一个将在以后某个时刻处理的队列上。本文解释此类攻击的工作原理,介绍如何保护代码免遭此类攻击。所有代码示例都可供下载。 终结器的理念是允许 Java 方法释放任何需要返回到操作系统的本机资源。遗憾的是,任何 Java 代码都可以在终结器中运行,可以使用类似清单 1 的代码: 清单 1. 一个可恢复的类 1 2 3 4 5 6 7 8 9 10 11 12 13 14 public class Zombie { static Zombie zombie; public void finalize() { zombie = this ; } public static void main(String[] args) { Zombie demo = new Zombie(); System.out.println(demo.zombie); demo.finalize(); System.out.println(demo.zombie); } } 运行结果: null Zombie@18a992f 在调用Zombie终结器时,它获取被终结的对象(由this引用)并将它存储在静态zombie变量中。现在该对象又是可访问的,其不能被垃圾收集。 此代码的一种存在更大隐患的版本甚至允许恢复部分构造的对象。即使对象在初始化过程中不能通过正确性检查,其仍能够被终结器创建出来,如清单 2 所示: 清单2 :创建一个非法的类 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 public class Zombie2 { static Zombie2 zombie; int value; public Zombie2( int value) { if (value < 0 ) { throw new IllegalArgumentException( "Negative Zombie2 value" ); } this .value = value; } public void finalize() { zombie = this ; } public static void main(String[] args) { Zombie2 demo= new Zombie2( 1 ); System.out.println(demo.value); demo.value=- 1 ; demo.finalize(); System.out.println(demo.value); } } 运行结果: 1 -1 finalize() 方法的存在使对 value 参数的检查变得无效 当然,可能没有人会编写类似 清单 2 这样的代码。但如果类被继承了的话,则可能出现漏洞,如清单 3 所示: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 class Vulnerable { Integer value = 0 ; Vulnerable( int value) { if (value <= 0 ) { throw new IllegalArgumentException( "Vulnerable value must be positive" ); } this .value = value; } @Override public String toString() { return (value.toString()); } } 清单 3中的Vulnerable类用于预防设置非正的value值。此意图被AttackVulnerable()方法破坏,如清单 4 所示: 清单 4. 破坏Vulnerable类的类 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 class AttackVulnerable extends Vulnerable { static Vulnerable vulnerable; public AttackVulnerable( int value) { super (value); } public void finalize() { vulnerable = this ; } public static void main(String[] args) { try { new AttackVulnerable(- 1 ); } catch (Exception e) { System.out.println(e); } System.gc(); System.runFinalization(); if (vulnerable != null ) { System.out.println( "Vulnerable object " + vulnerable + " created!" ); } } } AttackVulnerable类的main()方法试图创建一个新的AttackVulnerable对象实例。因为value的值超出了范围,所以抛出了一个被catch块捕获的异常。System.gc()和System.runFinalization()的调用促使 VM 运行一个垃圾回收周期并运行一些终结器。这些调用不是成功攻击的必要条件,但它们可用来说明攻击的最终结果,那就是创建了一个包含无效值的Vulnerable对象。 运行测试用例会得到以下结果: java.lang.IllegalArgumentException: Vulnerable value must be positive Vulnerable object 0 created! 为什么Vulnerable的值是 0,而不是 -1?请注意,在清单 3中的Vulnerable构造函数中,在执行参数检查后才会给value赋值。所以value拥有自己的初始值,在本例中为 0。 这种类型的攻击甚至可用于绕过显式安全检查。例如,如果在SecurityManager下运行并且调用方没有权限向当前目录写入数据,就可以使用清单 5 中的Insecure类来抛出SecurityException: 清单 5.Insecure类 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 import java.io.FilePermission; public class Insecure { Integer value = 0 ; public Insecure( int value) { SecurityManager sm = System.getSecurityManager(); if (sm != null ) { FilePermission fp = new FilePermission( "index" , "write" ); sm.checkPermission(fp); } this .value = value; } @Override public String toString() { return (value.toString()); } } 清单 5中的Insecure类可通过与前面相同的方式攻击,如清单 6 中的AttackInsecure类所示: 清单 6. 攻击Insecure类 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 public class AttackInsecure extends Insecure { static Insecure insecure; public AttackInsecure( int value) { super (value); } public void finalize() { insecure = this ; } public static void main(String[] args) { try { new AttackInsecure(- 1 ); } catch (Exception e) { System.out.println(e); } System.gc(); System.runFinalization(); if (insecure != null ) { System.out.println( "Insecure object " + insecure + " created!" ); } } 在SecurityManager下运行清单 6中的代码会得到以下输出: java -Djava.security.manager AttackInsecure java.security.AccessControlException: Access denied (java.io.FilePermission index write) Insecure object 0 created! 如何避免攻击 在 Java SE 6 中实现第三版 Java 语言规范 (JLS) 之前,避免攻击的仅有方式是使用initialized标志、禁止子类化或创建final终结器)并不是令人满意的解决方案。 使用initialized标志 一种避免攻击的方式是使用initialized标志,在正确创建对象之后它被设置为true。该类中的每个方法首先检查是否设置了initialized,如果没有设置则抛出一个异常。这样的代码编写起来很无趣,很容易被意外省略,也无法阻止攻击者子类化该方法。 预防子类化 您可以将所创建的类声明为final。这意味着没有人可创建该类的子类,这会阻止攻击生效。但是,此技术降低了灵活性,无法扩展该类来特殊化它或增加额外的功能。 创建一个final终结器 可以为所创建的类创建一个终结器并将它声明为final。这意味着该类的任何子类都无法声明终结器。此方法的缺点是,终结器的存在意味着对象的存活期比其他情况下更长。 一种新的、更好的方式 为了更容易避免此类攻击,而无需引入额外的代码或限制,Java 设计人员修改了 JLS(参见参考资料),声明如果在构造java.lang.Object之前在构造函数中抛出了一个异常,该方法的finalize()方法将不会执行。 但是如何在构造java.lang.Object之前抛出异常呢?毕竟,任何构造函数中的第一行都必须是对this()或super()的调用。如果构造函数没有包含这样的显式调用,将隐式添加对super()的调用。所以在创建对象之前,必须构造相同类或其超类的另一个对象。这最终导致了对java.lang.Object本身的构造,然后在执行所构造方法的任何代码之前,构造所有子类。 要理解如何在构造java.lang.Object之前抛出异常,需要理解准确的对象构造顺序。JLS 明确给出了这一顺序。 当创建对象时,JVM: 为对象分配空间。 将对象中所有的实例变量设置为它们的默认值。这包括对象超类中的实例变量。 分配对象的参数变量。 处理任何显式或隐式构造函数调用(在构造函数中调用this()或super())。 初始化类中的变量。 执行构造函数的剩余部分。 重要的是构造函数的参数在处理构造函数内的任何代码之前被处理。这意味着,如果在处理参数时执行验证,可以通过抛出异常预防类被终结。 这带来了清单 3的Vulnerable类的一个新版本,如清单 7 所示: 清单 7.Invulnerable类 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 class Invulnerable { int value = 0 ; Invulnerable( int value) { this (checkValues(value)); this .value = value; } private Invulnerable(Void checkValues) {} static Void checkValues( int value) { if (value <= 0 ) { throw new IllegalArgumentException( "Invulnerable value must be positive" ); } return null ; } @Override public String toString() { return (Integer.toString(value)); } } 在清单 7中,Invulnerable的公共构造函数调用一个私有构造函数,而后者调用checkValues方法来创建其参数。此方法在构造函数执行调用来构造其超类之前调用,该构造函数是Object的构造函数。所以如果checkValues中抛出了一个异常,那么将不会终结Invulnerable对象。 清单 8 中的代码尝试攻击Invulnerable: 清单 8. 尝试破坏Invulnerable类 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 class AttackInvulnerable extends Invulnerable { static Invulnerable vulnerable; public AttackInvulnerable( int value) { super (value); } public void finalize() { vulnerable = this ; } public static void main(String[] args) { try { new AttackInvulnerable(- 1 ); } catch (Exception e) { System.out.println(e); } System.gc(); System.runFinalization(); if (vulnerable != null ) { System.out.println( "Invulnerable object " + vulnerable + " created!"); } else { System.out.println( "Attack failed" ); } } } with the addition of } else { System.out.println( "Attack failed" ); 使用 Java 5(针对较旧 JLS 版本而编写),创建了一个Invulnerable对象: 1 2 java.lang.IllegalArgumentException: Invulnerable value must be positive Invulnerable object 0 created! 在 Java SE 6(自 Oracle 的 JVM 的通用版本和 IBM 的 JVM 的 SR9 开始)及以后的规范中,不会创建该对象 1 2 java.lang.IllegalArgumentException: Invulnerable value must be positive Attack failed 结束语 终结器是 Java 语言的一种不太幸运的功能。尽管垃圾收集器可自动回收 Java 对象不再使用的任何内存,但不存在回收本机内存、文件描述符或套接字等本机资源的机制。Java 提供了与这些本机资源交互的标准库通常有一个close()方法,允许执行恰当的清理,但它们也使用了终结器来确保在对象错误关闭时,没有资源泄漏。 对于其他对象,通常最好避免终结器。无法保证终结器将在何时运行,或者甚至它是否会运行。终结器的存在意味着在终结器运行之前,不会对无法访问的对象执行垃圾收集,而且此对象可能使更多对象存活。这导致活动对象数量增加,进而导致 Java 对象的堆使用率增加。 终结器恢复即将被垃圾收集的能力无疑是终结机制工作方式的一种意外后果。较新的 JVM 实现现在保护代码免遭此类安全隐患。 ============================================================================== 本文转自被遗忘的博客园博客,原文链接:http://www.cnblogs.com/rollenholt/archive/2011/10/13/2210166.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

复杂的IT企业交付模式Wise2C的到来可持续集成

传统金融企业用户数字化业务创新,常常面临企业IT架构陈旧、应用系统交付效率无法满足业务发展需求的困境。因此,改造旧有系统架构,将业务应用系统“云化”,打造更为高效顺畅的软件生产与持续运营平台,逐步成为诸多金融机构IT基础能力建设的重要课题。 容器服务的作用,当我们使用该服务,将无需安装、运维、扩展集群管理基础设施,只需进行简单的API调用,便可启动和停止Docker应用程序。 查询集群的完整状态,以及使用各种云服务。可以根据自身资源需求和可用性要求在集群中安排容器的置放,满足业务或应用程序的特定要求。 下面来看看睿云智合Wise2C的一些案例,提到基于容器的PaaS平台建设,不得不说说银行业的先行者恒丰银行。基于银行业务场景和银行业的特殊需求,我们为恒丰银行定制开发了鉴权认证、资源管理、应用编排、弹性伸缩、日志收集、监控告警以及镜像仓库可视化管理等一系列PaaS平台的微服务模块,实现了容器云平台对多租户隔离环境的集中管理。 其中,隔离环境分别对应到某个租户的特定网络,单个网络内部流量采用睿云智合(Wise2C)实现的扁平化网络方案,网络之间流量由外部防火墙控制。由于客户还存在跨网络部署应用栈的需求,因此存储必须要基于租户的粒度,可以实现跨环境共享。我们也为此设计了合适的方案。

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册
修改密码
忘记密码