You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We store some metadata for the stream contents (like hashes), and we wanted to
determine the encoding with it as well. I have therefore wrapped the
UniversalDetector inside a stream to be able to do several actions in one step
using nested streams.
Maybe it is useful to others:
public class EncodingDetectorInputStream extends BufferedInputStream {
private final UniversalDetector detector = new UniversalDetector(null);
public EncodingDetectorInputStream(InputStream in) {
super(in);
}
public String getDetectedCharset() {
return detector.getDetectedCharset();
}
@Override
public synchronized int read(byte[] b, int off, int len) throws IOException {
final int nrOfBytesRead = super.read(b, off, len);
if (!detector.isDone() && nrOfBytesRead > 0) {
detector.handleData(b, 0, nrOfBytesRead);
}
if (nrOfBytesRead == -1) {
detector.dataEnd();
}
return nrOfBytesRead;
}
}
Original issue reported on code.google.com by [email protected] on 23 Jul 2013 at 3:32
The text was updated successfully, but these errors were encountered:
Original issue reported on code.google.com by
[email protected]
on 23 Jul 2013 at 3:32The text was updated successfully, but these errors were encountered: