Search in sources :

Example 11 with InputSupplier

use of com.google.common.io.InputSupplier in project cdap by caskdata.

the class TextStreamBodyConsumerTest method generateFile.

@Override
protected ContentInfo generateFile(final int recordCount) throws IOException {
    return new FileContentInfo(generateFile(TMP_FOLDER.newFile(), recordCount)) {

        @Override
        public boolean verify(Map<String, String> headers, InputSupplier<? extends InputStream> contentSupplier) throws IOException {
            byte[] buf = null;
            InputStream input = contentSupplier.getInput();
            try {
                for (int i = 0; i < recordCount; i++) {
                    byte[] expected = ("Message number " + i).getBytes(Charsets.UTF_8);
                    buf = ensureCapacity(buf, expected.length);
                    ByteStreams.readFully(input, buf, 0, expected.length);
                    if (Bytes.compareTo(expected, 0, expected.length, buf, 0, expected.length) != 0) {
                        return false;
                    }
                }
                return true;
            } finally {
                input.close();
            }
        }
    };
}
Also used : InputStream(java.io.InputStream) Map(java.util.Map) InputSupplier(com.google.common.io.InputSupplier)

Aggregations

InputSupplier (com.google.common.io.InputSupplier)11 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 LocalLocationFactory (org.apache.twill.filesystem.LocalLocationFactory)3 Test (org.junit.Test)3 URI (java.net.URI)2 Map (java.util.Map)2 Manifest (java.util.jar.Manifest)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 Path (org.apache.hadoop.fs.Path)2 Location (org.apache.twill.filesystem.Location)2 ApplicationClass (co.cask.cdap.api.artifact.ApplicationClass)1 ArtifactClasses (co.cask.cdap.api.artifact.ArtifactClasses)1 ArtifactInfo (co.cask.cdap.api.artifact.ArtifactInfo)1 ArtifactRange (co.cask.cdap.api.artifact.ArtifactRange)1 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)1 ArtifactVersion (co.cask.cdap.api.artifact.ArtifactVersion)1 Schema (co.cask.cdap.api.data.schema.Schema)1 FileSet (co.cask.cdap.api.dataset.lib.FileSet)1 PluginClass (co.cask.cdap.api.plugin.PluginClass)1