com.google.sitebricks.client.transport.SimpleTextTransport Maven / Gradle / Ivy
package com.google.sitebricks.client.transport;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import com.google.common.io.ByteStreams;
import com.google.common.io.CharStreams;
/**
* @author Dhanji R. Prasanna ([email protected])
*/
class SimpleTextTransport extends Text {
public T in(InputStream in, Class type) throws IOException {
return type.cast(CharStreams.toString(new InputStreamReader(in)));
}
public void out(OutputStream out, Class type, T data) {
try {
ByteStreams.copy(new ByteArrayInputStream(data.toString().getBytes()), out);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}