首页 文章 精选 留言 我的

精选列表

搜索[文档系统],共10000篇文章
优秀的个人博客,低调大师

基于springcloud + vue的分布式服务paascloud项目部署文档

这里特别感谢 QQ 金宝宝 1771717896 提供的服务器 准备环境 安装虚拟机 安装项目运行环境 配置host文件 windows 目录 C:\Windows\System32\drivers\etc\hosts mac/linux 地址 /etc/hosts 下面的ip注意修改为自己虚拟机对应的ip地址 127.0.0.1 dev-login.paascloud.net 127.0.0.1 dev-admin.paascloud.net 127.0.0.1 dev-api.paascloud.net 127.0.0.1 dev-mall.paascloud.net 127.0.0.1 paascloud-discovery 127.0.0.1 paascloud-eureka 127.0.0.1 paascloud-gateway 127.0.0.1 paascloud-monitor 127.0.0.1 paascloud-zipkin 127.0.0.1 paascloud-provider-uac 127.0.0.1 paascloud-provider-mdc 127.0.0.1 paascloud-provider-omc 127.0.0.1 paascloud-provider-opc 192.168.241.21 paascloud-db-mysql 192.168.241.21 paascloud-db-redis 192.168.241.21 paascloud-mq-rabbit 192.168.241.21 paascloud-mq-rocket 192.168.241.21 paascloud-provider-zk 192.168.241.101 paascloud-zk-01 192.168.241.102 paascloud-zk-02 192.168.241.103 paascloud-zk-03 配置私服 http://blog.paascloud.net/2018/03/29/springcloud/nexus/maven-nexus-use/ 编译elastic-job-lite-starter-master https://github.com/paascloud/elastic-job-lite-starter-master 配置 spring cloud 配置中心 http://blog.paascloud.net/2018/03/26/springcloud/config/springcloud-config-encrypt/ fork 项目 paascloud-config-repo 修改配置中心git地址, 如果使用私有地址请配置用户名密码 修改第一步fork来的项目的application-dev.yml 配置文件配置文件 paascloud: mail: username: 'your email address' password: 'your email password' aliyun: key: accessKeyId: 'your aliyun accessKeyId' accessKeySecret: 'your aliyun accessKeySecret' sms: product: 'your sms product' qiniu: key: accessKey: 'your qiniu accessKey' secretKey: 'your qiniu secretKey' oss: privateHost: 'your qiniu oss private host' publicHost: 'your qiniu oss public host' 微服务启动顺序 1. paascloud-eureka 2. paascloud-discovery 3. paascloud-provider-uac 4. paascloud-gateway 5. 剩下微服务无启动数序要求 我的开源项目 github: https://github.com/paascloud/paascloud-master 码云:https://gitee.com/paascloud/paascloud-master 如果觉得本文对您有帮助, 空闲的时候点帮忙加个星星, 您的支持将鼓励我继续创作的动力!

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

Redisson官方文档 - 8. 分布式锁和同步器

8.1. 可重入锁(Reentrant Lock) 基于Redis的Redisson分布式可重入锁RLock Java对象实现了java.util.concurrent.locks.Lock接口。 RLock lock = redisson.getLock("anyLock"); // 最常见的使用方法 lock.lock(); 大家都知道,如果负责储存这个分布式锁的Redis节点宕机以后,而且这个锁正好处于锁住的状态时,这个锁会出现锁死的状态。为了避免这种情况的发生,Redisson内部提供了一个监控锁的看门狗,它的作用是在Redisson实例被关闭前,不断的延长锁的有效期。默认情况下,看门狗的检查锁的超时时间是30秒钟,也可以通过修改Config.lockWatchdogTimeout来另行指定。 另外Redisson还通过加锁的方法提供了leaseTime的参数来指定加锁的时间。超过这个时间后锁便自动解开了。 // 加锁以后10秒钟自动解锁 // 无需调用unlock方法手动解锁 lock.lock(10, TimeUnit.SECONDS); // 尝试加锁,最多等待100秒,上锁以后10秒自动解锁 boolean res = lock.tryLock(100, 10, TimeUnit.SECONDS); ... lock.unlock(); Redisson同时还为分布式锁提供了异步执行的相关方法: RLock lock = redisson.getLock("anyLock"); lock.lockAsync(); lock.lockAsync(10, TimeUnit.SECONDS); Future<Boolean> res = lock.tryLockAsync(100, 10, TimeUnit.SECONDS); RLock对象完全符合Java的Lock规范。也就是说只有拥有锁的进程才能解锁,其他进程解锁则会抛出IllegalMonitorStateException错误。但是如果遇到需要其他进程也能解锁的情况,请使用分布式信号量Semaphore 对象. 8.2. 公平锁(Fair Lock) 基于Redis的Redisson分布式可重入公平锁也是实现了java.util.concurrent.locks.Lock接口的一种RLock对象。它保证了当多个Redisson客户端线程同时请求加锁时,优先分配给先发出请求的线程。 RLock fairLock = redisson.getFairLock("anyLock"); // 最常见的使用方法 fairLock.lock(); 大家都知道,如果负责储存这个分布式锁的Redis节点宕机以后,而且这个锁正好处于锁住的状态时,这个锁会出现锁死的状态。为了避免这种情况的发生,Redisson内部提供了一个监控锁的看门狗,它的作用是在Redisson实例被关闭前,不断的延长锁的有效期。默认情况下,看门狗的检查锁的超时时间是30秒钟,也可以通过修改Config.lockWatchdogTimeout来另行指定。 另外Redisson还通过加锁的方法提供了leaseTime的参数来指定加锁的时间。超过这个时间后锁便自动解开了。 // 10秒钟以后自动解锁 // 无需调用unlock方法手动解锁 fairLock.lock(10, TimeUnit.SECONDS); // 尝试加锁,最多等待100秒,上锁以后10秒自动解锁 boolean res = fairLock.tryLock(100, 10, TimeUnit.SECONDS); ... fairLock.unlock(); Redisson同时还为分布式可重入公平锁提供了异步执行的相关方法: RLock fairLock = redisson.getFairLock("anyLock"); fairLock.lockAsync(); fairLock.lockAsync(10, TimeUnit.SECONDS); Future<Boolean> res = fairLock.tryLockAsync(100, 10, TimeUnit.SECONDS); 8.3. 联锁(MultiLock) 基于Redis的Redisson分布式联锁RedissonMultiLock对象可以将多个RLock对象关联为一个联锁,每个RLock对象实例可以来自于不同的Redisson实例。 RLock lock1 = redissonInstance1.getLock("lock1"); RLock lock2 = redissonInstance2.getLock("lock2"); RLock lock3 = redissonInstance3.getLock("lock3"); RedissonMultiLock lock = new RedissonMultiLock(lock1, lock2, lock3); // 同时加锁:lock1 lock2 lock3 // 所有的锁都上锁成功才算成功。 lock.lock(); ... lock.unlock(); 大家都知道,如果负责储存某些分布式锁的某些Redis节点宕机以后,而且这些锁正好处于锁住的状态时,这些锁会出现锁死的状态。为了避免这种情况的发生,Redisson内部提供了一个监控锁的看门狗,它的作用是在Redisson实例被关闭前,不断的延长锁的有效期。默认情况下,看门狗的检查锁的超时时间是30秒钟,也可以通过修改Config.lockWatchdogTimeout来另行指定。 另外Redisson还通过加锁的方法提供了leaseTime的参数来指定加锁的时间。超过这个时间后锁便自动解开了。 RedissonMultiLock lock = new RedissonMultiLock(lock1, lock2, lock3); // 给lock1,lock2,lock3加锁,如果没有手动解开的话,10秒钟后将会自动解开 lock.lock(10, TimeUnit.SECONDS); // 为加锁等待100秒时间,并在加锁成功10秒钟后自动解开 boolean res = lock.tryLock(100, 10, TimeUnit.SECONDS); ... lock.unlock(); 8.4. 红锁(RedLock) 基于Redis的Redisson红锁RedissonRedLock对象实现了Redlock介绍的加锁算法。该对象也可以用来将多个RLock对象关联为一个红锁,每个RLock对象实例可以来自于不同的Redisson实例。 RLock lock1 = redissonInstance1.getLock("lock1"); RLock lock2 = redissonInstance2.getLock("lock2"); RLock lock3 = redissonInstance3.getLock("lock3"); RedissonRedLock lock = new RedissonRedLock(lock1, lock2, lock3); // 同时加锁:lock1 lock2 lock3 // 红锁在大部分节点上加锁成功就算成功。 lock.lock(); ... lock.unlock(); 大家都知道,如果负责储存某些分布式锁的某些Redis节点宕机以后,而且这些锁正好处于锁住的状态时,这些锁会出现锁死的状态。为了避免这种情况的发生,Redisson内部提供了一个监控锁的看门狗,它的作用是在Redisson实例被关闭前,不断的延长锁的有效期。默认情况下,看门狗的检查锁的超时时间是30秒钟,也可以通过修改Config.lockWatchdogTimeout来另行指定。 另外Redisson还通过加锁的方法提供了leaseTime的参数来指定加锁的时间。超过这个时间后锁便自动解开了。 RedissonRedLock lock = new RedissonRedLock(lock1, lock2, lock3); // 给lock1,lock2,lock3加锁,如果没有手动解开的话,10秒钟后将会自动解开 lock.lock(10, TimeUnit.SECONDS); // 为加锁等待100秒时间,并在加锁成功10秒钟后自动解开 boolean res = lock.tryLock(100, 10, TimeUnit.SECONDS); ... lock.unlock(); 8.5. 读写锁(ReadWriteLock) 基于Redis的Redisson分布式可重入读写锁RReadWriteLock Java对象实现了java.util.concurrent.locks.ReadWriteLock接口。同时还支持自动过期解锁。该对象允许同时有多个读取锁,但是最多只能有一个写入锁。 RReadWriteLock rwlock = redisson.getLock("anyRWLock"); // 最常见的使用方法 rwlock.readLock().lock(); // 或 rwlock.writeLock().lock(); 大家都知道,如果负责储存这个分布式锁的Redis节点宕机以后,而且这个锁正好处于锁住的状态时,这个锁会出现锁死的状态。为了避免这种情况的发生,Redisson内部提供了一个监控锁的看门狗,它的作用是在Redisson实例被关闭前,不断的延长锁的有效期。默认情况下,看门狗的检查锁的超时时间是30秒钟,也可以通过修改Config.lockWatchdogTimeout来另行指定。 另外Redisson还通过加锁的方法提供了leaseTime的参数来指定加锁的时间。超过这个时间后锁便自动解开了。 // 10秒钟以后自动解锁 // 无需调用unlock方法手动解锁 rwlock.readLock().lock(10, TimeUnit.SECONDS); // 或 rwlock.writeLock().lock(10, TimeUnit.SECONDS); // 尝试加锁,最多等待100秒,上锁以后10秒自动解锁 boolean res = rwlock.readLock().tryLock(100, 10, TimeUnit.SECONDS); // 或 boolean res = rwlock.writeLock().tryLock(100, 10, TimeUnit.SECONDS); ... lock.unlock(); 8.6. 信号量(Semaphore) 基于Redis的Redisson的分布式信号量(Semaphore)Java对象RSemaphore采用了与java.util.concurrent.Semaphore相似的接口和用法。 RSemaphore semaphore = redisson.getSemaphore("semaphore"); semaphore.acquire(); //或 semaphore.acquireAsync(); semaphore.acquire(23); semaphore.tryAcquire(); //或 semaphore.tryAcquireAsync(); semaphore.tryAcquire(23, TimeUnit.SECONDS); //或 semaphore.tryAcquireAsync(23, TimeUnit.SECONDS); semaphore.release(10); semaphore.release(); //或 semaphore.releaseAsync(); 8.7. 可过期性信号量(PermitExpirableSemaphore) 基于Redis的Redisson可过期性信号量(PermitExpirableSemaphore)是在RSemaphore对象的基础上,为每个信号增加了一个过期时间。每个信号可以通过独立的ID来辨识,释放时只能通过提交这个ID才能释放。 RPermitExpirableSemaphore semaphore = redisson.getPermitExpirableSemaphore("mySemaphore"); String permitId = semaphore.acquire(); // 获取一个信号,有效期只有2秒钟。 String permitId = semaphore.acquire(2, TimeUnit.SECONDS); // ... semaphore.release(permitId); 8.8. 闭锁(CountDownLatch) 基于Redisson的Redisson分布式闭锁(CountDownLatch)Java对象RCountDownLatch采用了与java.util.concurrent.CountDownLatch相似的接口和用法。 RCountDownLatch latch = redisson.getCountDownLatch("anyCountDownLatch"); latch.trySetCount(1); latch.await(); // 在其他线程或其他JVM里 RCountDownLatch latch = redisson.getCountDownLatch("anyCountDownLatch"); latch.countDown();

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

建立高可靠、高性能的同步中间件(MirrorMaker)设计文档

FMQ同步中间件(MirrorMaker) 简介 FMQ的同步中间件英文名称为MirrorMaker,是在FMQ-Client的基础上引变而来的,用来作为跨机房的数据同步的工具。在网络异常等特殊情况下,也能在可靠性和性能上都能够满足公司线上需求而开发的一套同步中间件。 设计目标 MirrorMaker设计思路比较好理解,利用消费者从源机房拉取消息,并利用生产者发送消息至目标机房。但往往网络环境、broker集群稳定性、topic队列都会不断变化,在这种特殊情况下,也要实现一个高可靠、高性能的消息同步中间件需要考虑的细节非常多。比如消息幂等性、自动监控并切换网络出口、监控异常报警等。FMQ-mirrormaker就是针对这种特殊场景进行了定制化开发,实现高可靠和高性能的消息同步中间件。 应用模型 代码架构图 模块图 配置管理:配置source和target的broker的url、同步线程数、报警配置以及队列大小等 报警管理:基于event发布中心订阅相关的事件,并接入报警平台进行报警 消息同步管理:包括消费者管理、队列管理、生产者管理、Offset管理 监控管理:实时从broker获取需要监控的数据,并暴露接口给fmq-monitor获取监控数据 包结构图 mirrormaker-api:暴露api接口,供外部调用 mirrormaker-biz:具体的业务逻辑,包括监控、同步、报警、配置等信息 mirrormaker-bootstrap:启动类,包括(监控,配置、报警、消息同步)四大服务的启动 类图 AbstractBootstrap:作为最上层的抽象类,提供了doBootstrap()、doShutdown()供子类去实现,同时还持有事件发布接口、日志接口以及Config Monitor:持有SyncManager 实例,通过它来获取监控数据 Alarmer:通过订阅相关的事件提供报警服务 SyncManager:TargetDCProducer、SourceDCConsumer和TopicAndOffsetManager的大管家,用来协调消息同步。同时还会监听相应的事件,比如 网络不通、网络切换、新增同步topic、修改partition等等,对这些事件进行相应的处理来保证消息同步的正确性。 TopicAndOffsetManager: 1、获取需要同步的topic和分区,并定期更新topic和分区 2、获取并管理当前环境的source和target端的 分区对应的offset(source->brokerOffset、commitOffset,target->brokerOffset) SouceDCConsumer: 订阅需要同步的topic,并将消息放入queue中。定期提交缓存中的offset。 TargetDCProducer: 每个partition会启动一个线程来读取queue中消息,并写入目标broker,写成功后,将该消息的offset提交至缓存中。 具体实现 1、同步过程中异常情况处理 mirrormaker基于candy2的事件中心对异常情况进行了处理,使其真正意义上保证了跨机器消息同步的可靠性和实时性。 主要事件如下: add_topic:定期检测是否有新增topic并加入至同步列表中 remove_topic:释放占有的资源 modify_partion_num:定期检测,并将修改后的分区加入同步列表中 source_net_not_available: 定期检查网络情况,不通则抛出事件,由Alarmer报警 source_net_be_switched: 如果网络不通时间超过一定阀值,则会对source 网络进行切换(事先备好备用网络出口),切换成功后,再进行同步 target_net_not_available:目标端网络不通,抛出事件,由Alarmer报警 (备注:target的broker 一般和mirrormaker在同一机房,网络不通也不需要切换) 2、偏移量(offset)的管理 由于同步过程中,任何情况都可能发生,所以对于offset的何时提交尤为重要。一般正常情况是消费一条消息就提交,这样会存在以下二个问题: (1)频繁提交,会无形中给服务器增加压力 (2)作为同步中间件,应将整个同步的过程作为一个原子操作,也就是说消息要真正写入target端,才算同步成功,此时offset才会提交,否则不算同步成功 基于以上二种情况,我们在消息同步成功后将offset存入缓存中,并由消费者定期提交缓存中的offset,这样既降低了因频繁提交offset给服务器增加的压力,也将同步过程作为一个原子操作。同时还提供了饿JVM的钩子,保证宕机情况下,缓存里的offset能正常提交。 MirrorMaker监控 主要功能点: 1、获取各点mirrormaker的监控数据 Source端的TPS、Target端的TPS partition的sourceoffset、cacheoffset、commitoffset、lag(同步滞后数) 2、手动操作mirrormaker,比如网络不通,可以手动切换网络等等 总结 实现一个简单的同步中间件还是比较容易,但要在特殊情况下实现一个高可靠、高性能的同步中间件还是相对复杂的多,本章中的大幅篇幅基本上都是围绕如何建立高可靠、高性能的同步中间件。同步同步中间件实现消息的正常传输。

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

Android2.2 r1 API 中文文档系列(10) —— CheckBox

正文 一、类结构 public class CheckBox extends CompoundButton java.lang.Object android.view.View android.widget.TextView android.widget.Button android.widget.CompoundButton android.widget.CheckBox 二、 概述 复选框是一种有双状态按钮的特殊类型,可以选中或者不选中。如下是一个在activity中使用复选框的例子: 本文转自over140 51CTO博客,原文链接:http://blog.51cto.com/over140/582697,如需转载请自行联系原作者

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

关于安卓图像显示比iOS差的原因(英文文档)

There are so many comparations between Android phone and iPhone. We cannot make the conclusion about which one is better, but we all knows that the image quality of Android phone is much worse than iPhone. No matter you are using Facebook, Twitter or even Instagram, after taking the photo, adding a filter, then sharing to the social network, the images produced by Android phone are always coarse. Why? Our team had been working on this issue in the last year. After very deep research, we found that this was a "TINY" mistake made by Google. Although tiny, but the influence was very huge (all Android Apps related to image), and lasted till today. The problem is : libjpeg. We all know that libjpeg is widely used open source JPEG library. Android also uses libjpeg to compress images. After digging into the source code of Android, we can find that instead of using libjpeg directly, Android is based on an open source image engine called Skia. The Skia is a wonderful engine maintained by Google himself, all image functions are implemented in it, and it is widely used by Google and other companies' products (e.g.: Chrome, Firefox, Android......). The Skia has a good encapsulation of libjpeg, you can easily develop image utilites base on this engine. When using libjpeg to compress images, optimize_coding is a very important parameter. In libjpeg.doc, we can find following introductions about this parameter: boolean optimize_coding TRUE causes the compressor to compute optimal Huffman coding tables for the image. This requires an extra pass over the data and therefore costs a good deal of space and time. The default is FALSE, which tells the compressor to use the supplied or default Huffman tables. In most cases optimal tables save only a few percent of file size compared to the default tables. Note that when this is TRUE, you need not supply Huffman tables at all, and any you do supply will be overwritten. As the libjpeg.doc, we now know that because setting the optimize_coding to TRUE may cost a good deal of space and time, the default in libjpeg is FALSE. Everything seems fine about the doc, and libjpeg is very stable. But many people ignored that this document was writen for more than 10 years. At that time, space and computing abilities are very limited. With today's modern computers or even mobile phones, this is not an issue. On the contrary, we should pay more attention to the image quality (retina screens) and image size (cloud services). Google's engineers of skia project did not set this parameter, so the optimize_coding in Skia was remained to FALSE as the default value, and Skia concealed this setting, you could not change the setting outside of Skia. This became to a big problem, we had to endure worse image and bigger file size. Our team had tested optimize_coding for many different images. If you want the same quality of image compressing, the file size are 5-10 times bigger when setting the optimze_coding to FALSE than to TRUE. The difference is quite significant. We also compared the jpeg compressing between iOS and Android (they both concealed the optimize_coding parameter). With the same original images, if you want same quality level, you need 5-10 times file size on Android. The result is clear, Apple does know the importance of optimize_coding and Huffman tables and Google does not. (Apple uses their own Huffman table algorithm, not like libjpeg or libjpeg-turbo. It seems that Apple has done more tuning works on image compressing.) Finally, we decided not to use JPEG compress functions provided by Android, and we compiled our own native library based on libjpeg-turbo (libjpeg-turbo also has performance improvements). Now we can save 5-10 times of image space and enjoy the same or even better image quality. This work is totally worth to do. Thanks for reading, :) Our project on github: https://github.com/bither

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

android XMl 解析神奇xstream 六: 把集合list 转化为 XML文档

前言:对xstream不理解的请看: android XMl 解析神奇xstream 一: 解析android项目中 asset 文件夹 下的 aa.xml 文件 android XMl 解析神奇xstream 二: 把对象转换成xml android XMl 解析神奇xstream 三: 把复杂对象转换成 xml android XMl 解析神奇xstream 四: 将复杂的xml文件解析为对象 android XMl 解析神奇xstream 五: 把复杂对象转换成 xml ,并写入SD卡中的xml文件 1、创建JavaBeen package com.android10; public class Person { String pName ; String pAge ; public String getpName() { return pName; } public void setpName(String pName) { this.pName = pName; } public String getpAge() { return pAge; } public void setpAge(String pAge) { this.pAge = pAge; } } package com.android10; public class Product { private String name ; private String age ; private Person person ; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAge() { return age; } public void setAge(String age) { this.age = age; } public Person getPerson() { return person; } public void setPerson(Person person) { this.person = person; } } package com.android10; import java.util.List; public class ListBean { private List<Product> root ; public List<Product> getRoot() { return root; } public void setRoot(List<Product> root) { this.root = root; } } 2、主要方法 package com.android10; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.ArrayList; import java.util.List; import javax.xml.transform.OutputKeys; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.sax.SAXSource; import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.stream.StreamResult; import org.xml.sax.InputSource; import android.app.Activity; import android.os.Bundle; import com.thoughtworks.xstream.XStream; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView( R.layout.activity_main ); XStream xstream = new XStream() ; List<Product> root = getList() ; //将ListBean中的集合设置空元素,即不显示集合元素标签 xstream.addImplicitCollection( ListBean.class, "root"); xstream.autodetectAnnotations(true); //设置别名 xstream.alias( "product", Product.class ); //将name设置为父类(Student)的元素的属性 xstream.useAttributeFor( Product.class, "name" ); //把list集合转换成Xml字符串 String xmlString = xstream.toXML( root ) ; //把Xml字符串写入SD卡Xml文件 XstreamUtil xstreamUtil = new XstreamUtil() ; xstreamUtil.writeToXml( this , xmlString ) ; //把Xml字符串转化成list集合 List<Product> list = new ArrayList<Product>() ; list = (List<Product>) xstream.fromXML( xmlString ) ; System.out.println("sss"+ formatXml( xmlString ) ); } /** * 得到数据 * @return */ private List<Product> getList(){ Person person1 = new Person() ; person1.setpName( "saliy" ) ; person1.setpAge( "36" ); Product product1 = new Product() ; product1.setName( "jhon" ) ; product1.setAge( "30" ); product1.setPerson( person1 ); Person person2 = new Person() ; person2.setpName( "saliy02" ) ; person2.setpAge( "3602" ); Product product2 = new Product() ; product2.setName( "jhon02" ) ; product2.setAge( "3002" ); product2.setPerson( person2 ); List<Product> root = new ArrayList<Product>() ; root.add( product1 ) ; root.add( product2 ) ; return root ; } /** * 格式化XML字符串 * @param xml * @return */ public static String formatXml(String xml){ try{ Transformer serializer= SAXTransformerFactory.newInstance().newTransformer(); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); Source xmlSource=new SAXSource(new InputSource(new ByteArrayInputStream(xml.getBytes()))); StreamResult res = new StreamResult(new ByteArrayOutputStream()); serializer.transform(xmlSource, res); return new String(((ByteArrayOutputStream)res.getOutputStream()).toByteArray()); }catch(Exception e){ return xml; } } } package com.android10; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import android.content.Context; import android.os.Environment; public class XstreamUtil { XcallBack xcallBack ; /** * 把xml字符串写入SD卡文件 * @param context * @param str xml字符串 */ public void writeToXml(Context context, String str ){ //获取文件路径 String SDPATH = Environment.getExternalStorageDirectory() + "/myfile1.xml/" ; //创建文件 File file = new File( SDPATH ) ; if( !file.exists() ){ try { file.createNewFile() ; } catch (IOException e) { e.printStackTrace(); } } //写入数据 try { FileOutputStream out = new FileOutputStream( file ) ; OutputStreamWriter outw = new OutputStreamWriter(out); try { outw.write(str); outw.close(); out.close(); if( xcallBack != null ){ xcallBack.success(); } } catch (IOException e) { if( xcallBack != null ){ xcallBack.fail(); } } } catch (FileNotFoundException e1) { e1.printStackTrace(); if( xcallBack != null ){ xcallBack.fail(); } } } //设置监听器 void setXStreamLister( XcallBack xcallBack ){ this.xcallBack = xcallBack ; } } interface XcallBack{ /** * 写入成功 */ void success() ; /** * 写入失败 */ void fail() ; } 3、运行结果 <list> <product name="jhon"> <age>30</age> <person> <pAge>36</pAge> <pName>saliy</pName> </person> </product> <product name="jhon02"> <age>3002</age> <person> <pAge>3602</pAge> <pName>saliy02</pName> </person> </product></list>

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

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

用户登录
用户注册