copying noah's work to h3

Fix for [HER-1506] ByteReplayCharSequence ignores specified/non-default character encodings, reported by Jean-No?\195?\171l Rivasseau
* RecordingOutputStream.java
    use ByteReplayCharSequence only for iso8859-1
* ReplayCharSequenceTest.java
    new tests for iso8859-1, windows-1252 and ascii
This commit is contained in:
gojomo committed 2009-05-14 21:19:24 +00:00
1 parent ad33d302ff
commit 9155e5f4f9
2 files changed
+58 -4

No files matched your search

@@ -29,6 +29,7 @@ import it.unimi.dsi.fastutil.io.FastBufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
@@ -515,6 +516,8 @@ public class RecordingOutputStream extends OutputStream {
return getReplayCharSequence(characterEncoding, this.contentBeginMark);
}
private static final String canonicalLatin1 = Charset.forName("iso8859-1").name();
/**
* @param characterEncoding Encoding of recorded stream.
* @return A ReplayCharSequence Will return null if an IOException. Call
@@ -523,11 +526,11 @@ public class RecordingOutputStream extends OutputStream {
*/
public ReplayCharSequence getReplayCharSequence(String characterEncoding,
long startOffset) throws IOException {
if (characterEncoding == null) {
characterEncoding = Charset.defaultCharset().name();
}
// TODO: handled transfer-encoding: chunked content-bodies properly
float maxBytesPerChar = IoUtils.encodingMaxBytesPerChar(characterEncoding);
if(maxBytesPerChar<=1) {
// single
// TODO: take into account single-byte encoding may be non-default
if (canonicalLatin1.equals(Charset.forName(characterEncoding).name())) {
return new Latin1ByteReplayCharSequence(
this.buffer,
this.size,