![JAR search and dependency download from the Maven repository](/logo.png)
panda.tool.chardet.CharDetect Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of panda-tool Show documentation
Show all versions of panda-tool Show documentation
Panda Tool contains some commonly used tools and source code generator for Panda Mvc. Can generate Entity/Query/Dao/Action class, Freemarker (HTML) template file.
package panda.tool.chardet;
import java.io.InputStream;
import java.net.URL;
import panda.args.Argument;
import panda.args.Option;
import panda.io.Streams;
import panda.lang.HandledException;
import panda.tool.AbstractCommandTool;
import panda.util.chardet.CharDetects;
import panda.util.chardet.LangHint;
/**
* A class used for detect text encoding
*/
public class CharDetect extends AbstractCommandTool {
/**
* main
* @param args arugments
*/
public static void main(String args[]) {
new CharDetect().execute(args);
}
//---------------------------------------------------------------------------------------
// properties
//---------------------------------------------------------------------------------------
private String url;
private LangHint hint;
/**
* @param url the url to set
*/
@Argument(name="URL", required=true, usage="The URL to detect character encoding")
public void setUrl(String url) {
this.url = url;
}
/**
* @param hint the hint to set
*/
@Option(opt='h', option="hint", arg="HINT", usage="Language hint. (ja | zh | cn | tw | ko)")
public void setHint(String hint) {
this.hint = LangHint.parse(hint);
}
/**
* execute
*/
public void execute() {
InputStream is = null;
try {
is = new URL(url).openStream();
is = Streams.buffer(is);
String charset = CharDetects.detectCharset(is, hint);
System.out.println(charset);
}
catch (Exception e) {
e.printStackTrace();
throw new HandledException(e);
}
finally {
Streams.safeClose(is);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy