From 76ca253d198224438426bda8a6e7c92bc387844d Mon Sep 17 00:00:00 2001 From: Charles Allen Date: Tue, 27 Sep 2016 15:52:13 -0700 Subject: [PATCH] Make GenericIndexedWriter guava 14 friendly --- .../segment/data/GenericIndexedWriter.java | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/processing/src/main/java/io/druid/segment/data/GenericIndexedWriter.java b/processing/src/main/java/io/druid/segment/data/GenericIndexedWriter.java index 020fccd461f5..2d6d93b07224 100644 --- a/processing/src/main/java/io/druid/segment/data/GenericIndexedWriter.java +++ b/processing/src/main/java/io/druid/segment/data/GenericIndexedWriter.java @@ -25,14 +25,12 @@ import com.google.common.io.ByteSource; import com.google.common.io.ByteStreams; import com.google.common.io.CountingOutputStream; -import com.google.common.io.InputSupplier; import com.google.common.primitives.Ints; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.nio.ByteBuffer; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; import java.nio.channels.WritableByteChannel; @@ -136,26 +134,35 @@ public long getSerializedSize() public ByteSource combineStreams() { - return ByteSource.concat( - Iterables.transform( - Arrays.asList("meta", "header", "values"), - new Function() { - - @Override - public ByteSource apply(final String input) - { - return new ByteSource() + // ByteSource.concat is only available in guava 15 and higher + return new ByteSource() + { + @Override + public InputStream openStream() throws IOException + { + // When we no longer have to maintain compat with Guava 14, this can be upgraded + return ByteStreams.join( + Iterables.transform( + Arrays.asList("meta", "header", "values"), + new Function() { @Override - public InputStream openStream() throws IOException + public ByteSource apply(final String input) { - return ioPeon.makeInputStream(makeFilename(input)); + return new ByteSource() + { + @Override + public InputStream openStream() throws IOException + { + return ioPeon.makeInputStream(makeFilename(input)); + } + }; } - }; - } - } - ) - ); + } + ) + ).getInput(); + } + }; } public void writeToChannel(WritableByteChannel channel) throws IOException