01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.attachment;
19:
20: import java.io.ByteArrayInputStream;
21: import java.io.IOException;
22: import java.io.InputStream;
23: import java.io.OutputStream;
24:
25: import javax.activation.DataSource;
26:
27: public class ByteDataSource implements DataSource {
28: private String contentType;
29: private String name;
30: private byte[] data;
31: private int offset;
32: private int length;
33:
34: public ByteDataSource(byte[] dataParam) {
35: this (dataParam, 0, dataParam.length);
36: }
37:
38: public ByteDataSource(byte[] dataParam, int offsetParam,
39: int lengthParam) {
40: this .data = dataParam;
41: this .offset = offsetParam;
42: this .length = lengthParam;
43: }
44:
45: public byte[] getData() {
46: return data;
47: }
48:
49: public void setData(byte[] dataParam) {
50: this .data = dataParam;
51: }
52:
53: public void setContentType(String contentTypeParam) {
54: this .contentType = contentTypeParam;
55: }
56:
57: public void setName(String nameParam) {
58: this .name = nameParam;
59: }
60:
61: public String getContentType() {
62: return contentType;
63: }
64:
65: public InputStream getInputStream() throws IOException {
66: return new ByteArrayInputStream(data, offset, length);
67: }
68:
69: public String getName() {
70: return name;
71: }
72:
73: public OutputStream getOutputStream() throws IOException {
74: return null;
75: }
76:
77: }
|