package com.Big5ToUTF8;
import java.io.*;
public class Big5Tran {
private static final String tabFile ="bg-gb.tab";
private static byte[] data;
static{
try{
FileInputStream fis =new FileInputStream(tabFile);
int len =fis.available();
data =new byte[len];
fis.read(data);
fis.close();
}catch(Exception ex){
ex.printStackTrace();
System.exit(1);
}
}
/**
*取得BIG5汉字big在data中的偏移
*/
private static int indexOf(int big){
int high =(big>8)&0xff;
int low =big&0xff;
high -= 0xa1;
if(low<=0x7e) low -= 0x40;
else low -= (0xa1 -0x7e -1) +0x40;
return 2*(high*157+low);
}
/**
*将保存在bs数字中的big5编码的字符串数据转换成gb2312编码的数据
*注意:此方法将更改原先存储的数据
*@param bs 需要转换的以big5编码的字符串数据
*@return bs 经过转换的数据,保存在参数中的byte数组中
*/
public static byte[] translateBig5ToGb(byte[] bs){
int index =0;
while(index<bs.length){
int high =bs[index]&0xff;
if(high>=0xa1&&high<=0xfe){
index ++;
if(index>=bs.length) break;
int low =bs[index]&0xff;
if(low<0x40||low>0xfe) continue;
if(low>0x7e&&low<0xa1) continue;
int offset =indexOf((high<<8)|low);
bs[index-1] =data[offset];
bs[index ] =data[offset+1];
index++;
}
else index++;
}
return bs;
}
public static String translateBig5ToGb(String big){
String result =null;
try{
byte[] bs =big.getBytes("big5");
bs =translateBig5ToGb(bs);
result =new String(bs,"gb2312");
}catch(Exception e){
}
return result;
}
}
import java.io.*;
public class Big5Tran {
private static final String tabFile ="bg-gb.tab";
private static byte[] data;
static{
try{
FileInputStream fis =new FileInputStream(tabFile);
int len =fis.available();
data =new byte[len];
fis.read(data);
fis.close();
}catch(Exception ex){
ex.printStackTrace();
System.exit(1);
}
}
/**
*取得BIG5汉字big在data中的偏移
*/
private static int indexOf(int big){
int high =(big>8)&0xff;
int low =big&0xff;
high -= 0xa1;
if(low<=0x7e) low -= 0x40;
else low -= (0xa1 -0x7e -1) +0x40;
return 2*(high*157+low);
}
/**
*将保存在bs数字中的big5编码的字符串数据转换成gb2312编码的数据
*注意:此方法将更改原先存储的数据
*@param bs 需要转换的以big5编码的字符串数据
*@return bs 经过转换的数据,保存在参数中的byte数组中
*/
public static byte[] translateBig5ToGb(byte[] bs){
int index =0;
while(index<bs.length){
int high =bs[index]&0xff;
if(high>=0xa1&&high<=0xfe){
index ++;
if(index>=bs.length) break;
int low =bs[index]&0xff;
if(low<0x40||low>0xfe) continue;
if(low>0x7e&&low<0xa1) continue;
int offset =indexOf((high<<8)|low);
bs[index-1] =data[offset];
bs[index ] =data[offset+1];
index++;
}
else index++;
}
return bs;
}
public static String translateBig5ToGb(String big){
String result =null;
try{
byte[] bs =big.getBytes("big5");
bs =translateBig5ToGb(bs);
result =new String(bs,"gb2312");
}catch(Exception e){
}
return result;
}
}
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“java big5到gb2312的编码转换”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新动态
20240727
20240727
- 【雨果唱片】音乐图书馆系列《绣金匾》1999【WAV整轨+CUE】
- 曜爆甘弦乐团《忆声弦命 滚石40【40首OST 致经典】》[320K/MP3][94.1MB]
- 曜爆甘弦乐团《忆声弦命 滚石40【40首OST 致经典】》[FLAC/分轨][208.1MB]
- 丁当《日与夜,跟自己说晚安》[320K/MP3][98.51MB]
- 何炅.2005-漫游【中唱】【WAV+CUE】
- 何嘉莉.1998-MYDREAMS(EP)【飞图】【WAV+CUE】
- 群星.2019-天坑鷹猎电视剧原声带(EP)【智慧大狗】【FLAC分轨】
- 【雨果唱片】《春江花月夜》2020【WAV+CUE】
- 【正原唱片】女子十二乐坊《发烧国乐精粹-十二乐坊》WAV+CUE
- [黄翠珊]SusanWong-TheBestofSusanWong[WAV+CUE]
- 杜德伟.1995-BEST.LOVE(英)【滚石】【WAV+CUE】
- 杜德伟.1996-BEST.LOVE.2(英)【滚石】【WAV+CUE】
- 陈柏宇.2008-Change【SONY】【FLAC分轨】
- 丁当《日与夜,跟自己说晚安》[FLAC/分轨][285.42MB]
- 早安《Bubble Vision》[320KMP3][36.83MB]