aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/io/TextDataSource.java
diff options
context:
space:
mode:
Diffstat (limited to 'pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/io/TextDataSource.java')
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/io/TextDataSource.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/io/TextDataSource.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/io/TextDataSource.java
new file mode 100644
index 0000000..de5c7a8
--- /dev/null
+++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/io/TextDataSource.java
@@ -0,0 +1,50 @@
+package at.gv.egiz.pdfas.web.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+import at.gv.egiz.pdfas.api.io.DataSource;
+
+/**
+ *
+ * @author exthex
+ *
+ */
+public class TextDataSource implements DataSource {
+
+ private String text;
+
+ public TextDataSource(String text) {
+ this.text = text;
+ }
+
+ public InputStream createInputStream() {
+ try {
+ return new ByteArrayInputStream(text.getBytes("UTF-8"));
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public int getLength() {
+ return 0;
+ }
+
+ public byte[] getAsByteArray() {
+ try{
+ return text.getBytes("UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public String getMimeType() {
+ return "text/plain";
+ }
+
+ public String getCharacterEncoding() {
+ return "UTF-8";
+ }
+
+}