sascha@380: package de.intevation.artifactdatabase.rest; sascha@380: sascha@380: import org.restlet.representation.Representation; sascha@380: sascha@380: import java.io.Reader; sascha@380: import java.io.OutputStream; sascha@380: import java.io.InputStream; sascha@380: import java.io.Writer; sascha@380: import java.io.IOException; sascha@380: import java.io.InputStreamReader; sascha@380: import java.io.ByteArrayInputStream; sascha@380: sascha@380: import java.nio.ByteBuffer; sascha@380: sascha@380: import java.nio.channels.ReadableByteChannel; sascha@380: import java.nio.channels.WritableByteChannel; sascha@380: sascha@380: import org.restlet.data.MediaType; sascha@380: sascha@380: public class ByteArrayRepresentation sascha@380: extends Representation sascha@380: { sascha@380: protected byte [] data; sascha@380: sascha@380: public ByteArrayRepresentation(MediaType mediaType, byte [] data) { sascha@380: super(mediaType); sascha@380: this.data = data; sascha@380: } sascha@380: sascha@380: @Override sascha@380: public long getSize() { sascha@380: return data.length; sascha@380: } sascha@380: sascha@380: @Override sascha@380: public ReadableByteChannel getChannel() throws IOException { sascha@380: return null; sascha@380: } sascha@380: sascha@380: @Override sascha@380: public Reader getReader() throws IOException { sascha@380: return new InputStreamReader(getStream()); sascha@380: } sascha@380: sascha@380: @Override sascha@380: public InputStream getStream() throws IOException { sascha@380: return new ByteArrayInputStream(data); sascha@380: } sascha@380: sascha@380: @Override sascha@380: public void write(Writer writer) throws IOException { sascha@380: writer.append(ByteBuffer.wrap(data).asCharBuffer()); sascha@380: } sascha@380: sascha@380: @Override sascha@380: public void write(WritableByteChannel writableChannel) throws IOException { sascha@380: writableChannel.write(ByteBuffer.wrap(data)); sascha@380: } sascha@380: sascha@380: @Override sascha@380: public void write(OutputStream outputStream) throws IOException { sascha@380: outputStream.write(data); sascha@380: } sascha@380: } sascha@380: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :