sfdsf

karte 2011-04-02 01:13:21
package com.gmcc.boss.common.base;
import java.io.UnsupportedEncodingException;
import java.util.*;
import java.util.zip.*;
import com.gmcc.boss.common.base.CPEntity;
import com.gmcc.boss.common.base.CPDateTime;
import com.gmcc.boss.waf.service.resource.OurResources;
public class CObArchive extends CPObject {
private final static OurResources RESOURCES = OurResources.getOurResources(CObArchive.class);
public static int isCompressed = 1;
public static boolean GBK2UNICODE = false;
public static boolean UNICODE2GBK = false;
public static boolean IS_CONVERT_ENCODING = false;
public static String SEND_ENCODING = "UTF-8";
public static String RECV_ENCODING = "GBK";
static final int MAX_ARCHIVE_SZIE = 1024 * 1024 * 4;
static final int MAX_ALLOC_STEP = 1024 * 1024;
private static final byte BEGIN_JUSTIFY_FLAG = '<';
private static final byte END_JUSTIFY_FLAG = '>';
private Stack m_stkClassName = new Stack();
private byte[] m_strBuf = new byte[0];
private int m_dataLen = 0;
private byte[] m_rtnBuf = new byte[0];
private int m_outLen = 0;
private boolean bHaveReturned = false;
private int curpos = 0;
private int ALLOCSTEP = 1024 * 16;
private int DEFAULT_THRESHOLD = 30 * 1024;
private static String COMPRESS_FLAG = "COMPRESS";
private static byte[] byteCompressFlag = COMPRESS_FLAG.getBytes();
private static String EMPTY_STRING = "";

public CObArchive()
{
increaseBuf(1024);
m_stkClassName.push("CObArchive");
}

public CObArchive(byte []buf, int len) {
int flagLength = byteCompressFlag.length;
int offset = flagLength+10;
if (COMPRESS_FLAG.equals(new String(buf, 0, flagLength))) {
int ilen = Integer.parseInt((new String(buf, flagLength, 10)).trim());
m_strBuf = new byte[ilen];
m_dataLen = ilen;
Inflater decompresser = new Inflater();
decompresser.setInput(buf, offset, len - offset);
try {
decompresser.inflate(m_strBuf);
decompresser.end();
return;
} catch (DataFormatException dfx) {
throw new EObArchive(RESOURCES.getMessage("CObArchive.java", new Object[]{dfx.getMessage()}));
}
}

m_strBuf = buf;
m_dataLen = len;
m_stkClassName.push("CObArchive");
}

private void memset(byte[] buf, int pos, byte c, int len) {
for (int i = 0; i < len; i++) {
buf[pos + i] = c;
}
}

private void overflowCheck(int next_bytes) {
if (next_bytes < 0) {
throw new EObArchive(RESOURCES.getMessage("CObArchive.javadata", new Object[]{m_stkClassName.peek()}));
}

if ((curpos + next_bytes) > m_dataLen) {
throw new EObArchive(RESOURCES.getMessage("CObArchive.datafail", new Object[]{m_stkClassName.peek()}));
}
}

private void increaseBuf(int size) {
int needSize = curpos + size;
if (needSize <= m_strBuf.length) {
return;
}

if (needSize > MAX_ARCHIVE_SZIE) {
throw new EObArchive(RESOURCES.getMessage("CObArchive.limit", new Object[]{String.valueOf(needSize)}));
}

int new_size = ((needSize + ALLOCSTEP - 1) / ALLOCSTEP)*ALLOCSTEP;
byte []tmp = new byte[new_size];
System.arraycopy(m_strBuf, 0, tmp, 0, curpos);
m_strBuf = tmp;

ALLOCSTEP <<= 1;
if(ALLOCSTEP > MAX_ALLOC_STEP) {
ALLOCSTEP = MAX_ALLOC_STEP;
}
}

private void memcpy(byte[] dest,int destpos,byte[] src,int srcpos, int len) {
System.arraycopy(src,srcpos,dest,destpos,len);

}
...全文
61 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

23,404

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧