diff options
Diffstat (limited to 'guava/src/com/google/common/hash/Funnels.java')
-rw-r--r-- | guava/src/com/google/common/hash/Funnels.java | 88 |
1 files changed, 3 insertions, 85 deletions
diff --git a/guava/src/com/google/common/hash/Funnels.java b/guava/src/com/google/common/hash/Funnels.java index 7f76202..2cb04f4 100644 --- a/guava/src/com/google/common/hash/Funnels.java +++ b/guava/src/com/google/common/hash/Funnels.java @@ -15,13 +15,10 @@ package com.google.common.hash; import com.google.common.annotations.Beta; -import com.google.common.base.Preconditions; - -import java.io.OutputStream; /** * Funnels for common types. All implementations are serializable. - * + * * @author Dimitris Andreou * @since 11.0 */ @@ -39,7 +36,7 @@ public final class Funnels { private enum ByteArrayFunnel implements Funnel<byte[]> { INSTANCE; - public void funnel(byte[] from, PrimitiveSink into) { + public void funnel(byte[] from, Sink into) { into.putBytes(from); } @@ -58,7 +55,7 @@ public final class Funnels { private enum StringFunnel implements Funnel<CharSequence> { INSTANCE; - public void funnel(CharSequence from, PrimitiveSink into) { + public void funnel(CharSequence from, Sink into) { into.putString(from); } @@ -66,83 +63,4 @@ public final class Funnels { return "Funnels.stringFunnel()"; } } - - /** - * Returns a funnel for integers. - * - * @since 13.0 - */ - public static Funnel<Integer> integerFunnel() { - return IntegerFunnel.INSTANCE; - } - - private enum IntegerFunnel implements Funnel<Integer> { - INSTANCE; - - public void funnel(Integer from, PrimitiveSink into) { - into.putInt(from); - } - - @Override public String toString() { - return "Funnels.integerFunnel()"; - } - } - - /** - * Returns a funnel for longs. - * - * @since 13.0 - */ - public static Funnel<Long> longFunnel() { - return LongFunnel.INSTANCE; - } - - private enum LongFunnel implements Funnel<Long> { - INSTANCE; - - public void funnel(Long from, PrimitiveSink into) { - into.putLong(from); - } - - @Override public String toString() { - return "Funnels.longFunnel()"; - } - } - - /** - * Wraps a {@code PrimitiveSink} as an {@link OutputStream}, so it is easy to - * {@link Funnel#funnel funnel} an object to a {@code PrimitiveSink} - * if there is already a way to write the contents of the object to an {@code OutputStream}. - * - * <p>The {@code close} and {@code flush} methods of the returned {@code OutputStream} - * do nothing, and no method throws {@code IOException}. - * - * @since 13.0 - */ - public static OutputStream asOutputStream(PrimitiveSink sink) { - return new SinkAsStream(sink); - } - - private static class SinkAsStream extends OutputStream { - final PrimitiveSink sink; - SinkAsStream(PrimitiveSink sink) { - this.sink = Preconditions.checkNotNull(sink); - } - - @Override public void write(int b) { - sink.putByte((byte) b); - } - - @Override public void write(byte[] bytes) { - sink.putBytes(bytes); - } - - @Override public void write(byte[] bytes, int off, int len) { - sink.putBytes(bytes, off, len); - } - - @Override public String toString() { - return "Funnels.asOutputStream(" + sink + ")"; - } - } } |