本文整理匯總了Java中org.mozilla.universalchardet.UniversalDetector.isDone方法的典型用法代碼示例。如果您正苦於以下問題:Java UniversalDetector.isDone方法的具體用法?Java UniversalDetector.isDone怎麽用?Java UniversalDetector.isDone使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.mozilla.universalchardet.UniversalDetector
的用法示例。
在下文中一共展示了UniversalDetector.isDone方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getFileCharset
import org.mozilla.universalchardet.UniversalDetector; //導入方法依賴的package包/類
public static String getFileCharset(File file) throws IOException {
byte[] buf = new byte[4096];
BufferedInputStream bufferedInputStream = new BufferedInputStream(
new FileInputStream(file));
final UniversalDetector universalDetector = new UniversalDetector(null);
int numberOfBytesRead;
while ((numberOfBytesRead = bufferedInputStream.read(buf)) > 0
&& !universalDetector.isDone()) {
universalDetector.handleData(buf, 0, numberOfBytesRead);
}
universalDetector.dataEnd();
String encoding = universalDetector.getDetectedCharset();
universalDetector.reset();
bufferedInputStream.close();
return encoding;
}
示例2: isBinary
import org.mozilla.universalchardet.UniversalDetector; //導入方法依賴的package包/類
public static boolean isBinary(InputStream in) throws IOException {
byte[] buf = new byte[4];
in.mark(5);
int len = in.read(buf);
in.reset();
UniversalDetector detector = new UniversalDetector(null);
detector.handleData(buf, 0, len);
if (detector.isDone()) {
return false;
}
//Not UTF check ASCII text
in.mark(LOOKAHEAD);
len = 0;
int b;
while ((b = in.read()) != -1 && len < (LOOKAHEAD - 192)) {
len++;
if (b == 0) {
in.reset();
return true;
}
}
in.reset();
return false;
}
示例3: detectCharset
import org.mozilla.universalchardet.UniversalDetector; //導入方法依賴的package包/類
public static String detectCharset(InputStream fis) throws IOException {
byte[] buf = new byte[4096];
// (1)
UniversalDetector detector = new UniversalDetector(null);
// (2)
int nread;
while ((nread = fis.read(buf)) > 0 && !detector.isDone()) {
detector.handleData(buf, 0, nread);
}
// (3)
detector.dataEnd();
// (4)
String encoding = detector.getDetectedCharset();
// (5)
detector.reset();
return encoding;
}
示例4: detectEncoding
import org.mozilla.universalchardet.UniversalDetector; //導入方法依賴的package包/類
/**
* Detect the encoding of the supplied file.
*
* @see <a href="https://code.google.com/p/juniversalchardet/">Original</a>
* @see <a href="https://github.com/amake/juniversalchardet">Fork</a>
*/
public static String detectEncoding(InputStream stream) throws IOException {
UniversalDetector detector = new UniversalDetector(null);
byte[] buffer = new byte[4096];
int read;
while ((read = stream.read(buffer)) > 0 && !detector.isDone()) {
detector.handleData(buffer, 0, read);
}
detector.dataEnd();
String encoding = detector.getDetectedCharset();
detector.reset();
return encoding;
}
示例5: detect
import org.mozilla.universalchardet.UniversalDetector; //導入方法依賴的package包/類
public static String detect(InputStream inputStream) throws IOException {
UniversalDetector detector = Charset.getSingleton()
.getCharsetDetector();
byte[] buf = new byte[4096];
int nread;
while ((nread = inputStream.read(buf)) > 0 && !detector.isDone()) {
detector.handleData(buf, 0, nread);
}
detector.dataEnd();
String encoding = detector.getDetectedCharset();
detector.reset();
inputStream.close();
if (encoding == null) {
// If none encoding is detected, we assume UTF-8
encoding = UTF8;
}
return encoding;
}
示例6: detectFileCharset
import org.mozilla.universalchardet.UniversalDetector; //導入方法依賴的package包/類
/**
* 探測文本編碼.
*/
public static String detectFileCharset(File file, int detectLength) throws IOException {
String charset = null;
FileInputStream fis = null;
try {
byte[] buf = new byte[detectLength];
fis = new FileInputStream(file);
UniversalDetector detector = new UniversalDetector(null);
int nread;
while ((nread = fis.read(buf)) > 0 && !detector.isDone()) {
detector.handleData(buf, 0, nread);
}
detector.dataEnd();
charset = detector.getDetectedCharset();
detector.reset();
} finally {
if (fis != null) {
fis.close();
}
}
return charset;
}
示例7: guessCharset
import org.mozilla.universalchardet.UniversalDetector; //導入方法依賴的package包/類
public static String guessCharset(String fileName) throws IOException{
byte[] buf = new byte[4096];
java.io.FileInputStream fis = new java.io.FileInputStream(fileName);
UniversalDetector detector = new UniversalDetector(null);
int nread;
while ((nread = fis.read(buf)) > 0 && !detector.isDone()) {
detector.handleData(buf, 0, nread);
}
detector.dataEnd();
String encoding = detector.getDetectedCharset();
if (encoding != null) {
Log.d("ConvertUtil",fileName+" detected encoding = " + encoding);
} else {
Log.d("ConvertUtil","No encoding detected = " + encoding);
}
detector.reset();
return encoding;
}
示例8: extractCharset
import org.mozilla.universalchardet.UniversalDetector; //導入方法依賴的package包/類
/**
* This method extracts the charset from the html source code.
* If the charset is not specified, it is set to UTF-8 by default
* @param is
* @return
*/
public static String extractCharset(InputStream is) throws java.io.IOException {
byte[] buf = new byte[4096];
UniversalDetector detector = new UniversalDetector(null);
int nread;
while ((nread = is.read(buf)) > 0 && !detector.isDone()) {
detector.handleData(buf, 0, nread);
}
detector.dataEnd();
String encoding = detector.getDetectedCharset();
if (encoding != null) {
LOGGER.debug("Detected encoding = " + encoding);
} else {
LOGGER.debug("No encoding detected.");
}
detector.reset();
if (encoding != null && CrawlUtils.isValidCharset(encoding)) {
return encoding;
} else {
return DEFAULT_CHARSET;
}
}
示例9: detect
import org.mozilla.universalchardet.UniversalDetector; //導入方法依賴的package包/類
public static Charset detect(File file) {
FileInputStream fis = null;
UniversalDetector detector = new UniversalDetector(null);
try {
byte[] buf = new byte[BUFFER_SIZE];
fis = new FileInputStream(file);
int nread;
while ((nread = fis.read(buf)) > 0 && !detector.isDone()) {
detector.handleData(buf, 0, nread);
}
detector.dataEnd();
return Charset.forName(detector.getDetectedCharset());
} catch (Exception e) {
return Charset.defaultCharset();
} finally {
Closeables.closeQuitely(fis);
}
}
示例10: detectEncoding
import org.mozilla.universalchardet.UniversalDetector; //導入方法依賴的package包/類
private static String detectEncoding(File file) throws IOException {
byte[] buf = new byte[4096];
FileInputStream fis = new FileInputStream(file);
UniversalDetector detector = new UniversalDetector(null);
int nread;
while ((nread = fis.read(buf)) > 0 && !detector.isDone()) detector.handleData(buf, 0, nread);
Util.closeStream(fis);
detector.dataEnd();
String encoding = detector.getDetectedCharset();
if (encoding == null) encoding = DEFAULT_ENCODING;
return encoding;
}
示例11: getInputStreamReader
import org.mozilla.universalchardet.UniversalDetector; //導入方法依賴的package包/類
public static InputStreamReader getInputStreamReader(InputStream is, InputStream is2) throws IOException {
UniversalDetector detector = new UniversalDetector(null);
int nread;
byte[] buf = new byte[1024];
while ((nread = is2.read(buf)) > 0 && !detector.isDone()) {
detector.handleData(buf, 0, nread);
}
detector.dataEnd();
String encoding = detector.getDetectedCharset();
if(encoding!=null)
return new InputStreamReader(is, encoding);
else
return new InputStreamReader(is);
}
示例12: setLyricFile
import org.mozilla.universalchardet.UniversalDetector; //導入方法依賴的package包/類
public void setLyricFile(File file) {
if (file == null || !file.exists()) {
reset();
return;
} else if (file.getPath().equals(mCurrentLyricFilePath)) {
return;
} else {
mCurrentLyricFilePath = file.getPath();
reset();
}
try {
FileInputStream fis = new FileInputStream(file);
byte[] buf = new byte[1024];
UniversalDetector detector = new UniversalDetector(null);
int nread;
while ((nread = fis.read(buf)) > 0 && !detector.isDone()) {
detector.handleData(buf, 0, nread);
}
detector.dataEnd();
String encoding = detector.getDetectedCharset();
if (encoding != null) {
setLyricFile(file, encoding);
} else {
setLyricFile(file, "UTF-8");
}
detector.reset();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
示例13: setLyricFile
import org.mozilla.universalchardet.UniversalDetector; //導入方法依賴的package包/類
public void setLyricFile(File file) {
if (file == null || !file.exists()) {
reset();
mCurrentLyricFilePath = "";
return;
} else if (file.getPath().equals(mCurrentLyricFilePath)) {
return;
} else {
mCurrentLyricFilePath = file.getPath();
reset();
}
try {
FileInputStream fis = new FileInputStream(file);
byte[] buf = new byte[1024];
UniversalDetector detector = new UniversalDetector(null);
int nread;
while ((nread = fis.read(buf)) > 0 && !detector.isDone()) {
detector.handleData(buf, 0, nread);
}
detector.dataEnd();
String encoding = detector.getDetectedCharset();
if (encoding != null) {
setLyricFile(file, encoding);
} else {
setLyricFile(file, "UTF-8");
}
detector.reset();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
示例14: detectCharacterCodingOfFile
import org.mozilla.universalchardet.UniversalDetector; //導入方法依賴的package包/類
public static String detectCharacterCodingOfFile(String fileName) throws java.io.IOException {
byte[] buf = new byte[4096];
java.io.FileInputStream fis = new java.io.FileInputStream(fileName);
// (1)
UniversalDetector detector = new UniversalDetector(null);
// (2)
int nread;
while ((nread = fis.read(buf)) > 0 && !detector.isDone()) {
detector.handleData(buf, 0, nread);
}
// (3)
detector.dataEnd();
// (4)
String encoding = detector.getDetectedCharset();
if (encoding != null) {
// System.out.println("Detected encoding = " + encoding);
} else {
// System.out.println("No encoding detected.");
}
// (5)
detector.reset();
return encoding;
}
示例15: getInputStreamCharset
import org.mozilla.universalchardet.UniversalDetector; //導入方法依賴的package包/類
public static String getInputStreamCharset(InputStream is) throws IOException {
UniversalDetector detector = new UniversalDetector(null);
byte[] buf = new byte[4096];
int nread;
while ((nread = is.read(buf)) > 0 && !detector.isDone()) {
detector.handleData(buf, 0, nread);
}
detector.dataEnd();
return detector.getDetectedCharset();
}