首页 文章 精选 留言 我的

精选列表

搜索[安全机制],共10000篇文章
优秀的个人博客,低调大师

深入java虚拟机学习 -- 类的加载机制(四)

类加载的命名空间 每个类加载器都有自己的命名空间,命名空间由所有以此加载器为初始类加载器的类组成,不同命名空间的两个类是不可见的,但只要得到类所对应的Class对象的refrence(反射),还是可以访问另一个命名空间的类信息的。 同一个命名空间内的类是相互可见的,子加载器的命名空间包含所有父加载器的命名空间,也就是说由子加载器加载的类能看到父加载器加载的类。例如:系统类加载器加载的类能看到根类加载器加载的类(用户自定的类可以访问java.lang.*包下的信息),由父加载器加载的类不能看到子加载器加载的类。 如果两个加载器之间没有直接或者间接的父子关系,那么它们个字加载的类相互不可见。 创建用户自定义的类加载器 要创建用户自定义的类加载器,只需要扩展java.lang.ClassLoader类,然后覆盖它的findClass(String name)方法即可,该方法根据参数指定的类的名字,返回对应的Class对象的引用。 protected Class<?> findClass(String name) throws ClassNotFoundException { throw new ClassNotFoundException(name); } 我们可以按到ClassLoader里面的findClass方法的默认实现会抛出ClassNotFoundException异常,我们只需要在自定义的加载器里面重写,即可。 public class MyClassLoader extends ClassLoader { private String name;//类加载器的名字 private String path="";//加载类的默认路径 private String fileType=".class"; //class文件的扩展名 public MyClassLoader(String name){ super();//让系统类加载器成为该类加载器的父加载器 this.name=name; } public MyClassLoader(ClassLoader parent,String name){ super(parent);//显示指定该类加载器的父加载器 this.name=name; } @Override public String toString() { return this.name; } public String getPath() { return path; } public void setPath(String path) { this.path = path; } /** * 抽象类ClassLoader的findClass函数默认是抛出异常的。而前面我们知道, * loadClass在父加载器无法加载类的时候,就会调用我们自定义的类加载器中的findeClass函数, * 因此我们必须要在loadClass这个函数里面实现将一个指定类名称转换为Class对象. * @param name * @return */ @Override protected Class<?> findClass(String name) { byte [] data=this.loadClassData(name); return this.defineClass(name,data,0,data.length); } private byte[] loadClassData(String name) { InputStream is=null; byte [] data=null; ByteArrayOutputStream baos=null; try { this.name=this.name.replace(".","\\"); is=new FileInputStream(new File(path+name+fileType)); baos=new ByteArrayOutputStream(); int ch=0; while(-1!=(ch=is.read())){ baos.write(ch); } data= baos.toByteArray(); } catch(Exception e){ e.printStackTrace(); } finally { try { is.close(); baos.close(); } catch(IOException e) { e.printStackTrace(); } } return data; } public static void main(String[] args) throws Exception { MyClassLoader loader1 = new MyClassLoader("loader1");//没有指定loader的父加载器,则默认的父加载器为系统类加载器 loader1.setPath("G:\\myapp\\loader1\\"); MyClassLoader loader2 = new MyClassLoader(loader1,"loader2");//指定loader2的父加载器为loader1,这里的loader1和loader2都为MyClassLoader的实例 loader2.setPath("G:\\myapp\\loader2\\"); MyClassLoader loader3 = new MyClassLoader(null,"loader3");//bootstrap类加载器 loader3.setPath("G:\\myapp\\loader3\\"); //test(loader1); test(loader2); test(loader3); } public static void test(ClassLoader loader) throws Exception { Class clazz=loader.loadClass("Sample"); Object object=clazz.newInstance(); } 开开心心编码,快快乐乐生活。

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

Blackphone手机制造商欲推“高端”平板电脑

随着平板电脑市场变得越来越饱和,平板销售量可能也已达到峰值,平板制造商怎样才能脱颖而出呢?或许通过制造一款能把用户隐藏起来的平板电脑,将可实现这一目标。 图:Blackphone团队的隐私保护平板电脑标志 这正是Silent Circle在今年6月份推出的Blackphone智能手机背后的思想。该公司主要专注于用户隐私,这是其首要特征,因此Blackphone手机几乎为所有功能都进行了加密:短信、电子邮件、通话记录、网页浏览等。基于Blackphone手机的控制中心实用程序,Slient Circle强调用户有能力限制其信息的发送和接收量。这一切都因Silent Circle与Geeksphone合作构建的PrivatOS平台成为可能,该平台有点像专注于隐私的Android系统,但并未经Android认证。 正如许多其他Android设备制造商一样,Silent Circle决定从智能手机领域跃入平板电脑市场。该公司的联合创始人乔恩·卡拉斯(Jon Callas)向美国广播电视(BBC)表示,该公司“很快”将推出一款平板电脑,目前该设备已处于准备阶段。很遗憾,卡拉斯并未提供更多详细信息,不过他曾向美国全国广播公司财经频道(CNBC)表示,它将是一款“高端”平板设备。Blackphone智能手机的零售价为629美元,其中还包括一年期的Silent Circle移动计划。 毋庸置疑,该公司的这(些)款设备为智能手机市场上那些受隐私困扰的买家填补了空白,由于前段时间的明星照片曝光及类似事件,越来越多的人成为该隐私保护设备的买家。然而,即使是PrivatOS系统也并非刀枪不入——尽管Blackphone的小规模社区可保护其免受针对最大组织的黑客的窃听,但该设备在今年的Def Con黑客大会上还是被root了。 “Blackphone”式平板电脑面临的一个主要障碍是,它缺乏Android系统的认证,这意味着它将无法访问谷歌官方电子市场(Google Play Store)。然而Silent Circle详细说明了用户需如何访问亚马逊的应用商店,尽管其追踪用途与PrivatOS系统的目标有些相悖。虽然对智能手机用户而言,应用的缺乏可能没什么大碍,但对很多人来说,应用是他们选择使用平板电脑的主要因素。期待在Silent Circle最终发布其平板电脑时,我们可以看到该公司是如何处理这个问题的。 原文出处:科技行者 转载请与作者联系,同时请务必标明文章原始出处和原文链接及本声明。

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

IOS的消息传递机制,使用NSNotificationCenter进行通信,很实用

概述 在这个文档中,我们将讨论2个不相关的或者彼此之间不知道对方id的对象是如何通信的.所有的例子都是基于Objective-C的,这篇文章的关注点是Iphone开发.这个手册对那些在iphone开发和想要提高软件的易用性,扩展性的人将非常有用. 下面,我们将讨论具体的项目细节(http://www.hivestudio.cat/goldCube.zip),这个例子是一个小的OpenGL视图程序,你可以对金色正方体进行翻转.图片 使用者可以用"Rotate X""Rotate Y"和"Rotate Z"进行操作. 当使用者点击"Rotate X"按钮,"ViewController"中的“button1()”函数将被调用.然后"ViewController"将通知“OpenGLView”,告诉他,用户要进行翻转物体,问题是“ViewController”并没有任何"OpenGLView"实例,唯一可行的方法是使用"NotificationCenter"进行通信. 下面是使用“NotificationCenter”对"ViewController"和"OpenGLView"进行通信的步骤: 1) 在OpenGLView中添加消息的观察者. OpenGLView.m - (void)prepareOpenGL { //1 -> Adding OpenGLView as an observer.[[NSNotificationCenter defaultCenter]addObserver:selfselector:@selector(RotateX)name:@"button1"//表示消息名称,发送跟接收双方都要一致object:nil]... } 2)在"ViewController"中发送消息. viewController.m - (IBAction)button1:(id)pId; { //3 -> SENDING THE MESSAGE[[NSNotificationCenter defaultCenter] postNotificationName:@"button1" object:self];//注意object属性 } 3)"OpenGLView"相应对此消息的对应方法. OpenGLView.m //2 à IMPLEMENTING THE METHOD - (void) RotateX { NSLog(@"rotateX"); dAnlgeX=dAnlgeX+10; } 这些步骤允许我们在"OpenGLView"和"viewController"之间传递消息 同时在dealloc方法,将observer从notification center中移除 - (void)dealloc { [self setEmployees:nil]; NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc removeObserver:self]; [super dealloc]; } 本文转自编程小翁博客园博客,原文链接:http://www.cnblogs.com/wengzilin/archive/2012/03/15/2398229.html,如需转载请自行联系原作者

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

Android广播机制(两种注册方法)与 中断广播

两种注册类型的区别是: 1)第一种不是常驻型广播,也就是说广播跟随activity的生命周期。注意: 在activity结束前,移除广播接收器。 2)第二种是常驻型,也就是说当应用程序关闭后,如果有信息广播来,程序也会被系统调用自动运行。 在android下,要想接受广播信息,那么这个广播接收器就得我们自己来实现了,我们可以继承BroadcastReceiver,就可以有一个广播接受器了。有个接受器还不够,我们还得重写BroadcastReceiver里面的onReceiver方法,当来广播的时候我们要干什么,这就要我们自己来实现,不过我们可以搞一个信息防火墙。具体的代码: public class SmsBroadCastReceiver extends BroadcastReceiver { @Override public void onReceive(Contextcontext,Intentintent) { Bundlebundle = intent.getExtras(); Object[]object = (Object[])bundle.get( " pdus " ); SmsMessagesms[] = new SmsMessage[object.length]; for ( int i = 0 ;i < object.length;i ++ ) { sms[ 0 ] = SmsMessage.createFromPdu(( byte [])object[i]); Toast.makeText(context, " 来自 " + sms[i].getDisplayOriginatingAddress() + " 的消息是: " + sms[i].getDisplayMessageBody(),Toast.LENGTH_SHORT).show(); } // 终止广播,在这里我们可以稍微处理,根据用户输入的号码可以实现短信防火墙。 abortBroadcast(); } } 当实现了广播接收器,还要设置广播接收器接收广播信息的类型,这里是信息:android.provider.Telephony.SMS_RECEIVED 我们就可以把广播接收器注册到系统里面,可以让系统知道我们有个广播接收器。这里有两种,一种是代码动态注册: // 生成广播处理 smsBroadCastReceiver = new SmsBroadCastReceiver(); // 实例化过滤器并设置要过滤的广播 IntentFilter intentFilter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED"); // 注册广播 BroadCastReceiverActivity. this .registerReceiver(smsBroadCastReceiver,intentFilter); 一种是在AndroidManifest.xml中配置广播 <? xmlversion="1.0"encoding="utf-8" ?> < manifest xmlns:android ="http://schemas.android.com/apk/res/android" package ="spl.broadCastReceiver" android:versionCode ="1" android:versionName ="1.0" > < application android:icon ="@drawable/icon" android:label ="@string/app_name" > < activity android:name =".BroadCastReceiverActivity" android:label ="@string/app_name" > < intent-filter > < action android:name ="android.intent.action.MAIN" /> < category android:name ="android.intent.category.LAUNCHER" /> </ intent-filter > </ activity > <!-- 广播注册 --> < receiver android:name =".SmsBroadCastReceiver" > < intent-filter android:priority ="20" > < action android:name ="android.provider.Telephony.SMS_RECEIVED" /> </ intent-filter > </ receiver > </ application > < uses-sdk android:minSdkVersion ="7" /> <!-- 权限申请 --> < uses-permission android:name ="android.permission.RECEIVE_SMS" ></ uses-permission > </ manifest > 本文转自java豆子博客园博客,原文链接:http://www.cnblogs.com/error404/archive/2011/08/03/2126034.html,如需转载请自行联系原作者

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

android-手机内存分配和回收机制研究

Theory: There are two kinds ofmemory allocationmechanism : (1)Somelargeapplication ,like oracle client ,world of warcraft game : ( We can think about it likeBuffet(自助餐),if you paid, you can control what you eat and do not need to pay anymore ) This kind of application will have aminimum configurationof memory ( for example ,the WOW game will have at least 1gigabyte memory) ,this minimum memory is the largest estimation of the memory that it may use,it will never ask the Operation System for extra memory when runningit .(For example ,the wow.exe only need 400m memory ,the left memory are reserved for temp files ,swap files ,object files and so on ,so even it only needs 400M,the rest 600M are unavailable for other application .) So this kind of application has only two status: (Can run / cannot run),Once it runs ,it will always run and do not need to worry about the memory . (2)Small application: Most of the normal application are acted like this way ,it applies for a small memory ,and when it runs and needs more memory ,it asked the Operation system for more memory. (we can think it as “Choose dishes from menu”(点菜),if we needs more ,we order more ,pay more) So this kind of application will have three status: (cannot run /Can run/ can run but future the memory used out) During running ,it needs more memory and applied from OS ,so maybe onetime ,the OS cannot supply enough memory, this application will shutdown. Our issue: Based on the above theory ,we can take a look at the problem ,why sometimes ,the application will shut down if we scroll the screen very frequently in search result page. Because android mobile application is usingMechanism 2 Problem:when we go to the search result page ,if we scroll down the screen very frequently ,the application thread will shut down because of the memory used out. Phenomenon: scroll down very frequently ->Dalvik VM used out exception Reason: The Heap memory can be divided into parts,one is reserved for java objects ,the other is reserved for native C objects.(They cannot mix together) If we scroll up /down the screen very frequently ,the new native objects are created andONLY the native heap memory are recycled. And the recycling speed is much slower than the allocating memory speed ,that’s why the heap memory will used out. From the log ,we can see ,that only native heap memory are recycled (GC_EXTERNAL_ALLOC stands for the native heap memory recycle) And most the memory recycled are small( less than 150KB) ,that’s because android based on “slab” mechanism to allocate memory ,and the slab has a limit size. But what the size of the native heap memory it allocated when a new native c object created? The answer is320KBin our test So,allocate more and recycle less ,at last ,the memory will used out and the application process will die. Solution; When configure the emulator ,pleaseset the RAM(SD card) to be a large number ,and restart the emulator. Go to <ANDROID_ROOT>\.android\avd\<Your avd>\config.ini ,change thesdcard.size 本文转自 charles_wang888 51CTO博客,原文链接:http://blog.51cto.com/supercharles888/835923,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

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

Nacos

Nacos

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

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等操作系统。

用户登录
用户注册