annotate artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ByteArrayRepresentation.java @ 430:bedc87d11596

dummy merge for repo head
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:15:13 +0200
parents 9798e4d83681
children
rev   line source
380
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.artifactdatabase.rest;
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import org.restlet.representation.Representation;
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 import java.io.Reader;
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 import java.io.OutputStream;
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 import java.io.InputStream;
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 import java.io.Writer;
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 import java.io.IOException;
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 import java.io.InputStreamReader;
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 import java.io.ByteArrayInputStream;
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 import java.nio.ByteBuffer;
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 import java.nio.channels.ReadableByteChannel;
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 import java.nio.channels.WritableByteChannel;
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 import org.restlet.data.MediaType;
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 public class ByteArrayRepresentation
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 extends Representation
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 {
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 protected byte [] data;
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 public ByteArrayRepresentation(MediaType mediaType, byte [] data) {
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 super(mediaType);
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 this.data = data;
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 }
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 @Override
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 public long getSize() {
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 return data.length;
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 }
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 @Override
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 public ReadableByteChannel getChannel() throws IOException {
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 return null;
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 }
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 @Override
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 public Reader getReader() throws IOException {
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 return new InputStreamReader(getStream());
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 }
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 @Override
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 public InputStream getStream() throws IOException {
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 return new ByteArrayInputStream(data);
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 }
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 @Override
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 public void write(Writer writer) throws IOException {
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 writer.append(ByteBuffer.wrap(data).asCharBuffer());
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 }
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 @Override
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 public void write(WritableByteChannel writableChannel) throws IOException {
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 writableChannel.write(ByteBuffer.wrap(data));
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 }
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 @Override
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 public void write(OutputStream outputStream) throws IOException {
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 outputStream.write(data);
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 }
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 }
9798e4d83681 Services are now able to return more than just XML documents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org