2024年06月09日 1.0.5 优化参数下发的DBF文件中文乱码问题
parent
31fcd8c8cf
commit
e3ed4be52c
@ -0,0 +1,251 @@
|
|||||||
|
//
|
||||||
|
// Source code recreated from a .class file by IntelliJ IDEA
|
||||||
|
// (powered by FernFlower decompiler)
|
||||||
|
//
|
||||||
|
|
||||||
|
package com.linuxense.javadbf;
|
||||||
|
|
||||||
|
import java.io.DataInput;
|
||||||
|
import java.io.DataOutput;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DBFHeader {
|
||||||
|
public static final byte SIG_DBASE_III = 3;
|
||||||
|
private byte signature = 3;
|
||||||
|
private byte year;
|
||||||
|
private byte month;
|
||||||
|
private byte day;
|
||||||
|
int numberOfRecords;
|
||||||
|
short headerLength;
|
||||||
|
short recordLength;
|
||||||
|
private short reserv1;
|
||||||
|
private byte incompleteTransaction;
|
||||||
|
private byte encryptionFlag;
|
||||||
|
private int freeRecordThread;
|
||||||
|
private int reserv2;
|
||||||
|
private int reserv3;
|
||||||
|
private byte mdxFlag;
|
||||||
|
private byte languageDriver;
|
||||||
|
private short reserv4;
|
||||||
|
DBFField[] fieldArray;
|
||||||
|
DBFField[] userFieldArray;
|
||||||
|
private byte terminator1 = 13;
|
||||||
|
private Charset detectedCharset;
|
||||||
|
private Charset usedCharset;
|
||||||
|
private boolean supportExtendedCharacterFields = true;
|
||||||
|
private static final int DBASE_LEVEL_7 = 4;
|
||||||
|
|
||||||
|
protected DBFHeader() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void read(DataInput dataInput, Charset charset, boolean showDeletedRows) throws IOException {
|
||||||
|
this.signature = dataInput.readByte();
|
||||||
|
this.year = dataInput.readByte();
|
||||||
|
this.month = dataInput.readByte();
|
||||||
|
this.day = dataInput.readByte();
|
||||||
|
this.numberOfRecords = DBFUtils.readLittleEndianInt(dataInput);
|
||||||
|
this.headerLength = DBFUtils.readLittleEndianShort(dataInput);
|
||||||
|
this.recordLength = DBFUtils.readLittleEndianShort(dataInput);
|
||||||
|
this.reserv1 = DBFUtils.readLittleEndianShort(dataInput);
|
||||||
|
this.incompleteTransaction = dataInput.readByte();
|
||||||
|
this.encryptionFlag = dataInput.readByte();
|
||||||
|
this.freeRecordThread = DBFUtils.readLittleEndianInt(dataInput);
|
||||||
|
this.reserv2 = dataInput.readInt();
|
||||||
|
this.reserv3 = dataInput.readInt();
|
||||||
|
this.mdxFlag = dataInput.readByte();
|
||||||
|
this.languageDriver = dataInput.readByte();
|
||||||
|
this.reserv4 = DBFUtils.readLittleEndianShort(dataInput);
|
||||||
|
this.detectedCharset = DBFCharsetHelper.getCharsetByByte(this.languageDriver);
|
||||||
|
int read = 32;
|
||||||
|
if (this.isDB7()) {
|
||||||
|
byte[] languageName = new byte[32];
|
||||||
|
dataInput.readFully(languageName);
|
||||||
|
dataInput.readInt();
|
||||||
|
read += 36;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<DBFField> v_fields = new ArrayList();
|
||||||
|
this.usedCharset = this.detectedCharset;
|
||||||
|
if (charset != null) {
|
||||||
|
this.usedCharset = charset;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.usedCharset == null) {
|
||||||
|
this.usedCharset = DBFStandardCharsets.ISO_8859_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.isDB7()) {
|
||||||
|
while(read <= this.headerLength - 48) {
|
||||||
|
DBFField field = DBFField.createFieldDB7(dataInput, this.usedCharset, this.supportExtendedCharacterFields);
|
||||||
|
if (field == null) {
|
||||||
|
++read;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
v_fields.add(field);
|
||||||
|
read += 48;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for(boolean useFieldFlags = this.supportsFieldFlags(); read <= this.headerLength - 32; read += 32) {
|
||||||
|
DBFField field = DBFField.createField(dataInput, this.usedCharset, useFieldFlags, this.supportExtendedCharacterFields);
|
||||||
|
if (field == null) {
|
||||||
|
++read;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
v_fields.add(field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int skip = this.headerLength - read;
|
||||||
|
DBFUtils.skipDataInput(dataInput, skip);
|
||||||
|
this.fieldArray = (DBFField[])v_fields.toArray(new DBFField[v_fields.size()]);
|
||||||
|
List<DBFField> userFields = new ArrayList();
|
||||||
|
if (showDeletedRows) {
|
||||||
|
DBFField deletedField = new DBFField("deleted", DBFDataType.LOGICAL);
|
||||||
|
userFields.add(deletedField);
|
||||||
|
}
|
||||||
|
|
||||||
|
DBFField[] var16 = this.fieldArray;
|
||||||
|
int var9 = var16.length;
|
||||||
|
|
||||||
|
for(int var10 = 0; var10 < var9; ++var10) {
|
||||||
|
DBFField field1 = var16[var10];
|
||||||
|
if (!field1.isSystem() && field1.getType() != DBFDataType.NULL_FLAGS) {
|
||||||
|
userFields.add(field1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.userFieldArray = (DBFField[])userFields.toArray(new DBFField[userFields.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean supportsFieldFlags() {
|
||||||
|
return this.signature == 2 || this.signature == 48 || this.signature == 49 || this.signature == -11 || this.signature == -5;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getTableHeaderSize() {
|
||||||
|
return this.isDB7() ? 68 : 32;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getFieldDescriptorSize() {
|
||||||
|
return this.isDB7() ? 48 : 32;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isDB7() {
|
||||||
|
return (this.signature & 7) == 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
void write(DataOutput dataOutput) throws IOException {
|
||||||
|
dataOutput.writeByte(this.signature);
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
this.year = (byte)(calendar.get(1) - 1900);
|
||||||
|
this.month = (byte)(calendar.get(2) + 1);
|
||||||
|
this.day = (byte)calendar.get(5);
|
||||||
|
dataOutput.writeByte(this.year);
|
||||||
|
dataOutput.writeByte(this.month);
|
||||||
|
dataOutput.writeByte(this.day);
|
||||||
|
this.numberOfRecords = DBFUtils.littleEndian(this.numberOfRecords);
|
||||||
|
dataOutput.writeInt(this.numberOfRecords);
|
||||||
|
short oldHeaderLength = this.headerLength;
|
||||||
|
short newHeaderLength = this.findHeaderLength();
|
||||||
|
if (oldHeaderLength == 0) {
|
||||||
|
this.headerLength = newHeaderLength;
|
||||||
|
} else if (newHeaderLength > oldHeaderLength) {
|
||||||
|
throw new DBFException("Invalid header length");
|
||||||
|
}
|
||||||
|
|
||||||
|
dataOutput.writeShort(DBFUtils.littleEndian(this.headerLength));
|
||||||
|
this.recordLength = this.sumUpLenghtOfFields();
|
||||||
|
dataOutput.writeShort(DBFUtils.littleEndian(this.recordLength));
|
||||||
|
dataOutput.writeShort(DBFUtils.littleEndian(this.reserv1));
|
||||||
|
dataOutput.writeByte(this.incompleteTransaction);
|
||||||
|
dataOutput.writeByte(this.encryptionFlag);
|
||||||
|
dataOutput.writeInt(DBFUtils.littleEndian(this.freeRecordThread));
|
||||||
|
dataOutput.writeInt(DBFUtils.littleEndian(this.reserv2));
|
||||||
|
dataOutput.writeInt(DBFUtils.littleEndian(this.reserv3));
|
||||||
|
dataOutput.writeByte(this.mdxFlag);
|
||||||
|
//if (this.languageDriver != 0) {
|
||||||
|
// dataOutput.writeByte(this.languageDriver);
|
||||||
|
//} else if (this.getUsedCharset() != null) {
|
||||||
|
// dataOutput.writeByte(DBFCharsetHelper.getDBFCodeForCharset(this.getUsedCharset()));
|
||||||
|
//} else {
|
||||||
|
dataOutput.writeByte(0);
|
||||||
|
//}
|
||||||
|
|
||||||
|
dataOutput.writeShort(DBFUtils.littleEndian(this.reserv4));
|
||||||
|
DBFField[] var5 = this.fieldArray;
|
||||||
|
int var6 = var5.length;
|
||||||
|
|
||||||
|
for(int var7 = 0; var7 < var6; ++var7) {
|
||||||
|
DBFField field = var5[var7];
|
||||||
|
field.write(dataOutput, this.getUsedCharset());
|
||||||
|
}
|
||||||
|
|
||||||
|
dataOutput.writeByte(this.terminator1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private short findHeaderLength() {
|
||||||
|
return (short)(32 + 32 * this.fieldArray.length + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private short sumUpLenghtOfFields() {
|
||||||
|
int sum = 0;
|
||||||
|
DBFField[] var2 = this.fieldArray;
|
||||||
|
int var3 = var2.length;
|
||||||
|
|
||||||
|
for(int var4 = 0; var4 < var3; ++var4) {
|
||||||
|
DBFField field = var2[var4];
|
||||||
|
sum += field.getLength();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (short)(sum + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getYear() {
|
||||||
|
return 1900 + this.year;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMonth() {
|
||||||
|
return this.month;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDay() {
|
||||||
|
return this.day;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getLastModificationDate() {
|
||||||
|
if (this.year != 0 && this.month != 0 && this.day != 0) {
|
||||||
|
try {
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.set(this.year, this.month, this.day, 0, 0, 0);
|
||||||
|
calendar.set(14, 0);
|
||||||
|
return calendar.getTime();
|
||||||
|
} catch (Exception var2) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Charset getDetectedCharset() {
|
||||||
|
return this.detectedCharset;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Charset getUsedCharset() {
|
||||||
|
return this.usedCharset;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setUsedCharset(Charset charset) {
|
||||||
|
this.usedCharset = charset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSupportExtendedCharacterFields(boolean supportExtendedCharacterFields) {
|
||||||
|
this.supportExtendedCharacterFields = supportExtendedCharacterFields;
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
@ -0,0 +1,31 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<!--<html lang="en" class="dark">-->
|
||||||
|
<html lang="en" class="light">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
|
||||||
|
<title></title>
|
||||||
|
<script type="module" crossorigin src="./assets/index.0fd88e87.js"></script>
|
||||||
|
<link rel="stylesheet" href="./assets/index.d94d690a.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app">
|
||||||
|
<div class="loading">
|
||||||
|
<div class="loading-wrap">
|
||||||
|
<div class="loading-dots">
|
||||||
|
<span class="dot dot-spin">
|
||||||
|
<i></i>
|
||||||
|
<i></i>
|
||||||
|
<i></i>
|
||||||
|
<i></i>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="loading-title">
|
||||||
|
正在缓冲...
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 138 KiB |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
@ -0,0 +1,31 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<!--<html lang="en" class="dark">-->
|
||||||
|
<html lang="en" class="light">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
|
||||||
|
<title></title>
|
||||||
|
<script type="module" crossorigin src="./assets/index.0fd88e87.js"></script>
|
||||||
|
<link rel="stylesheet" href="./assets/index.d94d690a.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app">
|
||||||
|
<div class="loading">
|
||||||
|
<div class="loading-wrap">
|
||||||
|
<div class="loading-dots">
|
||||||
|
<span class="dot dot-spin">
|
||||||
|
<i></i>
|
||||||
|
<i></i>
|
||||||
|
<i></i>
|
||||||
|
<i></i>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="loading-title">
|
||||||
|
正在缓冲...
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -1,17 +1,29 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<!--<html lang="en" class="dark">-->
|
||||||
|
<html lang="en" class="light">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8"/>
|
<meta charset="UTF-8"/>
|
||||||
<link rel="icon" href="./public/favicon.ico"/>
|
|
||||||
<link rel="stylesheet" href="./src/util/css/loading.css">
|
<link rel="stylesheet" href="./src/util/css/loading.css">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
|
||||||
<title></title>
|
<title></title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<div id="app">
|
||||||
<div id="app"></div>
|
<div class="loading">
|
||||||
<script type="module" src="/src/main.js">
|
<div class="loading-wrap">
|
||||||
|
<div class="loading-dots">
|
||||||
</script>
|
<span class="dot dot-spin">
|
||||||
|
<i></i>
|
||||||
|
<i></i>
|
||||||
|
<i></i>
|
||||||
|
<i></i>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="loading-title">
|
||||||
|
正在缓冲...
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script type="module" src="/src/main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Loading…
Reference in New Issue