HER-1737 excessive job.log WARNINGs for misreported encoding (FLV reported as text/html;charset=UTF-8

* ReplayCharSequence.java
    new interface method: getDecoderExceptionCount(), reporting >0 if any decoding problems were encountered and silently replaced
* GenericReplayCharSequence.java
    count decoding problems, and only log as FINE rather than WARNING
* InMemoryReplayCharSequence.java
    try decoding with reporting; if any problems note at least one then decode without reporting errors
* ExtractorHTML.java
    after using ReplayCharSequence, log WARNING if nonzero decoding errors
This commit is contained in:
gojomo committed 2010-04-23 04:11:53 +00:00
1 parent 67bf73026f
commit a7caceb8ad
4 files changed
+51 -2

No files matched your search

@@ -92,6 +92,9 @@ public class GenericReplayCharSequence implements ReplayCharSequence {
*/
protected int length;
/** counter of decoding exceptions for report at end */
protected long decodingExceptions = 0;
/**
* Byte offset into the file where the memory mapped portion begins.
*/
@@ -316,7 +319,8 @@ public class GenericReplayCharSequence implements ReplayCharSequence {
CharBuffer cbuf = decoder.decode(tempBuf);
return cbuf.get();
} catch (CharacterCodingException e) {
logger.warning("unable to get character at index=" + index + " (fileIndex=" + fileIndex + "): " + e);
logger.log(Level.FINE,"unable to get character at index=" + index + " (fileIndex=" + fileIndex + "): " + e, e);
decodingExceptions++;
// U+FFFD REPLACEMENT CHARACTER --
// "used to replace an incoming character whose value is unknown or unrepresentable in Unicode"
return (char) 0xfffd;
@@ -392,4 +396,12 @@ public class GenericReplayCharSequence implements ReplayCharSequence {
public int length() {
return length;
}
/* (non-Javadoc)
* @see org.archive.io.ReplayCharSequence#getDecodeExceptionCount()
*/
@Override
public long getDecodeExceptionCount() {
return decodingExceptions;
}
}
@@ -22,7 +22,9 @@ package org.archive.io;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CodingErrorAction;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -38,6 +40,8 @@ public class InMemoryReplayCharSequence implements ReplayCharSequence {
*/
private CharBuffer charBuffer = null;
protected long decodingExceptionsCount = 0;
/**
* Constructor for all in-memory operation.
*
@@ -93,7 +97,15 @@ public class InMemoryReplayCharSequence implements ReplayCharSequence {
// TODO: better detection or default
charset = Charset.forName(FALLBACK_CHARSET_NAME);
}
return charset.decode(bb).asReadOnlyBuffer();
try {
return charset.newDecoder()
.onMalformedInput(CodingErrorAction.REPORT)
.onUnmappableCharacter(CodingErrorAction.REPORT)
.decode(bb).asReadOnlyBuffer();
} catch (CharacterCodingException cce) {
decodingExceptionsCount++;
return charset.decode(bb).asReadOnlyBuffer();
}
}
public void close() {
@@ -123,4 +135,14 @@ public class InMemoryReplayCharSequence implements ReplayCharSequence {
sb.append(this);
return sb.toString();
}
/**
* Return 1 if there were decoding problems (a full count isn't possible).
*
* @see org.archive.io.ReplayCharSequence#getDecodeExceptionCount()
*/
@Override
public long getDecodeExceptionCount() {
return decodingExceptionsCount;
}
}
@@ -46,4 +46,12 @@ public interface ReplayCharSequence extends CharSequence, Closeable {
* @throws IOException Problem cleaning up file system resources.
*/
public void close() throws IOException;
/**
* Report count of decoder errors silently eaten during ReplayCharSequence
* use. May be less than the number of individual decoding anomalies in
* underlying content (if decoding method doesn't allow counting individual
* errors).
*/
public long getDecodeExceptionCount();
}