Remove implicit uses of platform default charset

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=173419389
This commit is contained in:
mcilwain 2017-10-25 10:52:47 -07:00 committed by jianglai
parent 51326a1a5c
commit 996095aed3
5 changed files with 33 additions and 36 deletions

View file

@ -15,7 +15,6 @@
package google.registry.util;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static java.nio.charset.StandardCharsets.UTF_8;
import google.registry.testing.ExceptionRule;
@ -37,7 +36,7 @@ public class HexDumperTest {
String input = "";
String output = "[0 bytes total]\n";
assertThat(input).isEmpty();
assertThat(HexDumper.dumpHex(input.getBytes())).isEqualTo(output);
assertThat(HexDumper.dumpHex(input.getBytes(UTF_8))).isEqualTo(output);
}
@Test
@ -46,7 +45,7 @@ public class HexDumperTest {
String output = "[11 bytes total]\n"
+ "00000000 68 65 6c 6c 6f 20 77 6f 72 6c 64 hello world \n";
assertThat(input).hasLength(11);
assertThat(HexDumper.dumpHex(input.getBytes())).isEqualTo(output);
assertThat(HexDumper.dumpHex(input.getBytes(UTF_8))).isEqualTo(output);
}
@Test
@ -64,7 +63,7 @@ public class HexDumperTest {
+ "00000064 65 20 62 75 79 2c 20 63 6f 6d 65 20 62 75 79 3a e buy, come buy:\n"
+ "00000080 0a . \n";
assertThat(input).hasLength(81);
assertThat(HexDumper.dumpHex(input.getBytes())).isEqualTo(output);
assertThat(HexDumper.dumpHex(input.getBytes(UTF_8))).isEqualTo(output);
}
@Test
@ -73,7 +72,7 @@ public class HexDumperTest {
String output = "[16 bytes total]\n"
+ "00000000 68 65 6c 6c 6f 20 77 6f 72 6c 64 64 64 64 64 64 hello worldddddd\n";
assertThat(input).hasLength(16);
assertThat(HexDumper.dumpHex(input.getBytes())).isEqualTo(output);
assertThat(HexDumper.dumpHex(input.getBytes(UTF_8))).isEqualTo(output);
}
@Test
@ -114,7 +113,7 @@ public class HexDumperTest {
@Test
public void testLineBuffering() throws Exception {
// Assume that we have some data that's N bytes long.
byte[] data = "Sweet to tongue and sound to eye; Come buy, come buy.".getBytes();
byte[] data = "Sweet to tongue and sound to eye; Come buy, come buy.".getBytes(UTF_8);
// And a streaming HexDumper that displays N+1 characters per row.
int perLine = data.length + 1;
try (StringWriter out = new StringWriter();
@ -141,11 +140,11 @@ public class HexDumperTest {
public void testFlush() throws Exception {
try (StringWriter out = new StringWriter();
HexDumper dumper = new HexDumper(out)) {
dumper.write("hello ".getBytes());
dumper.write("hello ".getBytes(UTF_8));
assertThat(out.toString()).isEmpty();
dumper.flush();
assertThat(out.toString()).isEqualTo("00000000 68 65 6c 6c 6f 20 ");
dumper.write("world".getBytes());
dumper.write("world".getBytes(UTF_8));
assertThat(out.toString()).isEqualTo("00000000 68 65 6c 6c 6f 20 ");
dumper.flush();
assertThat(out.toString()).isEqualTo("00000000 68 65 6c 6c 6f 20 77 6f 72 6c 64 ");
@ -164,7 +163,7 @@ public class HexDumperTest {
+ "00000002 6c l\n"
+ "00000003 6c l\n"
+ "00000004 6f o\n";
assertThat(HexDumper.dumpHex(input.getBytes(), 1, 0)).isEqualTo(output);
assertThat(HexDumper.dumpHex(input.getBytes(UTF_8), 1, 0)).isEqualTo(output);
}
@Test

View file

@ -16,7 +16,6 @@ package google.registry.util;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.testing.SystemInfo.hasCommand;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assume.assumeTrue;
@ -53,7 +52,7 @@ public class PosixTarHeaderSystemTest {
// We have some data (in memory) that we'll call hello.txt.
String fileName = "hello.txt";
byte[] fileData = "hello world\n".getBytes();
byte[] fileData = "hello world\n".getBytes(UTF_8);
// We're going to put it in a new tar archive (on the filesystem) named hello.tar.
String tarName = "hello.tar";
@ -152,8 +151,8 @@ public class PosixTarHeaderSystemTest {
String one = "the first line";
String two = "the second line";
File cwd = folder.getRoot();
Files.write(one.getBytes(), new File(cwd, "one"));
Files.write(two.getBytes(), new File(cwd, "two"));
Files.write(one.getBytes(UTF_8), new File(cwd, "one"));
Files.write(two.getBytes(UTF_8), new File(cwd, "two"));
String[] cmd = {"tar", "--format=ustar", "-cf", "lines.tar", "one", "two"};
String[] env = {"PATH=" + System.getenv("PATH")};
@ -171,7 +170,7 @@ public class PosixTarHeaderSystemTest {
assertThat(header.getName()).isEqualTo("one");
assertThat(header.getSize()).isEqualTo(one.length());
assertThat(input.read(block)).isEqualTo(512);
assertThat(one).isEqualTo(new String(block, 0, one.length()));
assertThat(one).isEqualTo(new String(block, 0, one.length(), UTF_8));
assertThat(input.read(block)).isEqualTo(512);
header = PosixTarHeader.from(block);
@ -179,7 +178,7 @@ public class PosixTarHeaderSystemTest {
assertThat(header.getName()).isEqualTo("two");
assertThat(header.getSize()).isEqualTo(two.length());
assertThat(input.read(block)).isEqualTo(512);
assertThat(two).isEqualTo(new String(block, 0, two.length()));
assertThat(two).isEqualTo(new String(block, 0, two.length(), UTF_8));
assertThat(input.read(block)).isEqualTo(512);
assertWithMessage("End of archive marker corrupt").that(block).isEqualTo(new byte[512]);
@ -194,7 +193,7 @@ public class PosixTarHeaderSystemTest {
assumeTrue(hasCommand("tar"));
String truth = "No one really knows\n";
Files.write(truth.getBytes(), folder.newFile("truth.txt"));
Files.write(truth.getBytes(UTF_8), folder.newFile("truth.txt"));
String[] cmd = {"tar", "-cf", "steam.tar", "truth.txt"};
String[] env = {"PATH=" + System.getenv("PATH")};
@ -213,7 +212,7 @@ public class PosixTarHeaderSystemTest {
assertThat(header.getName()).isEqualTo("truth.txt");
assertThat(header.getSize()).isEqualTo(truth.length());
assertThat(input.read(block)).isEqualTo(512);
assertThat(truth).isEqualTo(new String(block, 0, truth.length()));
assertThat(truth).isEqualTo(new String(block, 0, truth.length(), UTF_8));
assertThat(input.read(block)).isEqualTo(512);
assertWithMessage("End of archive marker corrupt").that(block).isEqualTo(new byte[512]);

View file

@ -17,7 +17,6 @@ package google.registry.util;
import static com.google.common.io.BaseEncoding.base64;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static com.google.common.truth.Truth8.assertThat;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.testing.EqualsTester;
@ -273,7 +272,7 @@ public class PosixTarHeaderTest {
assertThat(header.getMtime().toString(ISODateTimeFormat.date())).isEqualTo("2013-08-16");
assertThat(input.read(block)).isEqualTo(512);
assertThat(new String(block, 0, likeTears.length())).isEqualTo(likeTears);
assertThat(new String(block, 0, likeTears.length(), UTF_8)).isEqualTo(likeTears);
assertThat(input.read(block)).isEqualTo(512);
header = PosixTarHeader.from(block);
@ -287,7 +286,7 @@ public class PosixTarHeaderTest {
assertThat(header.getMtime().toString(ISODateTimeFormat.date())).isEqualTo("2013-08-16");
assertThat(input.read(block)).isEqualTo(512);
assertThat(new String(block, 0, inRain.length())).isEqualTo(inRain);
assertThat(new String(block, 0, inRain.length(), UTF_8)).isEqualTo(inRain);
assertThat(input.read(block)).isEqualTo(512);
assertWithMessage("End of archive marker corrupt").that(block).isEqualTo(new byte[512]);
@ -327,7 +326,7 @@ public class PosixTarHeaderTest {
assertThat(header.getMtime().toString(ISODateTimeFormat.date())).isEqualTo("2013-08-16");
assertThat(input.read(block)).isEqualTo(512);
assertThat(new String(block, 0, likeTears.length())).isEqualTo(likeTears);
assertThat(new String(block, 0, likeTears.length(), UTF_8)).isEqualTo(likeTears);
assertThat(input.read(block)).isEqualTo(512);
header = PosixTarHeader.from(block);
@ -341,7 +340,7 @@ public class PosixTarHeaderTest {
assertThat(header.getMtime().toString(ISODateTimeFormat.date())).isEqualTo("2013-08-16");
assertThat(input.read(block)).isEqualTo(512);
assertThat(new String(block, 0, inRain.length())).isEqualTo(inRain);
assertThat(new String(block, 0, inRain.length(), UTF_8)).isEqualTo(inRain);
assertThat(input.read(block)).isEqualTo(512);
assertWithMessage("End of archive marker corrupt").that(block).isEqualTo(new byte[512]);
@ -381,7 +380,7 @@ public class PosixTarHeaderTest {
assertThat(header.getMtime().toString(ISODateTimeFormat.date())).isEqualTo("2013-08-16");
assertThat(input.read(block)).isEqualTo(512);
assertThat(new String(block, 0, likeTears.length())).isEqualTo(likeTears);
assertThat(new String(block, 0, likeTears.length(), UTF_8)).isEqualTo(likeTears);
assertThat(input.read(block)).isEqualTo(512);
header = PosixTarHeader.from(block);
@ -395,7 +394,7 @@ public class PosixTarHeaderTest {
assertThat(header.getMtime().toString(ISODateTimeFormat.date())).isEqualTo("2013-08-16");
assertThat(input.read(block)).isEqualTo(512);
assertThat(new String(block, 0, inRain.length())).isEqualTo(inRain);
assertThat(new String(block, 0, inRain.length(), UTF_8)).isEqualTo(inRain);
assertThat(input.read(block)).isEqualTo(512);
assertWithMessage("End of archive marker corrupt").that(block).isEqualTo(new byte[512]);
@ -436,7 +435,7 @@ public class PosixTarHeaderTest {
assertThat(header.getMtime().toString(ISODateTimeFormat.date())).isEqualTo("2013-08-16");
assertThat(input.read(block)).isEqualTo(512);
assertThat(new String(block, 0, likeTears.length())).isEqualTo(likeTears);
assertThat(new String(block, 0, likeTears.length(), UTF_8)).isEqualTo(likeTears);
assertThat(input.read(block)).isEqualTo(512);
header = PosixTarHeader.from(block);
@ -451,7 +450,7 @@ public class PosixTarHeaderTest {
assertThat(header.getMtime().toString(ISODateTimeFormat.date())).isEqualTo("2013-08-16");
assertThat(input.read(block)).isEqualTo(512);
assertThat(new String(block, 0, inRain.length())).isEqualTo(inRain);
assertThat(new String(block, 0, inRain.length(), UTF_8)).isEqualTo(inRain);
assertThat(input.read(block)).isEqualTo(512);
assertWithMessage("End of archive marker corrupt").that(block).isEqualTo(new byte[512]);

View file

@ -15,7 +15,7 @@
package google.registry.util;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Arrays.asList;
import com.google.common.collect.ImmutableSet;
@ -43,14 +43,14 @@ public class TeeOutputStreamTest {
// Write shared data using the tee output stream.
try (OutputStream tee =
new TeeOutputStream(asList(outputA, outputB, outputC))) {
tee.write("hello ".getBytes());
tee.write("hello world!".getBytes(), 6, 5);
tee.write("hello ".getBytes(UTF_8));
tee.write("hello world!".getBytes(UTF_8), 6, 5);
tee.write('!');
}
// Write some more data to the different streams - they should not have been closed.
outputA.write("a".getBytes());
outputB.write("b".getBytes());
outputC.write("c".getBytes());
outputA.write("a".getBytes(UTF_8));
outputB.write("b".getBytes(UTF_8));
outputC.write("c".getBytes(UTF_8));
// Check the results.
assertThat(outputA.toString()).isEqualTo("hello world!a");
assertThat(outputB.toString()).isEqualTo("hello world!b");
@ -77,7 +77,7 @@ public class TeeOutputStreamTest {
OutputStream tee = new TeeOutputStream(asList(outputA));
tee.close();
thrown.expect(IllegalStateException.class, "outputstream closed");
tee.write("hello".getBytes());
tee.write("hello".getBytes(UTF_8));
}
@Test
@ -85,6 +85,6 @@ public class TeeOutputStreamTest {
OutputStream tee = new TeeOutputStream(asList(outputA));
tee.close();
thrown.expect(IllegalStateException.class, "outputstream closed");
tee.write("hello".getBytes(), 1, 3);
tee.write("hello".getBytes(UTF_8), 1, 3);
}
}

View file

@ -15,8 +15,8 @@
package google.registry.xjc;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.util.ResourceUtils.readResourceUtf8;
import static java.nio.charset.StandardCharsets.UTF_8;
import google.registry.xjc.rdehost.XjcRdeHostElement;
import java.io.ByteArrayInputStream;
@ -40,7 +40,7 @@ public class JaxbFragmentTest {
public void testJavaSerialization() throws Exception {
// Load rdeHost xml fragment into a jaxb object, wrap it, marshal, unmarshal, verify host.
// The resulting host name should be "ns1.example1.test", from the original xml fragment.
try (InputStream source = new ByteArrayInputStream(HOST_FRAGMENT.getBytes())) {
try (InputStream source = new ByteArrayInputStream(HOST_FRAGMENT.getBytes(UTF_8))) {
// Load xml
JaxbFragment<XjcRdeHostElement> hostFragment =
JaxbFragment.create(XjcXmlTransformer.unmarshal(XjcRdeHostElement.class, source));