1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.any23.source;
19
20 import java.io.ByteArrayInputStream;
21 import java.io.IOException;
22 import java.io.InputStream;
23
24
25
26
27
28
29 public class ByteArrayDocumentSource implements DocumentSource {
30
31 private final byte[] bytes;
32
33 private final String documentIRI;
34
35 private final String contentType;
36
37 public ByteArrayDocumentSource(byte[] bytes, String documentIRI, String contentType) {
38 this.bytes = bytes;
39 this.documentIRI = documentIRI;
40 this.contentType = contentType;
41 }
42
43 public ByteArrayDocumentSource(InputStream inputStream, String documentIRI, String contentType) throws IOException {
44 this(MemCopyFactory.toByteArray(inputStream), documentIRI, contentType);
45 }
46
47 public InputStream openInputStream() throws IOException {
48 return new ByteArrayInputStream(bytes);
49 }
50
51 public long getContentLength() {
52 return bytes.length;
53 }
54
55 public String getDocumentIRI() {
56 return documentIRI;
57 }
58
59 public String getContentType() {
60 return contentType;
61 }
62
63 public boolean isLocal() {
64 return true;
65 }
66
67 }