首页 文章 精选 留言 我的

精选列表

搜索[Cookie处理],共10000篇文章
优秀的个人博客,低调大师

mysql中blob数据处理

package epoint.mppdb_01.h3c; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.net.URI; import java.sql.Blob; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPReply; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IOUtils; public class MySQLblobToMPPphoto { // MySQL连接 public static Connection getMySQLConnection() throws Exception { String MySQLDRIVER = "com.mysql.jdbc.Driver"; String MySQLURL = "jdbc:mysql://192.168.186.13:3306/bigdata_scene03_rktj"; String MySQLUSERNAME = "root"; String MySQLPASSWORD = "Gepoint"; Connection MySQLconn = DriverManager.getConnection(MySQLURL, MySQLUSERNAME, MySQLPASSWORD); return MySQLconn; } // MPP连接 public static Connection getMPPConnection() throws Exception { String MPPDRIVER = "com.MPP.jdbc.Driver"; String MPPURL = "jdbc:MPP://192.168.186.14:5258/bigdata_scene03_rktj"; String MPPUSERNAME = "mpp"; String MPPPASSWORD = "h3c"; Connection MPPconn = DriverManager.getConnection(MPPURL, MPPUSERNAME, MPPPASSWORD); return MPPconn; } // public static void getMySQLblobToHDFS() throws Exception { Connection conn = getMySQLConnection(); ResultSet rs = null; try { String sql = "select ROW_ID,photo from t_rk_baseinfo_blob limit 10"; Statement prest = conn.prepareStatement(sql); rs = prest.executeQuery(sql); while (rs.next()) { int row_id = rs.getInt(1); Blob photo = rs.getBlob(2); System.out.println(row_id + " " + photo); InputStream in = photo.getBinaryStream(); OutputStream out = new FileOutputStream("H:/photo/" + row_id + ".jpg"); int len = 0; byte[] buffer = new byte[1024]; while ((len = in.read(buffer)) != -1) { out.write(buffer, 0, len); } upload("H:/photo/" + row_id + ".jpg"); } prest.close(); rs.close(); } catch (Exception e) { e.printStackTrace(); } finally { // 关闭连接 if (conn != null) { try { conn.close(); conn = null; } catch (Exception e) { e.printStackTrace(); } } } } public static void main(String[] args) throws Exception { getMySQLblobToHDFS(); } // HDFS附件上传 public static void upload(String uploadpath) throws Exception { Configuration conf = new Configuration(); URI uri = new URI("hdfs://192.168.186.14:8020"); FileSystem fs = FileSystem.get(uri, conf, "HDFS"); Path resP = new Path(uploadpath); Path destP = new Path("/photo"); if (!fs.exists(destP)) { fs.mkdirs(destP); } fs.copyFromLocalFile(resP, destP); fs.close(); System.out.println("***********************"); System.out.println("上传成功!"); } // HDFS附件下载 public static void download() throws Exception { Configuration conf = new Configuration(); String dest = "hdfs://192.168.186.14:/photo/11.png"; String local = "D://11.png"; FileSystem fs = FileSystem.get(URI.create(dest), conf, "hdfs"); FSDataInputStream fsdi = fs.open(new Path(dest)); OutputStream output = new FileOutputStream(local); IOUtils.copyBytes(fsdi, output, 4096, true); System.out.println("***********************"); System.out.println("下载成功!"); } }

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

Python IP处理模块IPy(转载)

安装 先下载源码,地址:ps://pypi.python.org/pypi/IPy/">https://pypi.python.org/pypi/IPy/ ,然后解压后使用命令python setup.py install安装。 使用 1、显示IP类型 IP('192.168.1.1').version() 4 IP('::1').version() 6 类似如上所示,通过version方法可以的判断输入的IP是IPv4还是IPv6 。 2、网段计算输出 代码: from IPy import IP ip=IP('192.168.0.0/28') print ip.len() for x in ip: print x print ip.strNormal(0) print ip.strNormal(1) print ip.strNormal(2) print ip.strNormal(3) len()方法可以计算网段的IP个数。 strNormal()方法指定不同wantprefixlen参数可以定制不同类型的输出。上面输出类似如下: 16 192.168.0.0 192.168.0.1 192.168.0.2 192.168.0.3 ...... 192.168.0.15 192.168.0.0 192.168.0.0/28 192.168.0.0/255.255.255.240 192.168.0.0-192.168.0.15 3、格式转换 实例介绍几个常用方法,包括方向解析名称、IP类型、IP进制转换、网络地址网段地址转换。 ip=IP('192.168.0.1') print ip.reverseNames() #反向解析地址格式 print ip.iptype() #显示IP地址类型,私有还是公有 ip=IP('8.8.8.8') print ip.iptype() print ip.int() #转换成整型格式 print ip.strHex() #转换成十六进制格式 print ip.strBin() #转换成二进制格式 网络地址、网段地址格式转换 print (IP('192.168.1.0').make_net('255.255.255.0')) print (IP('192.168.1.0/255.255.255.0',make_net=True)) print (IP('192.168.1.0-192.168.1.255',make_net=True)) 4、地址比较 判断IP地址和网段是否包含于另一个网段中,如下: '192.168.1.1' in IP('192.168.1.0/24') True IP('192.168.1.0/24') in IP('192.168.0.0/16') True 判断两个网段是否存在重叠,如下: IP('192.168.0.0/23').overlaps('192.168.1.0/24') 1 IP('192.168.1.0/24').overlaps('192.168.2.0') 0 其中1表示存在重叠,0表示不存在重叠。 举例 代码: coding:utf-8 from IPy import IP ip_s=raw_input("please input an IP or net-range: ") ips=IP(ip_s) if len(ips)>1: #网络地址 print('net: %s' % ips.net()) print('netmask: %s' % ips.netmask()) print('broadcast: %s' % ips.broadcast()) print('reverse address: %s' % ips.reverseNames()[0]) print('subnet: %s' % len(ips)) else: #单个地址 print('reverse address: %s' % ips.reverseNames()[0]) print('hexadecimal: %s' % ips.strHex()) print('binary: %s' % ips.strBin()) print('iptype: %s' % ips.iptype()) 运行结果: C:\Users\admin\workspace\zhangnq>python IPy_test2.py please input an IP or net-range: 192.168.1.1 reverse address: 1.1.168.192.in-addr.arpa. hexadecimal: 0xc0a80101 binary: 11000000101010000000000100000001 iptype: PRIVATE C:\Users\admin\workspace\zhangnq>python IPy_test2.py please input an IP or net-range: 8.8.8.8 reverse address: 8.8.8.8.in-addr.arpa. hexadecimal: 0x8080808 binary: 00001000000010000000100000001000 iptype: PUBLIC C:\Users\admin\workspace\zhangnq>python IPy_test2.py please input an IP or net-range: 192.168.1.0/28 net: 192.168.1.0 netmask: 255.255.255.240 broadcast: 192.168.1.15 reverse address: 0.1.168.192.in-addr.arpa. subnet: 16 hexadecimal: 0xc0a80100 binary: 11000000101010000000000100000000 iptype: PRIVATE ipy模块用法 一个自动识别IP地址、子网、方向解析、IP类型等信息的脚本 !/usr/bin/env python -- coding: utf-8 -- <pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; color: rgb(51, 51, 51); font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">def ip(): try: from IPy import IP ###加载模块 ip_s = raw_input('请输入IP地址或者网段地址:' )###输入一个IP地址或者网段 ips = IP(ip_s) #定义元素 if len(ips) > 1: #如果len出来的数字大于1,那么就是一个网段 print('网络地址: %s' % ips.net()) print('子网掩码: %s' % ips.netmask()) print('网络广播地址: %s' % ips.reverseNames() [0]) print('网络子网数: %s' % len(ips)) else: ###否则就是一个地址 print('IP反向解析: %s' % ips.reverseNames() [0]) print('十六进制地址: %s' % ips.strHex()) print('二进制地址: %s' % ips.strBin()) print('地址类型: %s' % ips.iptype()) print time.strftime("%Y-%m-%d %H:%M:%S") #code except Exception, e: logging.info("error:" + str(e) + "\n" + traceback.format_exc()) print traceback.format_exc() finally: pass</pre> 运行效果: [root@mylinuxer python]# 192.168.1.0/24 -bash: 192.168.1.0/24: No such file or directory [root@mylinuxer python]# python python.py 请输入IP地址或者网段地址: 192.168.1.0/24 网络地址: 192.168.1.0 子网掩码: 255.255.255.0 网络广播地址: 1.168.192.in-addr.arpa. 网络子网数: 256 [root@mylinuxer python]# python python.py 请输入IP地址或者网段地址: 192.168.1.1 IP反向解析: 1.1.168.192.in-addr.arpa. 十六进制地址: 0xc0a80101 二进制地址: 11000000101010000000000100000001 地址类型: PRIVATE [root@mylinuxer python]# python python.py 请输入IP地址或者网段地址: 116.213.249.211 IP反向解析: 211.249.213.116.in-addr.arpa. 十六进制地址: 0x74d5f9d3 二进制地址: 01110100110101011111100111010011 地址类型: PUBLIC

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

iOS图像处理之绘制直线

-(void)drawLine:(CGPoint)fromPnt toPoint:(CGPoint)toPnt{ float xScale = theImageView.image.size.width/theImageView.frame.size.width; float yScale = theImageView.image.size.height/theImageView.frame.size.height; UIGraphicsBeginImageContext(theImageView.image.size); [theImageView.image drawInRect:CGRectMake(0, 0, theImageView.image.size.width, theImageView.image.size.height)]; CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapSquare); CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 2.0*[self returnMax:xScale withNumber:yScale]); CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES); CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0); CGContextBeginPath(UIGraphicsGetCurrentContext()); CGContextMoveToPoint(UIGraphicsGetCurrentContext(), fromPnt.x*xScale, fromPnt.y*yScale); CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), toPnt.x*xScale, toPnt.y*yScale); CGContextStrokePath(UIGraphicsGetCurrentContext()); theImageView.image=UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); } 本文转自 卓行天下 51CTO博客,原文链接:http://blog.51cto.com/9951038/1772572,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

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

腾讯云软件源

腾讯云软件源

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

Nacos

Nacos

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

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册