Backport ByteSources.repeatingArrayByteSource

This commit is contained in:
Andrew Gaul 2014-05-22 10:43:57 -07:00
parent 10a1b230a9
commit b41c4c2ab0
1 changed files with 5 additions and 0 deletions

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.InputStream;
import com.google.common.annotations.Beta;
import com.google.common.collect.Iterables;
import com.google.common.io.ByteSource;
/**
@ -48,4 +49,8 @@ public class ByteSources {
};
}
/** Create an infinite-length ByteSource which repeats its input. */
public static ByteSource repeatingArrayByteSource(final byte[] input) {
return ByteSource.concat(Iterables.cycle(ByteSource.wrap(input)));
}
}