CursorFileManager对cursor文件的读写
public class CursorFileManager implements CursorManager{public void write(String key, LongCursor cursor) throws IOException
{
File file = new File(key);
if (cursor == null) {
if (file.exists()) {
file.delete();
}
return;
} FileWriter fileWriter = null;
try {
fileWriter = new FileWriter(file);
JSON.writeJSONStringTo(cursor, fileWriter, new SerializerFeature[0]);
} catch (Exception e) {
this.logger.error(e.getMessage(), e);
} finally {
if (fileWriter != null)
fileWriter.close();
}
} public LongCursor read(String key){
JSONReader reader = null;
try {
File file = new File(key);
this.logger.info("try to read cursor from file={}", file.getAbsolutePath());
if (!file.exists()) {
return null;
}
reader = new JSONReader(new FileReader(file));
LongCursor cursor = (LongCursor)reader.readObject(LongCursor.class);
return cursor;
} catch (Exception e) {
this.logger.error(e.getMessage(), e);
} finally {
if (reader != null)
reader.close();
}
return null;
}
cursor格式:
{"biz":"false-0","extraInfo":1469203484000,"from":1469203208000,"to":1469203508000}
public LongCursor read() {
LongCursor cursor = cursorManager.read(cursorPath + "/" + fileName);
if (cursor != null) {
String biz = cursor.getBiz();
if (biz != null && biz.length() > 0) {
String[] secs = biz.split("-");
shouldWait = Boolean.parseBoolean(secs[0]);
if (secs.length > 1) {
completedOrderId = Long.valueOf(secs[1]);
}
}
}
return cursor;
} public void write(LongCursor cursor) throws IOException {
cursor.setBiz(shouldWait + "-" + completedOrderId);
cursorManager.write(cursorPath + "/" + fileName, cursor);
}
CursorFileManager对cursor文件的读写的更多相关文章
- C#对于文件的读写
C#文件的读写操作 转载请注明出处 http://www.cnblogs.com/Huerye/ /// <summary> /// 写入txt文件 /// </summary> ...
- java filechannel大文件的读写
java读取大文件 超大文件的几种方法 转自:http://wgslucky.blog.163.com/blog/static/97562532201332324639689/ java 读取一个 ...
- c# txt文件的读写
在公司实习,任务不太重,总结一下c#关于txt文件的读写,以便以后有用到的时候可以查看一下.如果有写得不完整的地方还请补充 说明:本人C#水平可能初级都谈不上,高手轻喷,参考:http://www.c ...
- C++中关于文件的读写
在C++的学习过程中,我们时常要用到对文件的操作,下面我们讲一下文件的读写. 首先,读.也就是把已有的文件读到控制台上,那么如何操作呢?首先要将文件操作的输入输出流包含进去. <fstream& ...
- php高并发状态下文件的读写
php高并发状态下文件的读写 背景 1.对于PV不高或者说并发数不是很大的应用,不用考虑这些,一般的文件操作方法完全没有问题 2.如果并发高,在我们对文件进行读写操作时,很有可能多个进程对进一文件 ...
- INI 文件的读写操作
在C#中对INI文件进行读写操作,在此要引入using System.Runtime.InteropServices; 命名空间,具体方法如下: #region 变量 private static r ...
- Java程序员的日常—— Properties文件的读写
在日常的Java程序开发中,Properties文件的读写是很常用的.经常有开发系统通过properties文件来当做配置文件,方便用户对系统参数进行调整. 那么本片就来简单的介绍下,如何使用Prop ...
- Android 对 properties文件的读写操作
-. 放在res中的properties文件的读取,例如对放在assets目录中的setting.properties的读取:PS:之所以这里只是有读取操作,而没有写的操作,是因为我发现不能对res下 ...
- C++学习48 对ASCII文件的读写操作
如果文件的每一个字节中均以ASCII代码形式存放数据,即一个字节存放一个字符,这个文件就是ASCII文件(或称字符文件).程序可以从ASCII文件中读入若干个字符,也可以向它输出一些字符. 对ASCI ...
随机推荐
- BAT批处理(六)
字符串处理 批处理有着具有非常强大的字符串处理能力,其功能绝不低于C语言里面的字符串函数集.批处理中可实现的字符串处理功能有:截取字符串内容.替换字符串特定字段.合并字符串.扩充字符串等功能.下面对这 ...
- HBase 所有命令解析
COMMAND GROUPS:Group name: generalCommands: status, table_help, version, whoami Group name: ddlComma ...
- mysql指定编码格式创建数据库
CREATE DATABASE `dev` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
- listBox和pictureBox的使用
重要属性:pictureBox中SizeMode可以更改图像显示的尺寸大小. using System; using System.Collections.Generic; using System. ...
- QT分析之QPushButton的初始化
原文地址:http://blog.163.com/net_worm/blog/static/127702419201001003326522/ 在简单的QT程序的第二行,声明了一个QPushButto ...
- %pylab ipython 中文
格式:%pylab [--no-import-all] [gui] 该命令会在ipython或notebook环境中自动加载numpy和matplotlib库,跟以下语句功能一致 import num ...
- java.awt.AWTError: Can't connect to X11 window server using ':20' as the value of the DISPLAY variable
1.使用pio在Linux服务器上创建window文件时,需要使用到Linux的图形界面服务,出现以下问题需确认用户权限. 参考文献:https://zhidao.baidu.com/question ...
- Delphi DBGrid双击事件、单元格操作
1.得到当前格子中的内容:DBGrid1.Fields[DBGrid1.SelectedIndex].DisplayText;把DBGrid1.SelectedIndex改为你所希望引用的字段就可以了 ...
- css3 字体渐变
先看个效果 https://www.bienvillecapital.com/ 然后人家样式这样写的 font-family: Overpass,Helvetica,sans-serif; font- ...
- BZOJ4873:[SHOI2017]寿司餐厅——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=4873 https://www.luogu.org/problemnew/show/P3749 简要题 ...