remove jchardet library

This commit is contained in:
wyq 2021-08-12 09:27:59 +08:00
parent 65a075e014
commit 3740913d98
20 changed files with 17 additions and 217 deletions

View File

@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="Maven: org.mozilla.intl:chardet:1.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/mozilla/intl/chardet/1.0/chardet-1.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/mozilla/intl/chardet/1.0/chardet-1.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/mozilla/intl/chardet/1.0/chardet-1.0-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -85,7 +85,6 @@
<orderEntry type="library" name="Maven: org.checkerframework:checker-qual:3.8.0" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.5.1" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
<orderEntry type="library" name="Maven: org.mozilla.intl:chardet:1.0" level="project" />
<orderEntry type="library" name="Maven: com.toedter:jcalendar:1.4" level="project" />
<orderEntry type="library" name="Maven: org.meteothink:wContour:1.7.1" level="project" />
<orderEntry type="library" name="Maven: org.scilab.forge:jlatexmath:1.0.7" level="project" />

View File

@ -18,6 +18,5 @@
<orderEntry type="library" name="Maven: org.checkerframework:checker-qual:3.8.0" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.5.1" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
<orderEntry type="library" name="Maven: org.mozilla.intl:chardet:1.0" level="project" />
</component>
</module>

View File

@ -11,25 +11,12 @@
<artifactId>meteoinfo-common</artifactId>
<repositories>
<repository>
<id>ebi</id>
<name>ebiRepo</name>
<url>http://www.ebi.ac.uk/intact/maven/nexus/content/repositories/ebi-repo/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>30.1.1-jre</version>
</dependency>
<dependency>
<groupId>org.mozilla.intl</groupId>
<artifactId>chardet</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<properties>

View File

@ -1,144 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.common.io;
//Use jchardet get file encoding -javacode
//Error with Chinese characters using ANSI encoding
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.mozilla.intl.chardet.nsDetector;
import org.mozilla.intl.chardet.nsICharsetDetectionObserver;
/**
* Using JCharDet get file charset
*
* @author icer PS: JCharDet
* http://jchardet.sourceforge.net/
*/
public class FileCharsetDetector {
private boolean found = false;
private String encoding = null;
/**
* Check file encoding
*
* @param file File object
* @return Encoding string
* @throws FileNotFoundException
* @throws IOException
*/
public String guestFileEncoding(File file) throws FileNotFoundException,
IOException {
return guestFileEncoding(file, new nsDetector());
}
/**
* Check file encoding
*
* @param file File object
* @param languageHint Language comment code, eg: 1 : Japanese; 2 : Chinese; 3 : Simplified
* Chinese; 4 : Traditional Chinese; 5 : Korean; 6 : Dont know (default)
* @return File encoding, eg: UTF-8,GBK,GB2312
* @throws FileNotFoundException
* @throws IOException
*/
public String guestFileEncoding(File file, int languageHint)
throws FileNotFoundException, IOException {
return guestFileEncoding(file, new nsDetector(languageHint));
}
/**
* Check file encoding
*
* @param path File path
* @return File encoding
* @throws FileNotFoundException
* @throws IOException
*/
public String guestFileEncoding(String path) throws FileNotFoundException,
IOException {
return guestFileEncoding(new File(path));
}
/**
* Get file encoding
*
* @param path File path
* @param languageHint Language comment code, eg: 1 : Japanese; 2 : Chinese; 3 : Simplified
* Chinese; 4 : Traditional Chinese; 5 : Korean; 6 : Dont know (default)
* @return
* @throws FileNotFoundException
* @throws IOException
*/
public String guestFileEncoding(String path, int languageHint)
throws FileNotFoundException, IOException {
return guestFileEncoding(new File(path), languageHint);
}
/**
* Get file encoding
*
* @param file File object
* @param det Detector
* @return File encoding
* @throws FileNotFoundException
* @throws IOException
*/
private String guestFileEncoding(File file, nsDetector det)
throws FileNotFoundException, IOException {
// Set an observer...
// The Notify() will be called when a matching charset is found.
det.Init(new nsICharsetDetectionObserver() {
@Override
public void Notify(String charset) {
found = true;
encoding = charset;
}
});
BufferedInputStream imp = new BufferedInputStream(new FileInputStream(
file));
byte[] buf = new byte[1024];
int len;
boolean done = false;
boolean isAscii = true;
while ((len = imp.read(buf, 0, buf.length)) != -1) {
// Check if the stream is only ascii.
if (isAscii) {
isAscii = det.isAscii(buf, len);
}
// DoIt if non-ascii and not done yet.
if (!isAscii && !done) {
done = det.DoIt(buf, len, false);
}
}
det.DataEnd();
if (isAscii) {
encoding = "ASCII";
found = true;
}
if (!found) {
String prob[] = det.getProbableCharsets();
if (prob.length > 0) {
// use file guess encoding when no encoding found
encoding = prob[0];
} else {
return null;
}
}
return encoding;
}
}

View File

@ -5,8 +5,6 @@
*/
package org.meteoinfo.common.io;
import org.meteoinfo.common.io.FileCharsetDetector;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
@ -54,19 +52,6 @@ public class IOUtil {
}
/**
* Guess file encoding
*
* @param filePath The file path
* @return Guessed encoding
* @throws IOException
*/
public static String guessFileEncoding(String filePath) throws IOException {
FileCharsetDetector fcd = new FileCharsetDetector();
String encoding = fcd.guestFileEncoding(filePath);
return encoding;
}
/**
* Detect file encoding
* @param filePath The file path

View File

@ -21,7 +21,6 @@
<orderEntry type="library" name="Maven: org.checkerframework:checker-qual:3.8.0" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.5.1" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
<orderEntry type="library" name="Maven: org.mozilla.intl:chardet:1.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-math3:3.6.1" level="project" />
<orderEntry type="library" name="Maven: jakarta.annotation:jakarta.annotation-api:2.0.0" level="project" />
<orderEntry type="module" module-name="meteoinfo-projection" />

View File

@ -23,12 +23,7 @@ import org.meteoinfo.data.meteodata.StationInfoData;
import org.meteoinfo.data.meteodata.StationModelData;
import org.meteoinfo.data.meteodata.Variable;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -36,9 +31,10 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import org.meteoinfo.data.meteodata.MeteoDataType;
import org.meteoinfo.common.io.FileCharsetDetector;
//import org.meteoinfo.common.io.FileCharsetDetector;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.data.meteodata.Attribute;
import org.mozilla.universalchardet.UniversalDetector;
/**
*
@ -71,9 +67,8 @@ import org.meteoinfo.data.meteodata.Attribute;
BufferedReader sr = null;
try {
this.setFileName(fileName);
FileCharsetDetector chardet = new FileCharsetDetector();
String charset = chardet.guestFileEncoding(this.getFileName());
sr = new BufferedReader(new InputStreamReader(new FileInputStream(fileName), charset));
String encoding = UniversalDetector.detectCharset(new File(fileName));
sr = new BufferedReader(new InputStreamReader(new FileInputStream(fileName), encoding));
String[] dataArray, fieldArray;
String aLine = sr.readLine().trim(); //Title
delimiter = GlobalUtil.getDelimiter(aLine);
@ -161,9 +156,8 @@ import org.meteoinfo.data.meteodata.Attribute;
public StationData getStationData(int timeIdx, String varName, int levelIdx) {
try {
List<String[]> dataList = new ArrayList<>();
FileCharsetDetector chardet = new FileCharsetDetector();
String charset = chardet.guestFileEncoding(this.getFileName());
BufferedReader sr = new BufferedReader(new InputStreamReader(new FileInputStream(this.getFileName()), charset));
String encoding = UniversalDetector.detectCharset(new File(fileName));
BufferedReader sr = new BufferedReader(new InputStreamReader(new FileInputStream(this.getFileName()), encoding));
sr.readLine();
String line = sr.readLine();
while (line != null) {
@ -254,9 +248,8 @@ import org.meteoinfo.data.meteodata.Attribute;
public StationInfoData getStationInfoData(int timeIdx, int levelIdx) {
BufferedReader sr = null;
try {
FileCharsetDetector chardet = new FileCharsetDetector();
String charset = chardet.guestFileEncoding(this.getFileName());
sr = new BufferedReader(new InputStreamReader(new FileInputStream(this.getFileName()), charset));
String encoding = UniversalDetector.detectCharset(new File(fileName));
sr = new BufferedReader(new InputStreamReader(new FileInputStream(this.getFileName()), encoding));
List<List<String>> dataList = new ArrayList<>();
sr.readLine();
String line = sr.readLine();

View File

@ -20,7 +20,6 @@
<orderEntry type="library" name="Maven: org.checkerframework:checker-qual:3.8.0" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.5.1" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
<orderEntry type="library" name="Maven: org.mozilla.intl:chardet:1.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-math3:3.6.1" level="project" />
<orderEntry type="library" name="Maven: jakarta.annotation:jakarta.annotation-api:2.0.0" level="project" />
<orderEntry type="library" name="Maven: com.github.albfernandez:juniversalchardet:2.4.0" level="project" />

View File

@ -23,7 +23,6 @@
<orderEntry type="library" name="Maven: org.checkerframework:checker-qual:3.8.0" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.5.1" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
<orderEntry type="library" name="Maven: org.mozilla.intl:chardet:1.0" level="project" />
<orderEntry type="library" name="Maven: org.ejml:ejml-experimental:0.40" level="project" />
<orderEntry type="library" name="Maven: org.ejml:ejml-core:0.40" level="project" />
<orderEntry type="library" name="Maven: org.ejml:ejml-ddense:0.40" level="project" />

View File

@ -19,7 +19,6 @@
<orderEntry type="library" name="Maven: org.checkerframework:checker-qual:3.8.0" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.5.1" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
<orderEntry type="library" name="Maven: org.mozilla.intl:chardet:1.0" level="project" />
<orderEntry type="module" module-name="meteoinfo-ndarray" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-math3:3.6.1" level="project" />
<orderEntry type="library" name="Maven: jakarta.annotation:jakarta.annotation-api:2.0.0" level="project" />

View File

@ -23,7 +23,6 @@
<orderEntry type="library" name="Maven: org.checkerframework:checker-qual:3.8.0" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.5.1" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
<orderEntry type="library" name="Maven: org.mozilla.intl:chardet:1.0" level="project" />
<orderEntry type="library" name="Maven: org.ejml:ejml-experimental:0.40" level="project" />
<orderEntry type="library" name="Maven: org.ejml:ejml-core:0.40" level="project" />
<orderEntry type="library" name="Maven: org.ejml:ejml-ddense:0.40" level="project" />

View File

@ -95,7 +95,6 @@
<orderEntry type="library" name="Maven: org.checkerframework:checker-qual:3.8.0" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.5.1" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
<orderEntry type="library" name="Maven: org.mozilla.intl:chardet:1.0" level="project" />
<orderEntry type="library" name="Maven: com.toedter:jcalendar:1.4" level="project" />
<orderEntry type="library" name="Maven: org.meteothink:wContour:1.7.1" level="project" />
<orderEntry type="library" name="Maven: org.scilab.forge:jlatexmath:1.0.7" level="project" />

View File

@ -1,15 +1,21 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MeteoInfo File="milconfig.xml" Type="configurefile">
<Path OpenPath="D:\Working\MIScript\Jython\mis\test">
<Path OpenPath="D:\Working\MIScript\Jython\mis\map">
<RecentFolder Folder="D:\MyProgram\java\MeteoInfoDev\MeteoInfo"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\test"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map"/>
</Path>
<File>
<OpenedFiles>
<OpenedFile File="D:\Working\MIScript\Jython\mis\test\sx_3d_rh_slice.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\map\add_layer_field.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\map\add_circle.py"/>
</OpenedFiles>
<RecentFiles>
<RecentFile File="D:\Working\MIScript\Jython\mis\test\sx_3d_rh_slice.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\map\add_layer_field.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\map\add_circle.py"/>
</RecentFiles>
</File>
<Font>
@ -17,5 +23,5 @@
</Font>
<LookFeel DockWindowDecorated="true" LafDecorated="true" Name="FlatDarkLaf"/>
<Figure DoubleBuffering="true"/>
<Startup MainFormLocation="-4,2" MainFormSize="1326,786"/>
<Startup MainFormLocation="-7,0" MainFormSize="1390,790"/>
</MeteoInfo>

View File

@ -86,7 +86,6 @@
<orderEntry type="library" name="Maven: org.checkerframework:checker-qual:3.8.0" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.5.1" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
<orderEntry type="library" name="Maven: org.mozilla.intl:chardet:1.0" level="project" />
<orderEntry type="library" name="Maven: com.toedter:jcalendar:1.4" level="project" />
<orderEntry type="library" name="Maven: org.meteothink:wContour:1.7.1" level="project" />
<orderEntry type="library" name="Maven: org.scilab.forge:jlatexmath:1.0.7" level="project" />

View File

@ -22,7 +22,6 @@
<orderEntry type="library" name="Maven: org.checkerframework:checker-qual:3.8.0" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.5.1" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
<orderEntry type="library" name="Maven: org.mozilla.intl:chardet:1.0" level="project" />
<orderEntry type="library" name="Maven: org.ejml:ejml-experimental:0.40" level="project" />
<orderEntry type="library" name="Maven: org.ejml:ejml-core:0.40" level="project" />
<orderEntry type="library" name="Maven: org.ejml:ejml-ddense:0.40" level="project" />

View File

@ -19,7 +19,6 @@
<orderEntry type="library" name="Maven: org.checkerframework:checker-qual:3.8.0" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.5.1" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
<orderEntry type="library" name="Maven: org.mozilla.intl:chardet:1.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-math3:3.6.1" level="project" />
<orderEntry type="library" name="Maven: jakarta.annotation:jakarta.annotation-api:2.0.0" level="project" />
</component>

View File

@ -20,7 +20,6 @@
<orderEntry type="library" name="Maven: org.checkerframework:checker-qual:3.8.0" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.5.1" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
<orderEntry type="library" name="Maven: org.mozilla.intl:chardet:1.0" level="project" />
<orderEntry type="module" module-name="meteoinfo-ndarray" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-math3:3.6.1" level="project" />
<orderEntry type="library" name="Maven: jakarta.annotation:jakarta.annotation-api:2.0.0" level="project" />

View File

@ -20,7 +20,6 @@
<orderEntry type="library" name="Maven: org.checkerframework:checker-qual:3.8.0" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.5.1" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
<orderEntry type="library" name="Maven: org.mozilla.intl:chardet:1.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-math3:3.6.1" level="project" />
<orderEntry type="library" name="Maven: jakarta.annotation:jakarta.annotation-api:2.0.0" level="project" />
</component>

View File

@ -19,7 +19,6 @@
<orderEntry type="library" name="Maven: org.checkerframework:checker-qual:3.8.0" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.5.1" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
<orderEntry type="library" name="Maven: org.mozilla.intl:chardet:1.0" level="project" />
<orderEntry type="library" name="Maven: com.toedter:jcalendar:1.4" level="project" />
</component>
</module>