Merge pull request #301 from Doha2012/master
inputStream guava improvement
This commit is contained in:
commit
eddf74f734
|
@ -32,7 +32,6 @@ import com.google.common.io.ByteSource;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import com.google.common.io.CharStreams;
|
import com.google.common.io.CharStreams;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
import com.google.common.io.InputSupplier;
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class JavaInputStreamToXUnitTest {
|
public class JavaInputStreamToXUnitTest {
|
||||||
|
@ -75,16 +74,14 @@ public class JavaInputStreamToXUnitTest {
|
||||||
final String originalString = randomAlphabetic(DEFAULT_SIZE);
|
final String originalString = randomAlphabetic(DEFAULT_SIZE);
|
||||||
final InputStream inputStream = new ByteArrayInputStream(originalString.getBytes());
|
final InputStream inputStream = new ByteArrayInputStream(originalString.getBytes());
|
||||||
|
|
||||||
final InputSupplier<InputStream> inputSupplier = new InputSupplier<InputStream>() {
|
final ByteSource byteSource = new ByteSource() {
|
||||||
@Override
|
@Override
|
||||||
public final InputStream getInput() throws IOException {
|
public final InputStream openStream() throws IOException {
|
||||||
return inputStream;
|
return inputStream;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
final InputSupplier<InputStreamReader> readerSupplier = CharStreams.newReaderSupplier(inputSupplier, Charsets.UTF_8);
|
|
||||||
|
|
||||||
// When
|
final String text = byteSource.asCharSource(Charsets.UTF_8).read();
|
||||||
final String text = CharStreams.toString(readerSupplier);
|
|
||||||
|
|
||||||
assertThat(text, equalTo(originalString));
|
assertThat(text, equalTo(originalString));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue