diff options
author | Liam Miller-Cushon <cushon@google.com> | 2022-08-15 11:24:00 -0700 |
---|---|---|
committer | Javac Team <javac-team+copybara@google.com> | 2022-08-15 11:24:50 -0700 |
commit | 7d16600ef7f1f884a45633c21680dad197bbaafd (patch) | |
tree | 8d24272ec37d49893e25caf6497faa0b7a0adc11 | |
parent | f6fa271dac7402cb5e59bc9e2c48ca252254d6fe (diff) | |
download | turbine-7d16600ef7f1f884a45633c21680dad197bbaafd.tar.gz |
Use `InputStream#readAllBytes` instead of `ByteStreams#toByteArray`
PiperOrigin-RevId: 467718127
9 files changed, 14 insertions, 27 deletions
diff --git a/java/com/google/turbine/binder/FileManagerClassBinder.java b/java/com/google/turbine/binder/FileManagerClassBinder.java index d36d2d8..a807dd7 100644 --- a/java/com/google/turbine/binder/FileManagerClassBinder.java +++ b/java/com/google/turbine/binder/FileManagerClassBinder.java @@ -19,7 +19,6 @@ package com.google.turbine.binder; import com.google.common.base.Joiner; import com.google.common.base.Supplier; import com.google.common.collect.ImmutableMap; -import com.google.common.io.ByteStreams; import com.google.turbine.binder.bound.ModuleInfo; import com.google.turbine.binder.bytecode.BytecodeBoundClass; import com.google.turbine.binder.env.Env; @@ -113,7 +112,7 @@ public final class FileManagerClassBinder { @Override public byte[] get() { try { - return ByteStreams.toByteArray(jfo.openInputStream()); + return jfo.openInputStream().readAllBytes(); } catch (IOException e) { throw new UncheckedIOException(e); } @@ -162,7 +161,7 @@ public final class FileManagerClassBinder { @Override public byte[] get() { try { - return ByteStreams.toByteArray(fileObject.openInputStream()); + return fileObject.openInputStream().readAllBytes(); } catch (IOException e) { throw new UncheckedIOException(e); } diff --git a/java/com/google/turbine/processing/TurbineFiler.java b/java/com/google/turbine/processing/TurbineFiler.java index f440ada..8c522ba 100644 --- a/java/com/google/turbine/processing/TurbineFiler.java +++ b/java/com/google/turbine/processing/TurbineFiler.java @@ -24,7 +24,6 @@ import com.google.common.base.Function; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableMap; -import com.google.common.io.ByteStreams; import com.google.turbine.diag.SourceFile; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -380,7 +379,7 @@ public class TurbineFiler implements Filer { @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { - return new String(ByteStreams.toByteArray(openInputStream()), UTF_8); + return new String(openInputStream().readAllBytes(), UTF_8); } } diff --git a/java/com/google/turbine/zip/Zip.java b/java/com/google/turbine/zip/Zip.java index d732b35..c08999b 100644 --- a/java/com/google/turbine/zip/Zip.java +++ b/java/com/google/turbine/zip/Zip.java @@ -18,7 +18,6 @@ package com.google.turbine.zip; import static java.nio.charset.StandardCharsets.UTF_8; -import com.google.common.io.ByteStreams; import com.google.common.primitives.UnsignedInts; import java.io.ByteArrayInputStream; import java.io.Closeable; @@ -332,9 +331,9 @@ public final class Zip { fc.get(bytes); if (deflate) { bytes = - ByteStreams.toByteArray( - new InflaterInputStream( - new ByteArrayInputStream(bytes), new Inflater(/*nowrap=*/ true))); + new InflaterInputStream( + new ByteArrayInputStream(bytes), new Inflater(/*nowrap=*/ true)) + .readAllBytes(); } return bytes; } catch (IOException e) { diff --git a/javatests/com/google/turbine/binder/bytecode/BytecodeBoundClassTest.java b/javatests/com/google/turbine/binder/bytecode/BytecodeBoundClassTest.java index 65d973d..e2d54bd 100644 --- a/javatests/com/google/turbine/binder/bytecode/BytecodeBoundClassTest.java +++ b/javatests/com/google/turbine/binder/bytecode/BytecodeBoundClassTest.java @@ -24,7 +24,6 @@ import static com.google.turbine.testing.TestClassPaths.TURBINE_BOOTCLASSPATH; import static java.util.Objects.requireNonNull; import com.google.common.collect.Iterables; -import com.google.common.io.ByteStreams; import com.google.turbine.binder.bound.TurbineClassValue; import com.google.turbine.binder.bound.TypeBoundClass; import com.google.turbine.binder.bound.TypeBoundClass.FieldInfo; @@ -195,7 +194,7 @@ public class BytecodeBoundClassTest { private static byte[] toByteArrayOrDie(InputStream is) { try { - return ByteStreams.toByteArray(is); + return is.readAllBytes(); } catch (IOException e) { throw new UncheckedIOException(e); } diff --git a/javatests/com/google/turbine/deps/TransitiveTest.java b/javatests/com/google/turbine/deps/TransitiveTest.java index f08e899..3829ddd 100644 --- a/javatests/com/google/turbine/deps/TransitiveTest.java +++ b/javatests/com/google/turbine/deps/TransitiveTest.java @@ -26,7 +26,6 @@ import static java.nio.charset.StandardCharsets.UTF_8; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; -import com.google.common.io.ByteStreams; import com.google.protobuf.ExtensionRegistry; import com.google.turbine.bytecode.ClassFile; import com.google.turbine.bytecode.ClassFile.InnerClass; @@ -87,7 +86,7 @@ public class TransitiveTest { Enumeration<JarEntry> entries = jf.entries(); while (entries.hasMoreElements()) { JarEntry je = entries.nextElement(); - jarEntries.put(je.getName(), ByteStreams.toByteArray(jf.getInputStream(je))); + jarEntries.put(je.getName(), jf.getInputStream(je).readAllBytes()); } } return jarEntries; diff --git a/javatests/com/google/turbine/main/MainTest.java b/javatests/com/google/turbine/main/MainTest.java index 3504891..c894d9d 100644 --- a/javatests/com/google/turbine/main/MainTest.java +++ b/javatests/com/google/turbine/main/MainTest.java @@ -28,7 +28,6 @@ import static org.junit.Assert.assertThrows; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.common.io.ByteStreams; import com.google.common.io.MoreFiles; import com.google.protobuf.ExtensionRegistry; import com.google.turbine.diag.TurbineError; @@ -148,7 +147,7 @@ public class MainTest { Enumeration<JarEntry> entries = jf.entries(); while (entries.hasMoreElements()) { JarEntry je = entries.nextElement(); - data.put(je.getName(), ByteStreams.toByteArray(jf.getInputStream(je))); + data.put(je.getName(), jf.getInputStream(je).readAllBytes()); } } return data; diff --git a/javatests/com/google/turbine/processing/TurbineFilerTest.java b/javatests/com/google/turbine/processing/TurbineFilerTest.java index 83dcc70..96c325b 100644 --- a/javatests/com/google/turbine/processing/TurbineFilerTest.java +++ b/javatests/com/google/turbine/processing/TurbineFilerTest.java @@ -23,7 +23,6 @@ import static org.junit.Assert.assertThrows; import com.google.common.base.Function; import com.google.common.base.Supplier; -import com.google.common.io.ByteStreams; import com.google.common.io.CharStreams; import com.google.turbine.diag.SourceFile; import java.io.FileNotFoundException; @@ -127,8 +126,7 @@ public class TurbineFilerTest { Collection<SourceFile> unused = filer.finishRound(); FileObject output = filer.getResource(StandardLocation.SOURCE_OUTPUT, "com.foo", "Bar.java"); - assertThat(new String(ByteStreams.toByteArray(output.openInputStream()), UTF_8)) - .isEqualTo("hello"); + assertThat(new String(output.openInputStream().readAllBytes(), UTF_8)).isEqualTo("hello"); assertThat(output.getCharContent(false).toString()).isEqualTo("hello"); assertThat(CharStreams.toString(output.openReader(true))).isEqualTo("hello"); } @@ -142,8 +140,7 @@ public class TurbineFilerTest { Collection<SourceFile> unused = filer.finishRound(); FileObject output = filer.getResource(StandardLocation.CLASS_OUTPUT, "com.foo", "Baz.class"); - assertThat(new String(ByteStreams.toByteArray(output.openInputStream()), UTF_8)) - .isEqualTo("goodbye"); + assertThat(new String(output.openInputStream().readAllBytes(), UTF_8)).isEqualTo("goodbye"); assertThat(output.getCharContent(false).toString()).isEqualTo("goodbye"); assertThat(CharStreams.toString(output.openReader(true))).isEqualTo("goodbye"); } @@ -153,7 +150,7 @@ public class TurbineFilerTest { FileObject resource = filer.getResource(StandardLocation.ANNOTATION_PROCESSOR_PATH, "META-INF", "MANIFEST.MF"); - assertThat(new String(ByteStreams.toByteArray(resource.openInputStream()), UTF_8)) + assertThat(new String(resource.openInputStream().readAllBytes(), UTF_8)) .contains("Manifest-Version:"); assertThat(CharStreams.toString(resource.openReader(true))).contains("Manifest-Version:"); assertThat(resource.getCharContent(false).toString()).contains("Manifest-Version:"); diff --git a/javatests/com/google/turbine/testing/TestResources.java b/javatests/com/google/turbine/testing/TestResources.java index 86c7632..6c456ab 100644 --- a/javatests/com/google/turbine/testing/TestResources.java +++ b/javatests/com/google/turbine/testing/TestResources.java @@ -19,7 +19,6 @@ package com.google.turbine.testing; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Objects.requireNonNull; -import com.google.common.io.ByteStreams; import java.io.IOException; import java.io.InputStream; import java.io.UncheckedIOException; @@ -32,7 +31,7 @@ public final class TestResources { public static byte[] getResourceBytes(Class<?> clazz, String resource) { try (InputStream is = requireNonNull(clazz.getResourceAsStream(resource), resource)) { - return ByteStreams.toByteArray(is); + return is.readAllBytes(); } catch (IOException e) { throw new UncheckedIOException(e); } diff --git a/javatests/com/google/turbine/zip/ZipTest.java b/javatests/com/google/turbine/zip/ZipTest.java index 2b6636d..b64531a 100644 --- a/javatests/com/google/turbine/zip/ZipTest.java +++ b/javatests/com/google/turbine/zip/ZipTest.java @@ -22,7 +22,6 @@ import static org.junit.Assert.assertThrows; import com.google.common.collect.ImmutableMap; import com.google.common.hash.Hashing; -import com.google.common.io.ByteStreams; import java.io.IOException; import java.net.URI; import java.nio.ByteBuffer; @@ -116,9 +115,7 @@ public class ZipTest { JarEntry je = entries.nextElement(); result.put( je.getName(), - Hashing.goodFastHash(128) - .hashBytes(ByteStreams.toByteArray(jf.getInputStream(je))) - .padToLong()); + Hashing.goodFastHash(128).hashBytes(jf.getInputStream(je).readAllBytes()).padToLong()); } } return result; |