package protobuf.proto;
option java_outer_classname = "HtmlThemeProtos";
message HtmlTheme {
required int32 id = 1;
optional string title = 2;
optional string data = 3;
}
package protobuf.impl;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import database.DatabaseUtil;
import protobuf.proto.HtmlThemeProtos.HtmlTheme;
import protobuf.proto.HtmlThemeProtos.HtmlTheme.Builder;
public class WriteToFile {
public static void main(String[] args) throws ClassNotFoundException, SQLException, IOException {
String file = "G:/corpus/protobuf/TIME.txt";
String querySQL = "SELECT * FROM TIME";
Connection conn = DatabaseUtil.getConnection();
Statement statement = conn.createStatement();
ResultSet resultSet = statement.executeQuery(querySQL);
FileOutputStream outputStream = new FileOutputStream(new File(file));
System.out.println("BEGIN");
int count = 0;
while (resultSet.next()) {
int id = resultSet.getInt(1);
String title = resultSet.getString(2);
String data = resultSet.getString(3);
if (title == null || data == null) {
count++;
continue;
}
Builder htmlThemeBuilder = HtmlTheme.newBuilder();
htmlThemeBuilder.setId(id);
htmlThemeBuilder.setTitle(title);
htmlThemeBuilder.setData(data);
HtmlTheme build = htmlThemeBuilder.build();
build.writeDelimitedTo(outputStream);
}
resultSet.close();
statement.close();
conn.close();
outputStream.flush();
outputStream.close();
System.out.println("DONE");
System.out.println("====================================");
System.out.println(count);
System.out.println("====================================");
}
}
package protobuf.impl;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import protobuf.proto.HtmlThemeProtos.HtmlTheme;
public class ReadFromFile {
public static void main(String[] args) throws IOException {
String file = "G:/corpus/protobuf/TIME.txt";
FileInputStream inputStream = new FileInputStream(new File(file));
HtmlTheme htmlTheme;
int count = 0;
while ((htmlTheme = HtmlTheme.parseDelimitedFrom(inputStream)) != null) {
System.out.println(htmlTheme.getId() + "\t\t" + htmlTheme.getTitle());
count++;
}
System.out.println("===============================");
System.out.println(count);
System.out.println("===============================");
}
}
分享到:
相关推荐
windows下vs环境对protobuf的简单应用,所用vs版本2010,protobuf版本protobuf-2.5.0
protobuf java自动生成,例子实用
最简单的用socket发送protobuf对象的例子,
Protocol Buffers是Google公司开发的一种数据描述语言,类似于XML能够将...它不依赖于语言和平台并且可扩展性极强。现阶段官方支持C++、JAVA、Python等三种编程语言,但可以找到大量的几乎涵盖所有语言的第三方拓展包。
protobuf 源码库文件需要考到下面目录ym_vcpp-txsl\ym_vcpp-txsl\PublicNetSoft
unity3d protobuf-net c#前后端例子代码
protobuf 小例子 电话薄 源码 在运行时 需要把下载下来的protobuf源码库 放到,=目录下stProtocolBufers1\TestProtocolBufers下,
protobuf 测试例子
http://blog.csdn.net/gongkongrs/article/details/34420947,在http://blog.csdn.net/menggucaoyuan/article/details/16107201的例子修改了Makefile以适应自己的环境
Protocol Buffers(protobuf)是Google提供的一个开源序列化框架,这个demo将演示如何在Windows下VC++使用protobuf 配套文章地址:http://blog.csdn.net/mycwq/article/details/17606527
protobuf3.4源码和win32
写了一个简单的netty server和client,传输协议是google protobuf。上传文件主要包括源码以及转换proto文件的工具.
大数据场景下序列化和反序列化技术,谷歌提供技术 protobuf-jetbrains-plugin-0.13.0.zip
这个是在erlang项目中使用google protobuf例子,配套文章地址http://blog.csdn.net/mycwq/article/details/21864191
简单介绍protobuf
protobuf-net简单序列化反序列化例子
C # socket使用protobuf例子*************************************** *********************************************************************
VS版本:VS2019 ProtoBuffer版本:protobuf-3.8.0 C++最简VS工程 已生成Protoc和lib,提出头文件引用,所有引用使用安全的相对路径
google protobuf 最新源代码google protobuf 最新源代码google protobuf 最新源代码google protobuf 最新源代码google protobuf 最新源代码google protobuf 最新源代码google protobuf 最新源代码google protobuf ...