mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Automated Code Change
PiperOrigin-RevId: 658829974
This commit is contained in:
parent
6a7e9132fd
commit
399f48ab42
@ -17,9 +17,9 @@ package androidx.media3.common.util;
|
|||||||
|
|
||||||
import static java.lang.Math.min;
|
import static java.lang.Math.min;
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
|
||||||
import com.google.errorprone.annotations.CheckReturnValue;
|
import com.google.errorprone.annotations.CheckReturnValue;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
/** Wraps a byte array, providing methods that allow it to be read as a bitstream. */
|
/** Wraps a byte array, providing methods that allow it to be read as a bitstream. */
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
@ -285,7 +285,7 @@ public final class ParsableBitArray {
|
|||||||
* @return The string encoded by the bytes in UTF-8.
|
* @return The string encoded by the bytes in UTF-8.
|
||||||
*/
|
*/
|
||||||
public String readBytesAsString(int length) {
|
public String readBytesAsString(int length) {
|
||||||
return readBytesAsString(length, Charsets.UTF_8);
|
return readBytesAsString(length, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,6 +24,7 @@ import com.google.common.primitives.UnsignedBytes;
|
|||||||
import com.google.errorprone.annotations.CheckReturnValue;
|
import com.google.errorprone.annotations.CheckReturnValue;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,7 +39,11 @@ public final class ParsableByteArray {
|
|||||||
private static final char[] LF = {'\n'};
|
private static final char[] LF = {'\n'};
|
||||||
private static final ImmutableSet<Charset> SUPPORTED_CHARSETS_FOR_READLINE =
|
private static final ImmutableSet<Charset> SUPPORTED_CHARSETS_FOR_READLINE =
|
||||||
ImmutableSet.of(
|
ImmutableSet.of(
|
||||||
Charsets.US_ASCII, Charsets.UTF_8, Charsets.UTF_16, Charsets.UTF_16BE, Charsets.UTF_16LE);
|
StandardCharsets.US_ASCII,
|
||||||
|
StandardCharsets.UTF_8,
|
||||||
|
StandardCharsets.UTF_16,
|
||||||
|
StandardCharsets.UTF_16BE,
|
||||||
|
StandardCharsets.UTF_16LE);
|
||||||
|
|
||||||
private byte[] data;
|
private byte[] data;
|
||||||
private int position;
|
private int position;
|
||||||
@ -447,7 +452,7 @@ public final class ParsableByteArray {
|
|||||||
* @return The string encoded by the bytes.
|
* @return The string encoded by the bytes.
|
||||||
*/
|
*/
|
||||||
public String readString(int length) {
|
public String readString(int length) {
|
||||||
return readString(length, Charsets.UTF_8);
|
return readString(length, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -525,7 +530,7 @@ public final class ParsableByteArray {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public String readLine() {
|
public String readLine() {
|
||||||
return readLine(Charsets.UTF_8);
|
return readLine(StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -551,7 +556,7 @@ public final class ParsableByteArray {
|
|||||||
if (bytesLeft() == 0) {
|
if (bytesLeft() == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!charset.equals(Charsets.US_ASCII)) {
|
if (!charset.equals(StandardCharsets.US_ASCII)) {
|
||||||
Charset unused = readUtfCharsetFromBom(); // Skip BOM if present
|
Charset unused = readUtfCharsetFromBom(); // Skip BOM if present
|
||||||
}
|
}
|
||||||
int lineLimit = findNextLineTerminator(charset);
|
int lineLimit = findNextLineTerminator(charset);
|
||||||
@ -644,14 +649,14 @@ public final class ParsableByteArray {
|
|||||||
&& data[position + 1] == (byte) 0xBB
|
&& data[position + 1] == (byte) 0xBB
|
||||||
&& data[position + 2] == (byte) 0xBF) {
|
&& data[position + 2] == (byte) 0xBF) {
|
||||||
position += 3;
|
position += 3;
|
||||||
return Charsets.UTF_8;
|
return StandardCharsets.UTF_8;
|
||||||
} else if (bytesLeft() >= 2) {
|
} else if (bytesLeft() >= 2) {
|
||||||
if (data[position] == (byte) 0xFE && data[position + 1] == (byte) 0xFF) {
|
if (data[position] == (byte) 0xFE && data[position + 1] == (byte) 0xFF) {
|
||||||
position += 2;
|
position += 2;
|
||||||
return Charsets.UTF_16BE;
|
return StandardCharsets.UTF_16BE;
|
||||||
} else if (data[position] == (byte) 0xFF && data[position + 1] == (byte) 0xFE) {
|
} else if (data[position] == (byte) 0xFF && data[position + 1] == (byte) 0xFE) {
|
||||||
position += 2;
|
position += 2;
|
||||||
return Charsets.UTF_16LE;
|
return StandardCharsets.UTF_16LE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -662,24 +667,25 @@ public final class ParsableByteArray {
|
|||||||
*/
|
*/
|
||||||
private int findNextLineTerminator(Charset charset) {
|
private int findNextLineTerminator(Charset charset) {
|
||||||
int stride;
|
int stride;
|
||||||
if (charset.equals(Charsets.UTF_8) || charset.equals(Charsets.US_ASCII)) {
|
if (charset.equals(StandardCharsets.UTF_8) || charset.equals(StandardCharsets.US_ASCII)) {
|
||||||
stride = 1;
|
stride = 1;
|
||||||
} else if (charset.equals(Charsets.UTF_16)
|
} else if (charset.equals(StandardCharsets.UTF_16)
|
||||||
|| charset.equals(Charsets.UTF_16LE)
|
|| charset.equals(StandardCharsets.UTF_16LE)
|
||||||
|| charset.equals(Charsets.UTF_16BE)) {
|
|| charset.equals(StandardCharsets.UTF_16BE)) {
|
||||||
stride = 2;
|
stride = 2;
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Unsupported charset: " + charset);
|
throw new IllegalArgumentException("Unsupported charset: " + charset);
|
||||||
}
|
}
|
||||||
for (int i = position; i < limit - (stride - 1); i += stride) {
|
for (int i = position; i < limit - (stride - 1); i += stride) {
|
||||||
if ((charset.equals(Charsets.UTF_8) || charset.equals(Charsets.US_ASCII))
|
if ((charset.equals(StandardCharsets.UTF_8) || charset.equals(StandardCharsets.US_ASCII))
|
||||||
&& Util.isLinebreak(data[i])) {
|
&& Util.isLinebreak(data[i])) {
|
||||||
return i;
|
return i;
|
||||||
} else if ((charset.equals(Charsets.UTF_16) || charset.equals(Charsets.UTF_16BE))
|
} else if ((charset.equals(StandardCharsets.UTF_16)
|
||||||
|
|| charset.equals(StandardCharsets.UTF_16BE))
|
||||||
&& data[i] == 0x00
|
&& data[i] == 0x00
|
||||||
&& Util.isLinebreak(data[i + 1])) {
|
&& Util.isLinebreak(data[i + 1])) {
|
||||||
return i;
|
return i;
|
||||||
} else if (charset.equals(Charsets.UTF_16LE)
|
} else if (charset.equals(StandardCharsets.UTF_16LE)
|
||||||
&& data[i + 1] == 0x00
|
&& data[i + 1] == 0x00
|
||||||
&& Util.isLinebreak(data[i])) {
|
&& Util.isLinebreak(data[i])) {
|
||||||
return i;
|
return i;
|
||||||
@ -727,14 +733,16 @@ public final class ParsableByteArray {
|
|||||||
private int peekCharacterAndSize(Charset charset) {
|
private int peekCharacterAndSize(Charset charset) {
|
||||||
byte character;
|
byte character;
|
||||||
short characterSize;
|
short characterSize;
|
||||||
if ((charset.equals(Charsets.UTF_8) || charset.equals(Charsets.US_ASCII)) && bytesLeft() >= 1) {
|
if ((charset.equals(StandardCharsets.UTF_8) || charset.equals(StandardCharsets.US_ASCII))
|
||||||
|
&& bytesLeft() >= 1) {
|
||||||
character = (byte) Chars.checkedCast(UnsignedBytes.toInt(data[position]));
|
character = (byte) Chars.checkedCast(UnsignedBytes.toInt(data[position]));
|
||||||
characterSize = 1;
|
characterSize = 1;
|
||||||
} else if ((charset.equals(Charsets.UTF_16) || charset.equals(Charsets.UTF_16BE))
|
} else if ((charset.equals(StandardCharsets.UTF_16)
|
||||||
|
|| charset.equals(StandardCharsets.UTF_16BE))
|
||||||
&& bytesLeft() >= 2) {
|
&& bytesLeft() >= 2) {
|
||||||
character = (byte) Chars.fromBytes(data[position], data[position + 1]);
|
character = (byte) Chars.fromBytes(data[position], data[position + 1]);
|
||||||
characterSize = 2;
|
characterSize = 2;
|
||||||
} else if (charset.equals(Charsets.UTF_16LE) && bytesLeft() >= 2) {
|
} else if (charset.equals(StandardCharsets.UTF_16LE) && bytesLeft() >= 2) {
|
||||||
character = (byte) Chars.fromBytes(data[position + 1], data[position]);
|
character = (byte) Chars.fromBytes(data[position + 1], data[position]);
|
||||||
characterSize = 2;
|
characterSize = 2;
|
||||||
} else {
|
} else {
|
||||||
|
@ -96,7 +96,6 @@ import androidx.media3.common.Player;
|
|||||||
import androidx.media3.common.Player.Commands;
|
import androidx.media3.common.Player.Commands;
|
||||||
import androidx.media3.common.audio.AudioProcessor;
|
import androidx.media3.common.audio.AudioProcessor;
|
||||||
import com.google.common.base.Ascii;
|
import com.google.common.base.Ascii;
|
||||||
import com.google.common.base.Charsets;
|
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import com.google.common.math.DoubleMath;
|
import com.google.common.math.DoubleMath;
|
||||||
import com.google.common.math.LongMath;
|
import com.google.common.math.LongMath;
|
||||||
@ -118,6 +117,7 @@ import java.math.BigDecimal;
|
|||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -1046,7 +1046,7 @@ public final class Util {
|
|||||||
*/
|
*/
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
public static String fromUtf8Bytes(byte[] bytes) {
|
public static String fromUtf8Bytes(byte[] bytes) {
|
||||||
return new String(bytes, Charsets.UTF_8);
|
return new String(bytes, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1059,7 +1059,7 @@ public final class Util {
|
|||||||
*/
|
*/
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
public static String fromUtf8Bytes(byte[] bytes, int offset, int length) {
|
public static String fromUtf8Bytes(byte[] bytes, int offset, int length) {
|
||||||
return new String(bytes, offset, length, Charsets.UTF_8);
|
return new String(bytes, offset, length, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1070,7 +1070,7 @@ public final class Util {
|
|||||||
*/
|
*/
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
public static byte[] getUtf8Bytes(String value) {
|
public static byte[] getUtf8Bytes(String value) {
|
||||||
return value.getBytes(Charsets.UTF_8);
|
return value.getBytes(StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,7 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import static org.junit.Assert.assertThrows;
|
import static org.junit.Assert.assertThrows;
|
||||||
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import com.google.common.base.Charsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
@ -280,7 +280,7 @@ public final class ParsableBitArrayTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readBytesAsStringDefaultsToUtf8() {
|
public void readBytesAsStringDefaultsToUtf8() {
|
||||||
byte[] testData = "a non-åscii strìng".getBytes(Charsets.UTF_8);
|
byte[] testData = "a non-åscii strìng".getBytes(StandardCharsets.UTF_8);
|
||||||
ParsableBitArray testArray = new ParsableBitArray(testData);
|
ParsableBitArray testArray = new ParsableBitArray(testData);
|
||||||
|
|
||||||
testArray.skipBytes(2);
|
testArray.skipBytes(2);
|
||||||
@ -289,18 +289,18 @@ public final class ParsableBitArrayTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readBytesAsStringExplicitCharset() {
|
public void readBytesAsStringExplicitCharset() {
|
||||||
byte[] testData = "a non-åscii strìng".getBytes(Charsets.UTF_16);
|
byte[] testData = "a non-åscii strìng".getBytes(StandardCharsets.UTF_16);
|
||||||
ParsableBitArray testArray = new ParsableBitArray(testData);
|
ParsableBitArray testArray = new ParsableBitArray(testData);
|
||||||
|
|
||||||
testArray.skipBytes(6);
|
testArray.skipBytes(6);
|
||||||
assertThat(testArray.readBytesAsString(testData.length - 6, Charsets.UTF_16))
|
assertThat(testArray.readBytesAsString(testData.length - 6, StandardCharsets.UTF_16))
|
||||||
.isEqualTo("non-åscii strìng");
|
.isEqualTo("non-åscii strìng");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readBytesNotByteAligned() {
|
public void readBytesNotByteAligned() {
|
||||||
String testString = "test string";
|
String testString = "test string";
|
||||||
byte[] testData = testString.getBytes(Charsets.UTF_8);
|
byte[] testData = testString.getBytes(StandardCharsets.UTF_8);
|
||||||
ParsableBitArray testArray = new ParsableBitArray(testData);
|
ParsableBitArray testArray = new ParsableBitArray(testData);
|
||||||
|
|
||||||
testArray.skipBit();
|
testArray.skipBit();
|
||||||
|
@ -22,9 +22,9 @@ import static org.junit.Assert.assertThrows;
|
|||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import com.google.common.base.Charsets;
|
|
||||||
import com.google.common.primitives.Bytes;
|
import com.google.common.primitives.Bytes;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -599,69 +599,69 @@ public final class ParsableByteArrayTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readSingleLineWithoutEndingTrail_ascii() {
|
public void readSingleLineWithoutEndingTrail_ascii() {
|
||||||
byte[] bytes = "foo".getBytes(Charsets.US_ASCII);
|
byte[] bytes = "foo".getBytes(StandardCharsets.US_ASCII);
|
||||||
ParsableByteArray parser = new ParsableByteArray(bytes);
|
ParsableByteArray parser = new ParsableByteArray(bytes);
|
||||||
|
|
||||||
assertThat(parser.readLine(Charsets.US_ASCII)).isEqualTo("foo");
|
assertThat(parser.readLine(StandardCharsets.US_ASCII)).isEqualTo("foo");
|
||||||
assertThat(parser.getPosition()).isEqualTo(3);
|
assertThat(parser.getPosition()).isEqualTo(3);
|
||||||
assertThat(parser.readLine(Charsets.US_ASCII)).isNull();
|
assertThat(parser.readLine(StandardCharsets.US_ASCII)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readSingleLineWithEndingLf_ascii() {
|
public void readSingleLineWithEndingLf_ascii() {
|
||||||
byte[] bytes = "foo\n".getBytes(Charsets.US_ASCII);
|
byte[] bytes = "foo\n".getBytes(StandardCharsets.US_ASCII);
|
||||||
ParsableByteArray parser = new ParsableByteArray(bytes);
|
ParsableByteArray parser = new ParsableByteArray(bytes);
|
||||||
|
|
||||||
assertThat(parser.readLine(Charsets.US_ASCII)).isEqualTo("foo");
|
assertThat(parser.readLine(StandardCharsets.US_ASCII)).isEqualTo("foo");
|
||||||
assertThat(parser.getPosition()).isEqualTo(4);
|
assertThat(parser.getPosition()).isEqualTo(4);
|
||||||
assertThat(parser.readLine(Charsets.US_ASCII)).isNull();
|
assertThat(parser.readLine(StandardCharsets.US_ASCII)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readTwoLinesWithCrFollowedByLf_ascii() {
|
public void readTwoLinesWithCrFollowedByLf_ascii() {
|
||||||
byte[] bytes = "foo\r\nbar".getBytes(Charsets.US_ASCII);
|
byte[] bytes = "foo\r\nbar".getBytes(StandardCharsets.US_ASCII);
|
||||||
ParsableByteArray parser = new ParsableByteArray(bytes);
|
ParsableByteArray parser = new ParsableByteArray(bytes);
|
||||||
|
|
||||||
assertThat(parser.readLine(Charsets.US_ASCII)).isEqualTo("foo");
|
assertThat(parser.readLine(StandardCharsets.US_ASCII)).isEqualTo("foo");
|
||||||
assertThat(parser.getPosition()).isEqualTo(5);
|
assertThat(parser.getPosition()).isEqualTo(5);
|
||||||
assertThat(parser.readLine(Charsets.US_ASCII)).isEqualTo("bar");
|
assertThat(parser.readLine(StandardCharsets.US_ASCII)).isEqualTo("bar");
|
||||||
assertThat(parser.getPosition()).isEqualTo(8);
|
assertThat(parser.getPosition()).isEqualTo(8);
|
||||||
assertThat(parser.readLine(Charsets.US_ASCII)).isNull();
|
assertThat(parser.readLine(StandardCharsets.US_ASCII)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readThreeLinesWithEmptyLine_ascii() {
|
public void readThreeLinesWithEmptyLine_ascii() {
|
||||||
byte[] bytes = "foo\r\n\rbar".getBytes(Charsets.US_ASCII);
|
byte[] bytes = "foo\r\n\rbar".getBytes(StandardCharsets.US_ASCII);
|
||||||
ParsableByteArray parser = new ParsableByteArray(bytes);
|
ParsableByteArray parser = new ParsableByteArray(bytes);
|
||||||
|
|
||||||
assertThat(parser.readLine(Charsets.US_ASCII)).isEqualTo("foo");
|
assertThat(parser.readLine(StandardCharsets.US_ASCII)).isEqualTo("foo");
|
||||||
assertThat(parser.getPosition()).isEqualTo(5);
|
assertThat(parser.getPosition()).isEqualTo(5);
|
||||||
assertThat(parser.readLine(Charsets.US_ASCII)).isEqualTo("");
|
assertThat(parser.readLine(StandardCharsets.US_ASCII)).isEqualTo("");
|
||||||
assertThat(parser.getPosition()).isEqualTo(6);
|
assertThat(parser.getPosition()).isEqualTo(6);
|
||||||
assertThat(parser.readLine(Charsets.US_ASCII)).isEqualTo("bar");
|
assertThat(parser.readLine(StandardCharsets.US_ASCII)).isEqualTo("bar");
|
||||||
assertThat(parser.getPosition()).isEqualTo(9);
|
assertThat(parser.getPosition()).isEqualTo(9);
|
||||||
assertThat(parser.readLine(Charsets.US_ASCII)).isNull();
|
assertThat(parser.readLine(StandardCharsets.US_ASCII)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readFourLinesWithLfFollowedByCr_ascii() {
|
public void readFourLinesWithLfFollowedByCr_ascii() {
|
||||||
byte[] bytes = "foo\n\r\rbar\r\n".getBytes(Charsets.US_ASCII);
|
byte[] bytes = "foo\n\r\rbar\r\n".getBytes(StandardCharsets.US_ASCII);
|
||||||
ParsableByteArray parser = new ParsableByteArray(bytes);
|
ParsableByteArray parser = new ParsableByteArray(bytes);
|
||||||
|
|
||||||
assertThat(parser.readLine(Charsets.US_ASCII)).isEqualTo("foo");
|
assertThat(parser.readLine(StandardCharsets.US_ASCII)).isEqualTo("foo");
|
||||||
assertThat(parser.getPosition()).isEqualTo(4);
|
assertThat(parser.getPosition()).isEqualTo(4);
|
||||||
assertThat(parser.readLine(Charsets.US_ASCII)).isEqualTo("");
|
assertThat(parser.readLine(StandardCharsets.US_ASCII)).isEqualTo("");
|
||||||
assertThat(parser.getPosition()).isEqualTo(5);
|
assertThat(parser.getPosition()).isEqualTo(5);
|
||||||
assertThat(parser.readLine(Charsets.US_ASCII)).isEqualTo("");
|
assertThat(parser.readLine(StandardCharsets.US_ASCII)).isEqualTo("");
|
||||||
assertThat(parser.getPosition()).isEqualTo(6);
|
assertThat(parser.getPosition()).isEqualTo(6);
|
||||||
assertThat(parser.readLine(Charsets.US_ASCII)).isEqualTo("bar");
|
assertThat(parser.readLine(StandardCharsets.US_ASCII)).isEqualTo("bar");
|
||||||
assertThat(parser.getPosition()).isEqualTo(11);
|
assertThat(parser.getPosition()).isEqualTo(11);
|
||||||
assertThat(parser.readLine(Charsets.US_ASCII)).isNull();
|
assertThat(parser.readLine(StandardCharsets.US_ASCII)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readSingleLineWithoutEndingTrail_utf8() {
|
public void readSingleLineWithoutEndingTrail_utf8() {
|
||||||
byte[] bytes = "foo".getBytes(Charsets.UTF_8);
|
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
|
||||||
ParsableByteArray parser = new ParsableByteArray(bytes);
|
ParsableByteArray parser = new ParsableByteArray(bytes);
|
||||||
|
|
||||||
assertThat(parser.readLine()).isEqualTo("foo");
|
assertThat(parser.readLine()).isEqualTo("foo");
|
||||||
@ -671,7 +671,7 @@ public final class ParsableByteArrayTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readSingleLineWithEndingLf_utf8() {
|
public void readSingleLineWithEndingLf_utf8() {
|
||||||
byte[] bytes = "foo\n".getBytes(Charsets.UTF_8);
|
byte[] bytes = "foo\n".getBytes(StandardCharsets.UTF_8);
|
||||||
ParsableByteArray parser = new ParsableByteArray(bytes);
|
ParsableByteArray parser = new ParsableByteArray(bytes);
|
||||||
|
|
||||||
assertThat(parser.readLine()).isEqualTo("foo");
|
assertThat(parser.readLine()).isEqualTo("foo");
|
||||||
@ -681,7 +681,7 @@ public final class ParsableByteArrayTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readTwoLinesWithCrFollowedByLf_utf8() {
|
public void readTwoLinesWithCrFollowedByLf_utf8() {
|
||||||
byte[] bytes = "foo\r\nbar".getBytes(Charsets.UTF_8);
|
byte[] bytes = "foo\r\nbar".getBytes(StandardCharsets.UTF_8);
|
||||||
ParsableByteArray parser = new ParsableByteArray(bytes);
|
ParsableByteArray parser = new ParsableByteArray(bytes);
|
||||||
|
|
||||||
assertThat(parser.readLine()).isEqualTo("foo");
|
assertThat(parser.readLine()).isEqualTo("foo");
|
||||||
@ -694,7 +694,8 @@ public final class ParsableByteArrayTest {
|
|||||||
@Test
|
@Test
|
||||||
public void readThreeLinesWithEmptyLineAndLeadingBom_utf8() {
|
public void readThreeLinesWithEmptyLineAndLeadingBom_utf8() {
|
||||||
byte[] bytes =
|
byte[] bytes =
|
||||||
Bytes.concat(createByteArray(0xEF, 0xBB, 0xBF), "foo\r\n\rbar".getBytes(Charsets.UTF_8));
|
Bytes.concat(
|
||||||
|
createByteArray(0xEF, 0xBB, 0xBF), "foo\r\n\rbar".getBytes(StandardCharsets.UTF_8));
|
||||||
ParsableByteArray parser = new ParsableByteArray(bytes);
|
ParsableByteArray parser = new ParsableByteArray(bytes);
|
||||||
|
|
||||||
assertThat(parser.readLine()).isEqualTo("foo");
|
assertThat(parser.readLine()).isEqualTo("foo");
|
||||||
@ -708,7 +709,7 @@ public final class ParsableByteArrayTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readFourLinesWithLfFollowedByCr_utf8() {
|
public void readFourLinesWithLfFollowedByCr_utf8() {
|
||||||
byte[] bytes = "foo\n\r\rbar\r\n".getBytes(Charsets.UTF_8);
|
byte[] bytes = "foo\n\r\rbar\r\n".getBytes(StandardCharsets.UTF_8);
|
||||||
ParsableByteArray parser = new ParsableByteArray(bytes);
|
ParsableByteArray parser = new ParsableByteArray(bytes);
|
||||||
|
|
||||||
assertThat(parser.readLine()).isEqualTo("foo");
|
assertThat(parser.readLine()).isEqualTo("foo");
|
||||||
@ -726,197 +727,199 @@ public final class ParsableByteArrayTest {
|
|||||||
public void readSingleLineWithoutEndingTrail_utf16() {
|
public void readSingleLineWithoutEndingTrail_utf16() {
|
||||||
// Use UTF_16BE because we don't want the leading BOM that's added by getBytes(UTF_16). We
|
// Use UTF_16BE because we don't want the leading BOM that's added by getBytes(UTF_16). We
|
||||||
// explicitly test with a BOM elsewhere.
|
// explicitly test with a BOM elsewhere.
|
||||||
byte[] bytes = "foo".getBytes(Charsets.UTF_16BE);
|
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_16BE);
|
||||||
ParsableByteArray parser = new ParsableByteArray(bytes);
|
ParsableByteArray parser = new ParsableByteArray(bytes);
|
||||||
|
|
||||||
assertThat(parser.readLine(Charsets.UTF_16)).isEqualTo("foo");
|
assertThat(parser.readLine(StandardCharsets.UTF_16)).isEqualTo("foo");
|
||||||
assertThat(parser.getPosition()).isEqualTo(6);
|
assertThat(parser.getPosition()).isEqualTo(6);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16)).isNull();
|
assertThat(parser.readLine(StandardCharsets.UTF_16)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readSingleLineWithEndingLf_utf16() {
|
public void readSingleLineWithEndingLf_utf16() {
|
||||||
// Use UTF_16BE because we don't want the leading BOM that's added by getBytes(UTF_16). We
|
// Use UTF_16BE because we don't want the leading BOM that's added by getBytes(UTF_16). We
|
||||||
// explicitly test with a BOM elsewhere.
|
// explicitly test with a BOM elsewhere.
|
||||||
byte[] bytes = "foo\n".getBytes(Charsets.UTF_16BE);
|
byte[] bytes = "foo\n".getBytes(StandardCharsets.UTF_16BE);
|
||||||
ParsableByteArray parser = new ParsableByteArray(bytes);
|
ParsableByteArray parser = new ParsableByteArray(bytes);
|
||||||
|
|
||||||
assertThat(parser.readLine(Charsets.UTF_16)).isEqualTo("foo");
|
assertThat(parser.readLine(StandardCharsets.UTF_16)).isEqualTo("foo");
|
||||||
assertThat(parser.getPosition()).isEqualTo(8);
|
assertThat(parser.getPosition()).isEqualTo(8);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16)).isNull();
|
assertThat(parser.readLine(StandardCharsets.UTF_16)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readTwoLinesWithCrFollowedByLf_utf16() {
|
public void readTwoLinesWithCrFollowedByLf_utf16() {
|
||||||
// Use UTF_16BE because we don't want the leading BOM that's added by getBytes(UTF_16). We
|
// Use UTF_16BE because we don't want the leading BOM that's added by getBytes(UTF_16). We
|
||||||
// explicitly test with a BOM elsewhere.
|
// explicitly test with a BOM elsewhere.
|
||||||
byte[] bytes = "foo\r\nbar".getBytes(Charsets.UTF_16BE);
|
byte[] bytes = "foo\r\nbar".getBytes(StandardCharsets.UTF_16BE);
|
||||||
ParsableByteArray parser = new ParsableByteArray(bytes);
|
ParsableByteArray parser = new ParsableByteArray(bytes);
|
||||||
|
|
||||||
assertThat(parser.readLine(Charsets.UTF_16)).isEqualTo("foo");
|
assertThat(parser.readLine(StandardCharsets.UTF_16)).isEqualTo("foo");
|
||||||
assertThat(parser.getPosition()).isEqualTo(10);
|
assertThat(parser.getPosition()).isEqualTo(10);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16)).isEqualTo("bar");
|
assertThat(parser.readLine(StandardCharsets.UTF_16)).isEqualTo("bar");
|
||||||
assertThat(parser.getPosition()).isEqualTo(16);
|
assertThat(parser.getPosition()).isEqualTo(16);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16)).isNull();
|
assertThat(parser.readLine(StandardCharsets.UTF_16)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readThreeLinesWithEmptyLineAndLeadingBom_utf16() {
|
public void readThreeLinesWithEmptyLineAndLeadingBom_utf16() {
|
||||||
// getBytes(UTF_16) always adds the leading BOM.
|
// getBytes(UTF_16) always adds the leading BOM.
|
||||||
byte[] bytes = "foo\r\n\rbar".getBytes(Charsets.UTF_16);
|
byte[] bytes = "foo\r\n\rbar".getBytes(StandardCharsets.UTF_16);
|
||||||
ParsableByteArray parser = new ParsableByteArray(bytes);
|
ParsableByteArray parser = new ParsableByteArray(bytes);
|
||||||
|
|
||||||
assertThat(parser.readLine(Charsets.UTF_16)).isEqualTo("foo");
|
assertThat(parser.readLine(StandardCharsets.UTF_16)).isEqualTo("foo");
|
||||||
assertThat(parser.getPosition()).isEqualTo(12);
|
assertThat(parser.getPosition()).isEqualTo(12);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16)).isEqualTo("");
|
assertThat(parser.readLine(StandardCharsets.UTF_16)).isEqualTo("");
|
||||||
assertThat(parser.getPosition()).isEqualTo(14);
|
assertThat(parser.getPosition()).isEqualTo(14);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16)).isEqualTo("bar");
|
assertThat(parser.readLine(StandardCharsets.UTF_16)).isEqualTo("bar");
|
||||||
assertThat(parser.getPosition()).isEqualTo(20);
|
assertThat(parser.getPosition()).isEqualTo(20);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16)).isNull();
|
assertThat(parser.readLine(StandardCharsets.UTF_16)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readFourLinesWithLfFollowedByCr_utf16() {
|
public void readFourLinesWithLfFollowedByCr_utf16() {
|
||||||
// Use UTF_16BE because we don't want the leading BOM that's added by getBytes(UTF_16). We
|
// Use UTF_16BE because we don't want the leading BOM that's added by getBytes(UTF_16). We
|
||||||
// explicitly test with a BOM elsewhere.
|
// explicitly test with a BOM elsewhere.
|
||||||
byte[] bytes = "foo\n\r\rbar\r\n".getBytes(Charsets.UTF_16BE);
|
byte[] bytes = "foo\n\r\rbar\r\n".getBytes(StandardCharsets.UTF_16BE);
|
||||||
ParsableByteArray parser = new ParsableByteArray(bytes);
|
ParsableByteArray parser = new ParsableByteArray(bytes);
|
||||||
|
|
||||||
assertThat(parser.readLine(Charsets.UTF_16)).isEqualTo("foo");
|
assertThat(parser.readLine(StandardCharsets.UTF_16)).isEqualTo("foo");
|
||||||
assertThat(parser.getPosition()).isEqualTo(8);
|
assertThat(parser.getPosition()).isEqualTo(8);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16)).isEqualTo("");
|
assertThat(parser.readLine(StandardCharsets.UTF_16)).isEqualTo("");
|
||||||
assertThat(parser.getPosition()).isEqualTo(10);
|
assertThat(parser.getPosition()).isEqualTo(10);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16)).isEqualTo("");
|
assertThat(parser.readLine(StandardCharsets.UTF_16)).isEqualTo("");
|
||||||
assertThat(parser.getPosition()).isEqualTo(12);
|
assertThat(parser.getPosition()).isEqualTo(12);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16)).isEqualTo("bar");
|
assertThat(parser.readLine(StandardCharsets.UTF_16)).isEqualTo("bar");
|
||||||
assertThat(parser.getPosition()).isEqualTo(22);
|
assertThat(parser.getPosition()).isEqualTo(22);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16)).isNull();
|
assertThat(parser.readLine(StandardCharsets.UTF_16)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readSingleLineWithoutEndingTrail_utf16be() {
|
public void readSingleLineWithoutEndingTrail_utf16be() {
|
||||||
byte[] bytes = "foo".getBytes(Charsets.UTF_16BE);
|
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_16BE);
|
||||||
ParsableByteArray parser = new ParsableByteArray(bytes);
|
ParsableByteArray parser = new ParsableByteArray(bytes);
|
||||||
|
|
||||||
assertThat(parser.readLine(Charsets.UTF_16BE)).isEqualTo("foo");
|
assertThat(parser.readLine(StandardCharsets.UTF_16BE)).isEqualTo("foo");
|
||||||
assertThat(parser.getPosition()).isEqualTo(6);
|
assertThat(parser.getPosition()).isEqualTo(6);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16BE)).isNull();
|
assertThat(parser.readLine(StandardCharsets.UTF_16BE)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readSingleLineWithEndingLf_utf16be() {
|
public void readSingleLineWithEndingLf_utf16be() {
|
||||||
byte[] bytes = "foo\n".getBytes(Charsets.UTF_16BE);
|
byte[] bytes = "foo\n".getBytes(StandardCharsets.UTF_16BE);
|
||||||
ParsableByteArray parser = new ParsableByteArray(bytes);
|
ParsableByteArray parser = new ParsableByteArray(bytes);
|
||||||
|
|
||||||
assertThat(parser.readLine(Charsets.UTF_16BE)).isEqualTo("foo");
|
assertThat(parser.readLine(StandardCharsets.UTF_16BE)).isEqualTo("foo");
|
||||||
assertThat(parser.getPosition()).isEqualTo(8);
|
assertThat(parser.getPosition()).isEqualTo(8);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16BE)).isNull();
|
assertThat(parser.readLine(StandardCharsets.UTF_16BE)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readTwoLinesWithCrFollowedByLf_utf16be() {
|
public void readTwoLinesWithCrFollowedByLf_utf16be() {
|
||||||
byte[] bytes = "foo\r\nbar".getBytes(Charsets.UTF_16BE);
|
byte[] bytes = "foo\r\nbar".getBytes(StandardCharsets.UTF_16BE);
|
||||||
ParsableByteArray parser = new ParsableByteArray(bytes);
|
ParsableByteArray parser = new ParsableByteArray(bytes);
|
||||||
|
|
||||||
assertThat(parser.readLine(Charsets.UTF_16BE)).isEqualTo("foo");
|
assertThat(parser.readLine(StandardCharsets.UTF_16BE)).isEqualTo("foo");
|
||||||
assertThat(parser.getPosition()).isEqualTo(10);
|
assertThat(parser.getPosition()).isEqualTo(10);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16BE)).isEqualTo("bar");
|
assertThat(parser.readLine(StandardCharsets.UTF_16BE)).isEqualTo("bar");
|
||||||
assertThat(parser.getPosition()).isEqualTo(16);
|
assertThat(parser.getPosition()).isEqualTo(16);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16BE)).isNull();
|
assertThat(parser.readLine(StandardCharsets.UTF_16BE)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readThreeLinesWithEmptyLineAndLeadingBom_utf16be() {
|
public void readThreeLinesWithEmptyLineAndLeadingBom_utf16be() {
|
||||||
byte[] bytes =
|
byte[] bytes =
|
||||||
Bytes.concat(createByteArray(0xFE, 0xFF), "foo\r\n\rbar".getBytes(Charsets.UTF_16BE));
|
Bytes.concat(
|
||||||
|
createByteArray(0xFE, 0xFF), "foo\r\n\rbar".getBytes(StandardCharsets.UTF_16BE));
|
||||||
ParsableByteArray parser = new ParsableByteArray(bytes);
|
ParsableByteArray parser = new ParsableByteArray(bytes);
|
||||||
|
|
||||||
assertThat(parser.readLine(Charsets.UTF_16BE)).isEqualTo("foo");
|
assertThat(parser.readLine(StandardCharsets.UTF_16BE)).isEqualTo("foo");
|
||||||
assertThat(parser.getPosition()).isEqualTo(12);
|
assertThat(parser.getPosition()).isEqualTo(12);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16BE)).isEqualTo("");
|
assertThat(parser.readLine(StandardCharsets.UTF_16BE)).isEqualTo("");
|
||||||
assertThat(parser.getPosition()).isEqualTo(14);
|
assertThat(parser.getPosition()).isEqualTo(14);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16BE)).isEqualTo("bar");
|
assertThat(parser.readLine(StandardCharsets.UTF_16BE)).isEqualTo("bar");
|
||||||
assertThat(parser.getPosition()).isEqualTo(20);
|
assertThat(parser.getPosition()).isEqualTo(20);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16BE)).isNull();
|
assertThat(parser.readLine(StandardCharsets.UTF_16BE)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readFourLinesWithLfFollowedByCr_utf16be() {
|
public void readFourLinesWithLfFollowedByCr_utf16be() {
|
||||||
byte[] bytes = "foo\n\r\rbar\r\n".getBytes(Charsets.UTF_16BE);
|
byte[] bytes = "foo\n\r\rbar\r\n".getBytes(StandardCharsets.UTF_16BE);
|
||||||
ParsableByteArray parser = new ParsableByteArray(bytes);
|
ParsableByteArray parser = new ParsableByteArray(bytes);
|
||||||
|
|
||||||
assertThat(parser.readLine(Charsets.UTF_16BE)).isEqualTo("foo");
|
assertThat(parser.readLine(StandardCharsets.UTF_16BE)).isEqualTo("foo");
|
||||||
assertThat(parser.getPosition()).isEqualTo(8);
|
assertThat(parser.getPosition()).isEqualTo(8);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16BE)).isEqualTo("");
|
assertThat(parser.readLine(StandardCharsets.UTF_16BE)).isEqualTo("");
|
||||||
assertThat(parser.getPosition()).isEqualTo(10);
|
assertThat(parser.getPosition()).isEqualTo(10);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16BE)).isEqualTo("");
|
assertThat(parser.readLine(StandardCharsets.UTF_16BE)).isEqualTo("");
|
||||||
assertThat(parser.getPosition()).isEqualTo(12);
|
assertThat(parser.getPosition()).isEqualTo(12);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16BE)).isEqualTo("bar");
|
assertThat(parser.readLine(StandardCharsets.UTF_16BE)).isEqualTo("bar");
|
||||||
assertThat(parser.getPosition()).isEqualTo(22);
|
assertThat(parser.getPosition()).isEqualTo(22);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16BE)).isNull();
|
assertThat(parser.readLine(StandardCharsets.UTF_16BE)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readSingleLineWithoutEndingTrail_utf16le() {
|
public void readSingleLineWithoutEndingTrail_utf16le() {
|
||||||
byte[] bytes = "foo".getBytes(Charsets.UTF_16LE);
|
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_16LE);
|
||||||
ParsableByteArray parser = new ParsableByteArray(bytes);
|
ParsableByteArray parser = new ParsableByteArray(bytes);
|
||||||
|
|
||||||
assertThat(parser.readLine(Charsets.UTF_16LE)).isEqualTo("foo");
|
assertThat(parser.readLine(StandardCharsets.UTF_16LE)).isEqualTo("foo");
|
||||||
assertThat(parser.getPosition()).isEqualTo(6);
|
assertThat(parser.getPosition()).isEqualTo(6);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16LE)).isNull();
|
assertThat(parser.readLine(StandardCharsets.UTF_16LE)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readSingleLineWithEndingLf_utf16le() {
|
public void readSingleLineWithEndingLf_utf16le() {
|
||||||
byte[] bytes = "foo\n".getBytes(Charsets.UTF_16LE);
|
byte[] bytes = "foo\n".getBytes(StandardCharsets.UTF_16LE);
|
||||||
ParsableByteArray parser = new ParsableByteArray(bytes);
|
ParsableByteArray parser = new ParsableByteArray(bytes);
|
||||||
|
|
||||||
assertThat(parser.readLine(Charsets.UTF_16LE)).isEqualTo("foo");
|
assertThat(parser.readLine(StandardCharsets.UTF_16LE)).isEqualTo("foo");
|
||||||
assertThat(parser.getPosition()).isEqualTo(8);
|
assertThat(parser.getPosition()).isEqualTo(8);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16LE)).isNull();
|
assertThat(parser.readLine(StandardCharsets.UTF_16LE)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readTwoLinesWithCrFollowedByLf_utf16le() {
|
public void readTwoLinesWithCrFollowedByLf_utf16le() {
|
||||||
byte[] bytes = "foo\r\nbar".getBytes(Charsets.UTF_16LE);
|
byte[] bytes = "foo\r\nbar".getBytes(StandardCharsets.UTF_16LE);
|
||||||
ParsableByteArray parser = new ParsableByteArray(bytes);
|
ParsableByteArray parser = new ParsableByteArray(bytes);
|
||||||
|
|
||||||
assertThat(parser.readLine(Charsets.UTF_16LE)).isEqualTo("foo");
|
assertThat(parser.readLine(StandardCharsets.UTF_16LE)).isEqualTo("foo");
|
||||||
assertThat(parser.getPosition()).isEqualTo(10);
|
assertThat(parser.getPosition()).isEqualTo(10);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16LE)).isEqualTo("bar");
|
assertThat(parser.readLine(StandardCharsets.UTF_16LE)).isEqualTo("bar");
|
||||||
assertThat(parser.getPosition()).isEqualTo(16);
|
assertThat(parser.getPosition()).isEqualTo(16);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16LE)).isNull();
|
assertThat(parser.readLine(StandardCharsets.UTF_16LE)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readThreeLinesWithEmptyLineAndLeadingBom_utf16le() {
|
public void readThreeLinesWithEmptyLineAndLeadingBom_utf16le() {
|
||||||
byte[] bytes =
|
byte[] bytes =
|
||||||
Bytes.concat(createByteArray(0xFF, 0xFE), "foo\r\n\rbar".getBytes(Charsets.UTF_16LE));
|
Bytes.concat(
|
||||||
|
createByteArray(0xFF, 0xFE), "foo\r\n\rbar".getBytes(StandardCharsets.UTF_16LE));
|
||||||
ParsableByteArray parser = new ParsableByteArray(bytes);
|
ParsableByteArray parser = new ParsableByteArray(bytes);
|
||||||
|
|
||||||
assertThat(parser.readLine(Charsets.UTF_16LE)).isEqualTo("foo");
|
assertThat(parser.readLine(StandardCharsets.UTF_16LE)).isEqualTo("foo");
|
||||||
assertThat(parser.getPosition()).isEqualTo(12);
|
assertThat(parser.getPosition()).isEqualTo(12);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16LE)).isEqualTo("");
|
assertThat(parser.readLine(StandardCharsets.UTF_16LE)).isEqualTo("");
|
||||||
assertThat(parser.getPosition()).isEqualTo(14);
|
assertThat(parser.getPosition()).isEqualTo(14);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16LE)).isEqualTo("bar");
|
assertThat(parser.readLine(StandardCharsets.UTF_16LE)).isEqualTo("bar");
|
||||||
assertThat(parser.getPosition()).isEqualTo(20);
|
assertThat(parser.getPosition()).isEqualTo(20);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16LE)).isNull();
|
assertThat(parser.readLine(StandardCharsets.UTF_16LE)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readFourLinesWithLfFollowedByCr_utf16le() {
|
public void readFourLinesWithLfFollowedByCr_utf16le() {
|
||||||
byte[] bytes = "foo\n\r\rbar\r\n".getBytes(Charsets.UTF_16LE);
|
byte[] bytes = "foo\n\r\rbar\r\n".getBytes(StandardCharsets.UTF_16LE);
|
||||||
ParsableByteArray parser = new ParsableByteArray(bytes);
|
ParsableByteArray parser = new ParsableByteArray(bytes);
|
||||||
|
|
||||||
assertThat(parser.readLine(Charsets.UTF_16LE)).isEqualTo("foo");
|
assertThat(parser.readLine(StandardCharsets.UTF_16LE)).isEqualTo("foo");
|
||||||
assertThat(parser.getPosition()).isEqualTo(8);
|
assertThat(parser.getPosition()).isEqualTo(8);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16LE)).isEqualTo("");
|
assertThat(parser.readLine(StandardCharsets.UTF_16LE)).isEqualTo("");
|
||||||
assertThat(parser.getPosition()).isEqualTo(10);
|
assertThat(parser.getPosition()).isEqualTo(10);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16LE)).isEqualTo("");
|
assertThat(parser.readLine(StandardCharsets.UTF_16LE)).isEqualTo("");
|
||||||
assertThat(parser.getPosition()).isEqualTo(12);
|
assertThat(parser.getPosition()).isEqualTo(12);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16LE)).isEqualTo("bar");
|
assertThat(parser.readLine(StandardCharsets.UTF_16LE)).isEqualTo("bar");
|
||||||
assertThat(parser.getPosition()).isEqualTo(22);
|
assertThat(parser.getPosition()).isEqualTo(22);
|
||||||
assertThat(parser.readLine(Charsets.UTF_16LE)).isNull();
|
assertThat(parser.readLine(StandardCharsets.UTF_16LE)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user