java 压缩缓存_缓存压缩技术

论坛 期权论坛 脚本     
已经匿名di用户   2022-5-29 19:38   1929   0

package com.sf.dtx5.cache;

import java.io.ByteArrayOutputStream;

import java.io.IOException;

import java.nio.ByteBuffer;

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.text.SimpleDateFormat;

import java.util.ArrayList;

import java.util.Arrays;

import java.util.Date;

import java.util.HashMap;

import java.util.Hashtable;

import java.util.List;

import java.util.Locale;

import java.util.Map;

import java.util.zip.DeflaterOutputStream;

import com.sf.dtx5.Config;

import com.sf.dtx5.db.ConnectionPool;

import com.sf.dtx5.db.DbConnect;

import com.sf.dtx5.domain.CBillItem;

import com.sf.dtx5.domain.PubFun;

import com.sf.dtx5.util.Constanst;

import com.sf.dtx5.util.ExpOutUtils;

import com.sf.dtx5.util.ParseProperties;

/**

* 运单数据集合

* @author 084120

*/

public class CDTX5BillSetBale {

static private String m_SearchBillSql = ParseProperties.getValue("CDTX5BillSetBale_sql");

private static String mSearchBillSqlbyte = ParseProperties.getValue("CDTX5BillSetBale_sql_byte");

private static String judgesqlbyte = ParseProperties.getValue("billroute_Judge_sql");

private SimpleDateFormat timeformat = new SimpleDateFormat("HHmmss",Locale.US);

static private String loadDelayTm = ParseProperties.getValue("loadDelayTm");

static private String billrouteDays = ParseProperties.getValue("billrouteDays");

/**

* 最后一条运单记录的序列号

*/

private volatile long m_MaxSerialBillRoute = -1;

private volatile boolean reloadFlg = false; //用于控制全量加载

private String on=ParseProperties.getValue("CacheControl");

private int to=92;

private int go=3000;

/**

* 运单缓冲的快照信息队列

*/

private Hashtable> deliveCache;

private HashMap> deliveCacheByte;

private HashMap maxCacheNum ;

private HashMap maxGetNum ;

public CDTX5BillSetBale() {

deliveCache = new Hashtable>();

deliveCacheByte=new HashMap>();

maxCacheNum=new HashMap();

maxGetNum=new HashMap();

}

/**

* 从数据库中加载增量数据

*/

public void loadIncrementData() {

Connection con = null;

PreparedStatement pstmtCode = null;

ResultSet rsCode = null;

PreparedStatement pstmt = null;

ResultSet rs = null;

try {

con = ConnectionPool.getInstance().getConnection();

if (con == null) {

Config.log.writeLog(2, "连接数据库失败");

return;

}

if(reloadFlg){

m_MaxSerialBillRoute = -1;

reloadFlg = false;

}

Config.log.writeLog(2, "----序号信息----:%d", m_MaxSerialBillRoute);

if (m_MaxSerialBillRoute == -1) {

m_SearchBillSql = m_SearchBillSql.replaceAll(":1", loadDelayTm);

mSearchBillSqlbyte = mSearchBillSqlbyte.replaceAll(":1", loadDelayTm);

this.deliveCache.clear();

this.deliveCacheByte.clear();

this.maxCacheNum.clear();

this.maxGetNum.clear();

}

m_SearchBillSql = m_SearchBillSql.replaceAll(":2", billrouteDays);

mSearchBillSqlbyte = mSearchBillSqlbyte.replaceAll(":2", billrouteDays);

if("1".equals(on)){

m_MaxSerialBillRoute -=2;

pstmtCode=con.prepareStatement(judgesqlbyte);

rsCode = pstmtCode.executeQuery();

while(rsCode!=null&&rsCode.next()){

String zno=rsCode.getString(1);

if (zno == null|| zno.trim().equals("")) {

continue;

}

pstmt = con.prepareStatement(mSearchBillSqlbyte);

if(reloadFlg){

for(Map.Entry entry : maxCacheNum.entrySet()){

String key = entry.getKey();

maxCacheNum.put(key, -1L);

}

}

if (maxCacheNum.get(zno)==null){

maxCacheNum.put(zno, -1L);

}

pstmt.setLong(1, maxCacheNum.get(zno));

pstmt.setString(2, zno);

rs = pstmt.executeQuery();

itemGetByte(rs,zno);

DbConnect.closeOthers(pstmt, null);

}

} else {

pstmt = con.prepareStatement(m_SearchBillSql);

pstmt.setLong(1, m_MaxSerialBillRoute);

rs = pstmt.executeQuery();

if (rs.next()) {

int i = 0;

CBillItem item;

List ls = new ArrayList(20000);

do {

try {

item = new CBillItem(rs.getString("bno"),

rs.getString("deszno").contains(Constanst.IDENT_NO)?rs.getString("deszno").replaceAll(Constanst.IDENT_NO, "000"):rs.getString("deszno"),

rs.getString("ident_des_zno_mapbef"),

rs.getString("objzone"),

rs.getLong("id"),

(short)0,//rs.getShort("wanted_status"),

rs.getString("transit_zno"),

rs.getString("area_code"),//片区代码

rs.getDouble("weight"),

rs.getString("product_code"),//产品类型T4

rs.getString("origin_detail_info")//源快件内容

);

ls.add(item);

} catch (Exception e) {

e.printStackTrace();

}

// 分多次添加到列表,防止列表被长时间锁定

if ((++i) >= 20000) {

i = 0;

additems(ls);

Config.log.writeLog(2, "加载序号信息:%d",m_MaxSerialBillRoute);

}

} while (rs.next());

additems(ls);

Config.log.writeLog(2, "加载序号信息:%d", m_MaxSerialBillRoute);

}

}

} catch (Exception e) {

Config.log.writeLog(2, "查询运单失败:%s", e);

} finally {

DbConnect.closeOthers(pstmt, rs);

DbConnect.closeOthers(pstmtCode, rsCode);

ConnectionPool.getInstance().putConnection(con);

}

}

public void itemGetByte(ResultSet rs,String zno) throws SQLException {

if (rs.next()) {

int i = 0;

CBillItem item;

List ls = new ArrayList(20000);

do {

try {

item = new CBillItem(rs.getString("bno"),

rs.getString("deszno").contains(Constanst.IDENT_NO)?rs.getString("deszno").replaceAll(Constanst.IDENT_NO, "000"):rs.getString("deszno"),

rs.getString("ident_des_zno_mapbef"),

rs.getString("objzone"),

rs.getLong("id"),

(short)0,//rs.getShort("wanted_status"),

rs.getString("transit_zno"),

rs.getString("area_code"),//片区代码

rs.getDouble("weight"),

rs.getString("product_code"),//产品类型T4

rs.getString("origin_detail_info")//源快件内容

);

ls.add(item);

} catch (Exception e) {

e.printStackTrace();

}

// 分多次添加到列表,防止列表被长时间锁定

if ((++i) >= 20000) {

i = 0;

additemsByte(ls,zno);

Config.log.writeLog(2, "加载序号信息:%d",

m_MaxSerialBillRoute);

}

} while (rs.next());

additemsByte(ls,zno);

Config.log.writeLog(2, "加载序号信息:%d", m_MaxSerialBillRoute);

}

}

/**

* 取得运单信息,支持V2.3或以上的版本

* @param seqid 开始运单系号

* @param maxcount 最大可取的取记录个数

* @param ver 版本号数

* @param bIncrement 是否增量下载

*/

public byte[] getBill(char cmdChar, long seqid, int maxcount,

String transitcode) {

long lsatId=seqid;

byte[] datas = null;

DeflaterOutputStream dos = null;

int total = 0;

int right =0;

try {

byte[] data = null;

if("1".equals(on)

&&seqid

List listbyte = this.deliveCacheByte.get(transitcode);

if (!listbyte.isEmpty()) {

total =listbyte.size();

int last=listbyte.get(total-1).length/to;

int good=(total- 1)*go;

right = good+last;

long startindex = (seqid > 0) ? getBillStartIndexByte(seqid,

listbyte,right,transitcode) : 0;

int count = (int) (right - startindex);

if (count > maxcount) {// 设置最大下载量限制

count = maxcount;

}

if (count > 0) {

lsatId =conTrast(listbyte,startindex + count);

data = getBuffersByte(cmdChar, startindex, count,

listbyte,transitcode,lsatId);

}

}

}else if (seqid < m_MaxSerialBillRoute) {

List list = this.deliveCache.get(transitcode);

if (!list.isEmpty()) {

total = list.size();

int startindex = (seqid > 0) ? getBillStartIndex(seqid,

list) : 0;

int count = list.size() - startindex;

if (count > maxcount) {// 设置最大下载量限制

count = maxcount;

}

if (count > 0) {

lsatId = list.get(startindex + count - 1).seqid;

data = getBuffers(cmdChar, startindex, count,

list);

}

}

}

if(cmdChar=='x' || cmdChar=='d' || cmdChar=='e'){

ByteBuffer buffer = ByteBuffer.allocate(4 + 2 + 12 + 12 + 8

+ ((data != null) ? data.length : 0));

String str = timeformat.format(new Date());

buffer.put((byte) str.charAt(0));

buffer.put((byte) str.charAt(1));

buffer.put((byte) str.charAt(2));

buffer.put((byte) str.charAt(3));

buffer.put((byte) str.charAt(4));

buffer.put((byte) str.charAt(5));

String strseqid = PubFun.padLeft(String.valueOf(lsatId), 12);

PubFun.putString(buffer, strseqid);

if (data != null && data.length > 0) {// 当存在数据时实时更新最大序列

if("1".equals(on)){

PubFun.putString(buffer, PubFun.padLeft(

String.valueOf(maxCacheNum.get(transitcode)), //getMaxSeqIDFromDatabase(transit_code)

12));

}else{

PubFun.putString(buffer, PubFun.padLeft(

String.valueOf(m_MaxSerialBillRoute), //getMaxSeqIDFromDatabase(transit_code)

12));

}

} else {

PubFun.putString(buffer, strseqid);

}

if("1".equals(on)){

PubFun.putString(buffer, PubFun.padLeft(String.valueOf(right), 8));

}else{

PubFun.putString(buffer, PubFun.padLeft(String.valueOf(total), 8));

}

if (data != null) {

buffer.put(data);

}

datas = zipGet(buffer);

}else{

ByteBuffer buffer = ByteBuffer.allocate(4 + 2 + 12 + 12

+ ((data != null) ? data.length : 0));

String str = timeformat.format(new Date());

buffer.put((byte) str.charAt(0));

buffer.put((byte) str.charAt(1));

buffer.put((byte) str.charAt(2));

buffer.put((byte) str.charAt(3));

buffer.put((byte) str.charAt(4));

buffer.put((byte) str.charAt(5));

String strseqid = PubFun.padLeft(String.valueOf(lsatId), 12);

PubFun.putString(buffer, strseqid);

if (data != null && data.length > 0) {// 当存在数据时实时更新最大序列

PubFun.putString(buffer, PubFun.padLeft(

String.valueOf(m_MaxSerialBillRoute), //getMaxSeqIDFromDatabase(transit_code)

12));

} else {

PubFun.putString(buffer, strseqid);

}

if (data != null) {

buffer.put(data);

}

if (cmdChar == 'D'||cmdChar == 'X') {// 压缩

datas = zipGet(buffer);

}else {

datas = buffer.array();

}

}

} catch (Exception e) {

datas = null;

Config.log.writeLog(2, "返回路由信息失败[%s]", e.getMessage() + " strace : " + ExpOutUtils.getStackTrace(e));

} finally {

try {

if (dos != null)

dos.close();

} catch (IOException e) {

e.printStackTrace();

}

}

return datas;

}

public byte[] zipGet(ByteBuffer buffer) throws IOException {

byte[] datas;

DeflaterOutputStream dos;

ByteArrayOutputStream baos = new ByteArrayOutputStream();

dos = new DeflaterOutputStream(baos);

dos.write(buffer.array());

dos.finish();

int len = buffer.array().length;

ByteBuffer temp = ByteBuffer

.allocate(4 + baos.toByteArray().length);// 压缩前的数据长度

temp.putInt(Integer.reverseBytes(len));

temp.put(baos.toByteArray());

datas = temp.array();

return datas;

}

/**

* 添加运单信息到列表,防止列表长时间被锁住

* @param ls

*/

private void additems(List ls) {

if (ls.size() > 0) {

int delcount;

synchronized (this) {

m_MaxSerialBillRoute = ls.get(ls.size() - 1).seqid;

for (int i = 0; i < ls.size(); i++) {

CBillItem item = ls.get(i);

if (item.getTransitCode() == null

|| item.getTransitCode().trim().equals("")) {

continue;

}

List tmp = this.deliveCache.get(item

.getTransitCode());

if (tmp == null) {

tmp = new ArrayList(Config.getMaxbillstartcount());//Config.getMaxBillZoneRecourdCount()

this.deliveCache.put(item.getTransitCode(), tmp);

}

delcount = tmp.size() + 1

- Config.getMaxBillZoneRecourdCount();

if (delcount > 0) {// 删除超出DTX5巴枪容量部分

if (delcount > tmp.size()) {// 最多删除list的大小

delcount = tmp.size();

}

tmp.subList(0, delcount).clear(); // 从头部截断超出的部分

}

tmp.add(item);

}

}

ls.clear();

}

}

/**

* 添加运单信息到列表,防止列表长时间被锁住

*

* @param ls

*/

private void additemsByte(List ls,String zno) {

if (!ls.isEmpty()) {

synchronized (this) {

cacheGet(ls, zno);

}

ls.clear();

}

}

public void cacheGet(List ls, String zno) {

ByteBuffer buffer=null;

ByteBuffer bufferre=null;

maxCacheNum.put(zno, ls.get(ls.size() - 1).seqid);

List tmp = this.deliveCacheByte.get(zno);

if (tmp == null) {

tmp = new ArrayList();//Config.getMaxBillZoneRecourdCount()

this.deliveCacheByte.put(zno, tmp);

int remain=ls.size()%go;

int tosize=ls.size()/go;

if(tosize!=0){

for(int j=0;j

buffer=ByteBuffer.allocate(to*go);

for (int i=j*go;i

CBillItem bill = ls.get(i);

byteGet(buffer, bill);

}

cacheGet(buffer, bufferre,tmp);

}

buffer=null;

}

if (remain!=0) {

bufferre = ByteBuffer.allocate(to*remain);

for (int i=tosize*go;i

CBillItem bill = ls.get(i);

byteGet(bufferre, bill);

}

}

}else{

byte[] lastsize=tmp.get(tmp.size()-1);

int lenght=go-lastsize.length/to;

ByteBuffer buf;

if(ls.size()<=lenght){

buf=ByteBuffer.allocate(lastsize.length+to*ls.size());

buf.put(Arrays.copyOf(lastsize,lastsize.length));

for (int i = 0; i < ls.size(); i++) {

CBillItem bill = ls.get(i);

byteGet(buf, bill);

}

tmp.set(tmp.size() - 1, buf.array());

} else {

buf = ByteBuffer.allocate(to*go);

buf.put(Arrays.copyOf(lastsize, lastsize.length));

for (int i = 0; i < lenght; i++) {

CBillItem bill = ls.get(i);

byteGet(buf, bill);

}

tmp.set(tmp.size() - 1, buf.array());

int resize=ls.size()-lenght;

int remain=resize%go;

int tosize=resize/go;

if(tosize!=0){

for(int j=0;j

buffer=ByteBuffer.allocate(to*go);

for (int i=j*go+lenght;i

CBillItem bill = ls.get(i);

byteGet(buffer, bill);

}

cacheGet(buffer, bufferre,tmp);

}

buffer=null;

}

if (remain!=0) {

bufferre = ByteBuffer.allocate(to*remain);

for (int i=tosize*go+lenght;i

CBillItem bill = ls.get(i);

byteGet(bufferre, bill);

}

}

}

}

cacheGet(buffer, bufferre,tmp);

}

public void cacheGet(ByteBuffer buffer, ByteBuffer bufferre,List tmp) {

int delcount;

int maxnum=Config.getMaxBillZoneRecourdCount()/go;

delcount = tmp.size() + 1

- maxnum;

if (delcount > 0) {// 删除超出DTX5巴枪容量部分

if (delcount > maxnum) {// 最多删除list的大小

delcount = maxnum;

}

tmp.subList(0, delcount).clear(); // 从头部截断超出的部分

}

if(buffer!=null){

tmp.add(buffer.array());

buffer.clear();

}

if(bufferre!=null){

tmp.add(bufferre.array());

bufferre.clear();

}

}

public void byteGet(ByteBuffer buffer, CBillItem bill) {

buffer.put(bill.billBytes); // 6 byte

buffer.put(bill.zoneBytes); // 10 byte

buffer.put(bill.tagWanted); // 1 byte

buffer.put(bill.objzoneBytes); // 10 byte

buffer.put(bill.zoneBefBytes); // 10 byte

buffer.put(bill.areaCode); // 10 byte

buffer.put(bill.weight); // 10 byte

buffer.put(bill.productCode); // 5 byte

buffer.put(bill.origin_detail_info); // 10 byte

buffer.put(longToBytes(bill.seqid));//20 byte total 92 byte

}

/**

* 找出增量下载索引的开始位置

* @param seqid

*/

private int getBillStartIndex(long seqid, List ls) {

int right = ls.size() - 1;

int middle = right - (int) (ls.get(ls.size() - 1).seqid - seqid);// 上一次下载记录在列表的相对位置

if ((middle >= 0) && (middle < right)

&& (ls.get(middle).seqid == seqid)) {// 直接在相对位置找到上一次传送的记录,则当前记录的下一条为开始位置

return (middle + 1);

} else {// 用利用二分查找,找出开始下载的位置

int left = 0;

while (left <= right) {

middle = (left + right) / 2;

if (ls.get(middle).seqid > seqid) {

right = middle - 1; // 继续在R[left..middle-1]中查找

} else {

left = middle + 1; // 继续在R[middle+1..right]中查找

}

}

return left;

}

}

public long bytesToLong(byte[] bytes) {

ByteBuffer buffer=ByteBuffer.allocate(20);

buffer.put(bytes, 0, bytes.length);

buffer.flip();//need flip

return buffer.getLong();

}

public byte[] longToBytes(long x) {

ByteBuffer buffer=ByteBuffer.allocate(20);

buffer.putLong(0, x);

return buffer.array();

}

private long getBillStartIndexByte(long seqid, List ls,int right,String zno) {

long findId = 0;

long fini=0;

long realseqid;

byte[] bigNum=ls.get(ls.size() - 1);

if(maxGetNum.get(zno)!=null&&maxGetNum.get(zno)==seqid){

realseqid=seqid+1L;

}else{

realseqid=bytesToLong(Arrays.copyOfRange(bigNum, bigNum.length-20, bigNum.length));

}

long add=realseqid - seqid;

long middle = right-add-1;// 上一次下载记录在列表的相对位置

if ((middle >= 0) && (middle < right-1)) {// 直接在相对位置找到上一次传送的记录,则当前记录的下一条为开始位置

fini = conTrast(ls, middle+1);

}

if(fini==seqid){

findId=middle+1;

}else{// 用利用二分查找,找出开始下载的位置

long left = 0;

long rigtwo=right-1;

while (left <= rigtwo) {

middle = (left + rigtwo) / 2;

if (conTrast(ls, middle+1) > seqid) {

rigtwo = middle - 1; // 继续在R[left..middle-1]中查找

} else {

left = middle + 1; // 继续在R[middle+1..right]中查找

}

}

findId= left;

}

return findId;

}

public long conTrast(List ls, long middle) {

int real=(int) (middle%go);

int size=(int) (middle/go);

long fini;

if(real==0){

byte[] fiList=ls.get(size-1);

fini=bytesToLong(Arrays.copyOfRange(fiList, fiList.length-20, fiList.length));

}else{

byte[] fiList=ls.get(size);

fini=bytesToLong(Arrays.copyOfRange(fiList, to*real-20, to*real));

}

return fini;

}

/**

* 客户端V2.3版本的下载数据结构

* @param startindex

* @param count

*/

private byte[] getBuffers(char cmdChar, int startindex, int count,

List ls) {

CBillItem bill;

ByteBuffer buffer = null;

long seqid = 0;

if (cmdChar == 'D') {

buffer = ByteBuffer.allocate(count * 27);

for (int i = 0; i < count; i++) {

bill = ls.get(startindex + i);

buffer.put(bill.billBytes); // 6 byte

buffer.put(bill.zoneBytes); // 10 byte

buffer.put(bill.tagWanted); // 1 byte

buffer.put(bill.objzoneBytes); // 10 byte

seqid = bill.seqid;

}

}else if(cmdChar == 'X' || cmdChar == 'x' ){

buffer = ByteBuffer.allocate(count * 37);

for (int i = 0; i < count; i++) {

bill = ls.get(startindex + i);

buffer.put(bill.billBytes); // 6 byte

buffer.put(bill.zoneBytes); // 10 byte

buffer.put(bill.tagWanted); // 1 byte

buffer.put(bill.objzoneBytes); // 10 byte

buffer.put(bill.zoneBefBytes); // 10 byte

seqid = bill.seqid;

}

}else if(cmdChar == 'd'){//sfit0336 billroute表增加字段:area_code/weight

buffer = ByteBuffer.allocate(count * 57);

for (int i = 0; i < count; i++) {

bill = ls.get(startindex + i);

buffer.put(bill.billBytes); // 6 byte

buffer.put(bill.zoneBytes); // 10 byte

buffer.put(bill.tagWanted); // 1 byte

buffer.put(bill.objzoneBytes); // 10 byte

buffer.put(bill.zoneBefBytes); // 10 byte

buffer.put(bill.areaCode); // 10 byte

buffer.put(bill.weight); // 10 byte

seqid = bill.seqid;

}

}else if(cmdChar == 'e'){//sfit0336 billroute表增加字段:product_code 5 origin_detail_info 10

buffer = ByteBuffer.allocate(count * 72);

for (int i = 0; i < count; i++) {

bill = ls.get(startindex + i);

buffer.put(bill.billBytes); // 6 byte

buffer.put(bill.zoneBytes); // 10 byte

buffer.put(bill.tagWanted); // 1 byte

buffer.put(bill.objzoneBytes); // 10 byte

buffer.put(bill.zoneBefBytes); // 10 byte

buffer.put(bill.areaCode); // 10 byte

buffer.put(bill.weight); // 10 byte

buffer.put(bill.productCode); // 5 byte

buffer.put(bill.origin_detail_info); // 10 byte

seqid = bill.seqid;

}

}else{

buffer = ByteBuffer.allocate(count * 17);

for (int i = 0; i < count; i++) {

bill = ls.get(startindex + i);

buffer.put(bill.billBytes); // 6 byte

buffer.put(Arrays.copyOfRange(bill.zoneBytes, 0, 5)); // 5 byte

buffer.put(bill.tagWanted); // 1 byte

buffer.put(Arrays.copyOfRange(bill.objzoneBytes, 0, 5)); // 5

seqid = bill.seqid;

}

}

Config.log.writeLog(4, cmdChar+":传送系号--位置:%d--%d", seqid, startindex + count);

return buffer.array();

}

private byte[] getBuffersByte(char cmdChar, long startindex, int counts,

List ls,String zno,long lastId) {

this.maxGetNum.put(zno, lastId);

byte[] billget;

ByteBuffer buffer = null;

if (cmdChar == 'D') {

buffer=ByteBuffer.allocate(counts * 27);

}else if(cmdChar == 'X' || cmdChar == 'x' ){

buffer=ByteBuffer.allocate(counts * 37);

}else if(cmdChar == 'd'){

buffer=ByteBuffer.allocate(counts * 57);

}else if(cmdChar == 'e'){

buffer=ByteBuffer.allocate(counts * 72);

}else {

buffer=ByteBuffer.allocate(counts * 17);

}

int remain=(int) ((startindex)%go);

int reLenght=go-remain;

int tosize=(int) ((startindex)/go);

if(remain==0){

int rem=counts%go;

int size=counts/go;

if(size!=0){

for(int j=tosize;j

billget= ls.get(j);

for(int k=0;k

if (cmdChar == 'D') {

byteGetD(buffer, k, billget);

}else if(cmdChar == 'X' || cmdChar == 'x' ){

byteGetX(buffer, k, billget);

}else if(cmdChar == 'd'){

byteGetDd(buffer, k, billget);

}else if(cmdChar == 'e'){

byteGetE(buffer, k, billget);

}else {

byteGetOther(buffer, k, billget);

}

}

}

}

if(rem!=0){

billget= ls.get(size+tosize);

for(int k=0;k

if (cmdChar == 'D') {

byteGetD(buffer, k, billget);

}else if(cmdChar == 'X' || cmdChar == 'x' ){

byteGetX(buffer, k, billget);

}else if(cmdChar == 'd'){

byteGetDd(buffer, k, billget);

}else if(cmdChar == 'e'){

byteGetE(buffer, k, billget);

}else {

byteGetOther(buffer, k, billget);

}

}

}

}else{

billget= ls.get(tosize);

if(counts<=reLenght){

for(int k=remain;k

if (cmdChar == 'D') {

byteGetD(buffer, k, billget);

}else if(cmdChar == 'X' || cmdChar == 'x' ){

byteGetX(buffer, k, billget);

}else if(cmdChar == 'd'){

byteGetDd(buffer, k, billget);

}else if(cmdChar == 'e'){

byteGetE(buffer, k, billget);

}else {

byteGetOther(buffer, k, billget);

}

}

}else{

for(int k=remain;k

if (cmdChar == 'D') {

byteGetD(buffer, k, billget);

}else if(cmdChar == 'X' || cmdChar == 'x' ){

byteGetX(buffer, k, billget);

}else if(cmdChar == 'd'){

byteGetDd(buffer, k, billget);

}else if(cmdChar == 'e'){

byteGetE(buffer, k, billget);

}else {

byteGetOther(buffer, k, billget);

}

}

int resize=counts-reLenght;

int rem=resize%go;

int size=resize/go;

if(size!=0){

for(int j=tosize+1;j

billget= ls.get(j);

for(int k=0;k

if (cmdChar == 'D') {

byteGetD(buffer, k, billget);

}else if(cmdChar == 'X' || cmdChar == 'x' ){

byteGetX(buffer, k, billget);

}else if(cmdChar == 'd'){

byteGetDd(buffer, k, billget);

}else if(cmdChar == 'e'){

byteGetE(buffer, k, billget);

}else {

byteGetOther(buffer, k, billget);

}

}

}

}

if(rem!=0){

billget= ls.get(size+tosize+1);

for(int k=0;k

if (cmdChar == 'D') {

byteGetD(buffer, k, billget);

}else if(cmdChar == 'X' || cmdChar == 'x' ){

byteGetX(buffer, k, billget);

}else if(cmdChar == 'd'){

byteGetDd(buffer, k, billget);

}else if(cmdChar == 'e'){

byteGetE(buffer, k, billget);

}else {

byteGetOther(buffer, k, billget);

}

}

}

}

}

Config.log.writeLog(4, cmdChar+":传送系号--位置:%d--%d", lastId, startindex + counts);

return buffer.array();

}

public void byteGetD(ByteBuffer buffer, int k, byte[] billget) {

buffer.put(Arrays.copyOfRange(billget, k*to, k*to+6));

buffer.put(Arrays.copyOfRange(billget, k*to+6, k*to+16));

buffer.put(Arrays.copyOfRange(billget, k*to+16, k*to+17));

buffer.put(Arrays.copyOfRange(billget, k*to+17, k*to+27));

}

public void byteGetX(ByteBuffer buffer, int k, byte[] billget) {

buffer.put(Arrays.copyOfRange(billget, k*to, k*to+6));

buffer.put(Arrays.copyOfRange(billget, k*to+6, k*to+16));

buffer.put(Arrays.copyOfRange(billget, k*to+16, k*to+17));

buffer.put(Arrays.copyOfRange(billget, k*to+17, k*to+27));

buffer.put(Arrays.copyOfRange(billget, k*to+27, k*to+37));

}

public void byteGetDd(ByteBuffer buffer, int k, byte[] billget) {

buffer.put(Arrays.copyOfRange(billget, k*to, k*to+6));

buffer.put(Arrays.copyOfRange(billget, k*to+6, k*to+16));

buffer.put(Arrays.copyOfRange(billget, k*to+16, k*to+17));

buffer.put(Arrays.copyOfRange(billget, k*to+17, k*to+27));

buffer.put(Arrays.copyOfRange(billget, k*to+27, k*to+37));

buffer.put(Arrays.copyOfRange(billget, k*to+37, k*to+47));

buffer.put(Arrays.copyOfRange(billget, k*to+47, k*to+57));

}

public void byteGetE(ByteBuffer buffer, int k, byte[] billget) {

buffer.put(Arrays.copyOfRange(billget, k*to, k*to+6));

buffer.put(Arrays.copyOfRange(billget, k*to+6, k*to+16));

buffer.put(Arrays.copyOfRange(billget, k*to+16, k*to+17));

buffer.put(Arrays.copyOfRange(billget, k*to+17, k*to+27));

buffer.put(Arrays.copyOfRange(billget, k*to+27, k*to+37));

buffer.put(Arrays.copyOfRange(billget, k*to+37, k*to+47));

buffer.put(Arrays.copyOfRange(billget, k*to+47, k*to+57));

buffer.put(Arrays.copyOfRange(billget, k*to+57, k*to+62));

buffer.put(Arrays.copyOfRange(billget, k*to+62, k*to+72));

}

public void byteGetOther(ByteBuffer buffer, int k, byte[] billget) {

buffer.put(Arrays.copyOfRange(billget, k*to, k*to+6));

buffer.put(Arrays.copyOfRange(billget, k*to+6, k*to+11));

buffer.put(Arrays.copyOfRange(billget, k*to+16, k*to+17));

buffer.put(Arrays.copyOfRange(billget, k*to+17, k*to+22));

}

public void reloadData() {

try {

reloadFlg = true ;

} catch (Exception e) {

Config.log.writeLog(3, "进港重新加载缓存失败:%s", e + " " + e.getMessage());

}

}

}

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:81
帖子:4969
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP