- 浏览: 269719 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
laitaogood:
请问,还有哪些API服务呢?比如说查看用户问答积分啊,用户发帖 ...
JavaEye-Api -
ruixinzheng:
闲聊一下
URL: http://api.iteye.com ...
JavaEye-Api -
ling520:
.....
思绪起*心间 -
ling520:
亲爱的,对不起哦~以后我一定尽量不让你等了~
今天,突然有了一种失落感 -
ling520:
小兔子想你了哈~
我很想你
目录结构如下:
--bean
----------MessageBean.java
----------ReceiveBean.java
----------SenderBean.java
---je
----------ClientUtilsMain.java
----------ReadThread.java
---lib
----------commons-beanutils-1.8.0.jar
----------commons-codec-1.3.jar
----------commons-collections-3.2.1.jar
----------commons-lang-2.4.jar
----------commons-logging-1.1.1.jar
----------ezmorph-1.0.6.jar
----------httpclient-4.0-beta2.jar
----------httpcore-4.0-beta3.jar
----------json-lib-2.3-jdk15.jar
---tools
----------ClientUtils.java
----------Native2AsciiUtils.java
----------TimeUtil.java
1.
json-lib-2.3-jdk15.jar
http://sourceforge.net/projects/json-lib/files
2.
http-client , http-core
http://hc.apache.org/
3.ezmorph-1.0.3.jar,commons-lang.jar,commons-logging.jar,commons-beanutils.jar,commons-collections-3.2.jar
可以下载jar包的网站http://www.docjar.com/
MessageBean.java package bean; public class MessageBean { private String system_notice ; private String created_at ; private String plain_body ; private String title ; private String id ; private String has_read ; private String attach ; private SenderBean sender ; private ReceiveBean receiver ; public String getAttach() { return attach; } public void setAttach(String attach) { this.attach = attach; } public String getCreated_at() { return created_at; } public void setCreated_at(String created_at) { this.created_at = created_at; } public String getHas_read() { return has_read; } public void setHas_read(String has_read) { this.has_read = has_read; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getPlain_body() { return plain_body; } public void setPlain_body(String plain_body) { this.plain_body = plain_body; } public ReceiveBean getReceiver() { return receiver; } public void setReceiver(ReceiveBean receiver) { this.receiver = receiver; } public SenderBean getSender() { return sender; } public void setSender(SenderBean sender) { this.sender = sender; } public String getSystem_notice() { return system_notice; } public void setSystem_notice(String system_notice) { this.system_notice = system_notice; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } }
ReceiveBean.java package bean; public class ReceiveBean { private String name ; private String logo ; private String domain ; public String getDomain() { return domain; } public void setDomain(String domain) { this.domain = domain; } public String getLogo() { return logo; } public void setLogo(String logo) { this.logo = logo; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
SenderBean.java package bean; public class SenderBean { private String name ; private String logo ; private String domain ; public String getDomain() { return domain; } public void setDomain(String domain) { this.domain = domain; } public String getLogo() { return logo; } public void setLogo(String logo) { this.logo = logo; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
ClientUtilsMain.java package je; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.sql.Timestamp; import java.util.ArrayList; import java.util.List; import net.sf.json.JSONArray; import org.apache.http.client.ClientProtocolException; import tools.ClientUtils; import tools.Native2AsciiUtils; import tools.TimeUtil; import bean.MessageBean; /** * * Notes:Main Class * Created:2010-8-9 * @author:Gerry * @version:1.0 */ public class ClientUtilsMain { /*User param setting*/ private static String user_name = "11" ; private static String user_pass = "11" ; private static String receive_name = "11" ; private static boolean isproxy = true ; private static final String NOTICE_STR = "Notice: `.refresh; 1.shownew ; 2.send ;3.history; 4.cls screen ; 5.help ; 6.exit" ; /*System param*/ //The JE only can show fifteen rows by api public static List<MessageBean> listBean = new ArrayList<MessageBean>(); public static String last_update_time = "2000/01/01 00:00:00.00" ; /** * @param args * @throws Exception * @throws Exception */ @SuppressWarnings("deprecation") public static void main(String[] args) throws Exception { System.out.println("please input your username:"); BufferedReader stdin1 =new BufferedReader(new InputStreamReader(System.in)); String str1=stdin1.readLine(); if(!str1.equals("")){user_name = str1 ;} System.out.println("please input your password:"); String str2=stdin1.readLine(); if(!str2.equals("")){user_pass = str2 ;} System.out.println("please input your receivename:"); String str3=stdin1.readLine(); if(!str3.equals("")){receive_name = str3 ;} clsScreen(); showNotice(); //Read line ReadThread readThread = new ReadThread(); readThread.start(); while(true){ System.out.println("+++++++++++++++++++++++++++++++++++"); String str=stdin1.readLine(); if(str!=null){ if(str.equals("`") || str.equals("refresh")){ receiveNewMessage(); } if(str.equals("1")){ showLastListMsg(); } if(str.equals("2")){ System.out.println("please wait..."); sendMessage(); clsScreen(); showNotice(); } if(str.equals("3")){ System.out.println("please wait..."); receiveMessage(); } if(str.equals("4") || str.equals("cls")){ //Process k = Runtime.getRuntime().exec("cmd /c cls"); clsScreen(); } if(str.equals("5") || str.equals("help")){ showNotice(); } if(str.equals("6") || str.equals("exit")){ readThread.stop(); break; } } } } public static List<MessageBean> showLastListMsg(){ for(int i=0;i<listBean.size();i++){ MessageBean bean = listBean.get(i); Timestamp stamp1 = TimeUtil.getTimeFromString(bean.getCreated_at()); Timestamp stamp2 = TimeUtil.getTimeFromString(last_update_time); long diff = TimeUtil.timeDiff2Timestamp(stamp1, stamp2); if(diff>0){ last_update_time = bean.getCreated_at();//取最后一条记录的时间 } System.out.println("No."+(i+1)+": ["+bean.getCreated_at()+"] "+bean.getSender().getName()+" :"+bean.getPlain_body()); } for(int i=0;i<listBean.size();i++){ listBean.remove(i); i--; } return listBean ; } public static String receiveMessage(){ String strResult = null; try { strResult = ClientUtils.getJsonContent("api.iteye.com","api/messages/inbox", user_name,user_pass,isproxy); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } //Use JSON-LIB parse data JSONArray jsonArray = JSONArray.fromObject(Native2AsciiUtils.ascii2Native(strResult)); MessageBean[] beans = (MessageBean[])JSONArray.toArray(jsonArray, MessageBean.class); for(int i=0;i<beans.length;i++){ System.out.println("No."+(i+1)+": ["+beans[i].getCreated_at()+"] "+beans[i].getSender().getName()+" :"+beans[i].getPlain_body()); } return Native2AsciiUtils.ascii2Native(strResult); } public static int receiveNewMessage(){ String strResult = null; try { strResult = ClientUtils.getJsonContent("api.iteye.com","api/messages/inbox", user_name,user_pass,isproxy); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } strResult = Native2AsciiUtils.ascii2Native(strResult); JSONArray jsonArray = JSONArray.fromObject(Native2AsciiUtils.ascii2Native(strResult)); MessageBean[] beans = (MessageBean[])JSONArray.toArray(jsonArray, MessageBean.class); for(int i=0;i<listBean.size();i++){ listBean.remove(i); i--; } for(int i=0;i<beans.length;i++){ Timestamp stamp1 = TimeUtil.getTimeFromString(beans[i].getCreated_at()); Timestamp stamp2 = TimeUtil.getTimeFromString(last_update_time); long diff = TimeUtil.timeDiff2Timestamp(stamp1, stamp2); if(diff > 0){ listBean.add(beans[i]); } } if(listBean.size()>0){ System.out.println("Notice: There is "+listBean.size()+" to press 1 shownew!"); } return 1 ; } public static String sendMessage() throws Exception { String str=null; String strResult = null; System.out.println("Please input the text:"); BufferedReader stdin =new BufferedReader(new InputStreamReader(System.in)); str=stdin.readLine(); try { //The third param is true for proxy,false for no proxy . strResult = ClientUtils.getJsonContent("api.iteye.com","api/messages/create?title=Message:&receiver_name="+receive_name+"&body="+str, user_name,user_pass,isproxy); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } System.out.println(Native2AsciiUtils.ascii2Native(strResult)); return "" ; } public static String showNotice(){ System.out.println(NOTICE_STR); return "" ; } public static String clsScreen(){ for(int i=0;i<10;i++){ System.out.println(""); } return "" ; } }
ReadThread.java package je; public class ReadThread extends Thread{ public long times = 30000L ; //30000ms public ReadThread(){} @SuppressWarnings("static-access") public void run() { while(true){ ClientUtilsMain.receiveNewMessage();//程序后台接收数据 try { this.sleep(times); } catch (InterruptedException e) { e.printStackTrace(); } } } }
ClientUtils.java package tools; import java.io.IOException; import org.apache.http.HttpEntity; import org.apache.http.HttpException; import org.apache.http.HttpHost; import org.apache.http.HttpRequest; import org.apache.http.HttpRequestInterceptor; import org.apache.http.HttpResponse; import org.apache.http.auth.AuthScheme; import org.apache.http.auth.AuthScope; import org.apache.http.auth.AuthState; import org.apache.http.auth.Credentials; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.CredentialsProvider; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.protocol.ClientContext; import org.apache.http.conn.params.ConnRoutePNames; import org.apache.http.impl.auth.BasicScheme; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.ExecutionContext; import org.apache.http.protocol.HttpContext; import org.apache.http.util.EntityUtils; public class ClientUtils { /** * 基于Basic认证的httpclient 连接 * @param hostUrl 要请求的host name 如:http://api.iteye.com/api/twitters/list -> api.iteye.com * @param getUrl 要请求的get url 如:http://api.iteye.com/api/twitters/list -> api/twitters/list * @param userName username * @param password password * @param isProxy isProxy * @return javaeye api 返回的json字符串 * @throws IOException * @throws ClientProtocolException */ public static String getJsonContent(String hostUrl,String getUrl,String userName,String password,boolean isProxy) throws ClientProtocolException, IOException{ String jsonStr=""; getUrl = getUrl.replaceAll(" ", ","); DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.getCredentialsProvider().setCredentials(new AuthScope(hostUrl, 80), new UsernamePasswordCredentials(userName, password)); BasicHttpContext localcontext = new BasicHttpContext(); BasicScheme basicAuth = new BasicScheme(); localcontext.setAttribute("preemptive-auth", basicAuth); httpclient.addRequestInterceptor((HttpRequestInterceptor) new PreemptiveAuth(), 0); HttpHost targetHost = new HttpHost(hostUrl); //Set proxy if(isProxy){ HttpHost proxy = new HttpHost("openproxy.xxx.com",8080); httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } HttpGet httpget = new HttpGet("/" + getUrl); HttpResponse response = httpclient.execute(targetHost, httpget, localcontext); HttpEntity entity = response.getEntity(); if (entity != null) { jsonStr = EntityUtils.toString(entity); //System.out.println(jsonStr); entity.consumeContent(); } httpclient.getConnectionManager().shutdown(); return jsonStr; } static class PreemptiveAuth implements HttpRequestInterceptor { public void process(final HttpRequest request,final HttpContext context) throws HttpException, IOException { AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE); // If no auth scheme avaialble yet, try to initialize it preemptively if (authState.getAuthScheme() == null) { AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth"); CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER); HttpHost targetHost = (HttpHost) context.getAttribute( ExecutionContext.HTTP_TARGET_HOST); if (authScheme != null) { Credentials creds = credsProvider.getCredentials( new AuthScope( targetHost.getHostName(), targetHost.getPort())); if (creds == null) { throw new HttpException("No credentials for preemptive authentication"); } authState.setAuthScheme(authScheme); authState.setCredentials(creds); } } } } }
Native2AsciiUtils.java package tools; /** * 仿照JDK-native2ascii.exe功能实现的(Java源代码) * Unicode编码转码 * 2010-08-06 * @author Gerry * @version 1.0 */ public class Native2AsciiUtils { /** * prefix of ascii string of native character */ private static String PREFIX = "\\u"; /** * Native to ascii string. It's same as execut native2ascii.exe. * @param str * native string * @return ascii string */ public static String native2Ascii(String str) { char[] chars = str.toCharArray(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < chars.length; i++) { sb.append(char2Ascii(chars[i])); } return sb.toString(); } /** * Native character to ascii string. * @param c * native character * @return ascii string */ private static String char2Ascii(char c) { if (c > 255) { StringBuilder sb = new StringBuilder(); sb.append(PREFIX); int code = (c >> 8); String tmp = Integer.toHexString(code); if (tmp.length() == 1) { sb.append("0"); } sb.append(tmp); code = (c & 0xFF); tmp = Integer.toHexString(code); if (tmp.length() == 1) { sb.append("0"); } sb.append(tmp); return sb.toString(); } else { return Character.toString(c); } } /** * Ascii to native string. It's same as execute native2ascii.exe -reverse. * @param str * ascii string * @return native string */ public static String ascii2Native(String str) { StringBuilder sb = new StringBuilder(); int begin = 0; int index = str.indexOf(PREFIX); while (index != -1) { sb.append(str.substring(begin, index)); sb.append(ascii2Char(str.substring(index, index + 6))); begin = index + 6; index = str.indexOf(PREFIX, begin); } sb.append(str.substring(begin)); return sb.toString(); } /** * Ascii to native character. * @param str * ascii string * @return native character */ private static char ascii2Char(String str) { if (str.length() != 6) { throw new IllegalArgumentException("Ascii string of a native character must be 6 character."); } if (!PREFIX.equals(str.substring(0, 2))) { throw new IllegalArgumentException("Ascii string of a native character must start with \"\\u\"."); } String tmp = str.substring(2, 4); int code = Integer.parseInt(tmp, 16) << 8; tmp = str.substring(4, 6); code += Integer.parseInt(tmp, 16); return (char) code; } }
TimeUtil.java package tools; import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; public class TimeUtil { /** * * Notes: 格式转换 * @param strTime * @return * Created:2010-8-11 * @author:Gerry */ public static Timestamp getTimeFromString(Object strTime) { SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.ENGLISH); Date date = new Date(); if (!strTime.equals("")) { try { String s=strTime.toString(); if(s.indexOf(".")!=-1){ if(s.substring(s.indexOf(".")).length()>4){ s=s.substring(0, s.indexOf(".")+4); } } date = format.parse(s); } catch (ParseException e) { e.printStackTrace(); } } Timestamp t = new Timestamp(date.getTime()); return t; } /** * 计算指定的两个时间的时间差数值 * @param time * @param anotherTime "2009-12-12 00:55:25.000 " * 前面的时间减去后面的时间 * @return */ public static long timeDiff2Timestamp(Timestamp time, Timestamp anotherTime) { long timeDiff = 1000;// 时间的差数值 timeDiff = time.getTime()-anotherTime.getTime(); return timeDiff; } /** * 当前时间 * Notes:TODO Please specify the functions of the method. * @return * Created:2010-8-11 * @author:Gerry */ public static String getCurrentTimeString() { return getCurrentTimeByFormat("yyyy/MM/dd HH:mm:ss"); } private static String getCurrentTimeByFormat(String format) { GregorianCalendar calendar = new GregorianCalendar(); java.util.Date date = calendar.getTime(); SimpleDateFormat sformat = new SimpleDateFormat(format); String currentDate = sformat.format(date); return currentDate; } }
发表评论
-
基于JavaEye-API实现的Gerry-聊天Dos版v1.0-lib库
2010-11-18 08:02 719Dos版本相关Lib库 -
关于运行方式上网简述
2010-11-10 12:56 0配置proxy后可上网。 代理地址 Proxycn2.hua ... -
Everything--Windows文件快速搜索引擎-支持Http服务器功能
2010-09-20 17:30 932http://www.voidtools.com/ ... -
基于JavaEye-API实现的Gerry-聊天QQ版v2.0
2010-09-20 17:27 693http://ling520.iteye.com/blog/7 ... -
基于JavaEye-API实现的Gerry-聊天QQ版v1.0 (全)
2010-09-02 23:37 1772目录结构如下: --bean----------Messag ... -
我的地盘--加密工具盘
2010-08-29 02:38 756官方网站: http://www.flagware.net/ ... -
工具-使用Fat-Jar为程序打包(支持加入第三方包)
2010-08-12 16:05 9591.下载Fat-Jarhttp://fjep.sourcefo ... -
JavaEye-Api
2010-08-05 13:18 1836更新时间:2010-04-12 JavaEye目前 ... -
Key:29189.id-pf.hta
2010-07-30 17:18 121053277B06DBD44EB91D05DA8FD7D3223 ... -
工具> DecodeFileFormatTxt.hta (通用模板)
2010-07-30 17:13 758<html> <head> < ... -
工具>FileFormatTxt.hta (v0.1文件转txt格式)
2010-07-30 16:28 1035<!DOCTYPE HTML PUBLIC " ... -
关于一段文字替换回车换行符(使之成为一行)
2010-07-21 09:58 1908把文字内容拷贝到Word文档中,使用 替换功能 输入 替换符 ... -
Html(纯文本显示浏览器-LynxLike)
2010-07-02 17:45 1118http://www.seo-browser.com ... -
在线制作你的素描图像(酷)
2010-07-02 15:40 1981http://www.pimptheface.com
相关推荐
NULL 博文链接:https://ago520.iteye.com/blog/814571
NULL 博文链接:https://ago520.iteye.com/blog/754087
"geronimo-stax-api_1.0_spec-1.0.1.jar"则是Geronimo项目的STAX API规范实现,STAX(Streaming API for XML)是一种处理XML的API,它允许开发者以流式的方式读取和写入XML数据,比DOM解析更高效,因为它不需要一次...
JavaEye的API使用帮助是一个针对JavaEye开发框架的详细指南,旨在帮助开发者更好地理解和应用这个框架。这个压缩包包含了三个文件:一个PDF文档,一个TXT文本文件,以及一个URL链接。接下来,我们将深入探讨JavaEye ...
- **JDK 5.0 API**:官方中文版,帮助开发者理解和使用Java 5.0的类库和接口。 - **JDK 1.6 API**:CHM格式的中文版,适用于Java 1.6版本。 4. **Java源码下载**: - **源码爱好者-JAVA专区**:提供各种Java项目...
在这个场景中,我们使用HttpClient来调用JavaEye API来验证用户。JavaEye可能是一个提供用户认证服务的平台,而API则提供了验证用户身份的功能。 以下是一个关于如何使用HttpClient调用JavaEye API的基本步骤: 1....
- JEECMS是一个基于Java的企业级内容管理系统,版本v1.1和v2.0的发布,展示了开源社区对内容管理系统的贡献,并提供了更多的功能如评论和投票。 11. **正则表达式实现的讨论** - Sun的Regexpr实现可能成为讨论的...
JavaEye API 的简单封装主要基于 Java 的 HttpClient 库,提供了更方便、易用的接口来执行 HTTP 请求。HttpClient 是一个成熟的 Java 库,用于执行 HTTP 协议的客户端请求,而 JavaEyeClient 则是对这个库进行了一层...
这个预览版包含了一系列新特性和改进,为即将发布的正式版奠定了基础。 - 后续的Eclipse 3.5.1 Galileo SR1版本则是对3.5版本的一次重要更新,修复了若干问题并提升了整体稳定性。 6. **Spring框架的更新** - ...
寒假花了3、4天改进了一下棋盘覆盖游戏,支持电脑演示,也可自己过关,具体可自己玩 ...呵呵 有安装程序 我放在javaeye上别人说有毒,真是无语,结果版主还给我屏蔽了。。。 我用的是Smart Install Maker安装软件打包的
Jsp-Servlet复习笔记-----第3章 Servlet技术 - 堕落天使 - JavaEye技术网站.mhtJsp-Servlet复习笔记-----第3章 Servlet技术 - 堕落天使 - JavaEye技术网站.mht
Xmappr是一个用Java实现的XML处理工具,它可能提供了高效且易于使用的API,帮助开发者更便捷地处理XML文档。 7. **2010年JFreeChart图表的新功能**: JFreeChart,一个流行的Java图表库,发布了新版本,增加了新...
JavaEye是一个基于Android平台的应用程序,它展示了在移动设备上构建功能丰富的软件的可能性。这个小应用旨在为开发者提供灵感和指导,帮助他们更好地理解和实践Android应用开发。让我们深入探讨一下这个应用背后的...
- 实现了JavaEye闲聊功能,允许用户进行即时聊天。 - 支持站内短信功能,方便用户发送和接收站内消息。 - 集成了收藏功能,让用户能够收藏感兴趣的内容。 - **发布情况**:该应用已经成功上线Android Market,即...
基于SNMP的网络拓扑发现 - 我的未来不是梦! - JavaEye技术网站.files基于SNMP的网络拓扑发现 - 我的未来不是梦! - JavaEye技术网站.files
2. **Android SDK**:作为基于Android平台的应用,JavaEye Client SourceCode必然使用了Android SDK,包括Android API的各种类库,例如视图(View)和布局(Layout)系统,以及用于网络通信、数据库操作、文件I/O等...
JavaEye新闻月刊2009年3月第13期内容涉及了当时软件开发领域内的一系列重要话题,包括IBM拟收购Sun Microsystems公司的新闻报道、Java社区对此的看法以及各种编程语言、开发工具和技术的新动态。 首先,新闻月刊...
13. Excel Report:这是一个基于Java实现的轻量级Excel报表生成工具,适合快速生成和导出数据报表。 14. Spring与Hibernate的声明式事务管理:Spring的声明式事务管理简化了事务控制,与Hibernate集成后能有效处理...