| Home >> All >> org >> apache >> axis >> [ attachments Javadoc ] |
Source code: org/apache/axis/attachments/PlainTextDataSource.java
1 /* 2 * Copyright 2001-2004 The Apache Software Foundation. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.apache.axis.attachments; 17 18 import javax.activation.DataSource; 19 import java.io.ByteArrayInputStream; 20 import java.io.ByteArrayOutputStream; 21 import java.io.IOException; 22 import java.io.InputStream; 23 import java.io.OutputStream; 24 25 public class PlainTextDataSource implements DataSource { 26 public static final String CONTENT_TYPE = "text/plain"; 27 28 private final String name; 29 private byte[] data; 30 private ByteArrayOutputStream os; 31 32 public PlainTextDataSource(String name, String data) { 33 this.name = name; 34 this.data = data == null ? null : data.getBytes(); 35 os = new ByteArrayOutputStream(); 36 } // ctor 37 38 public String getName() { 39 return name; 40 } // getName 41 42 public String getContentType() { 43 return CONTENT_TYPE; 44 } // getContentType 45 46 public InputStream getInputStream() throws IOException { 47 if (os.size() != 0) { 48 data = os.toByteArray(); 49 } 50 return new ByteArrayInputStream(data == null ? new byte[0] : data); 51 } // getInputStream 52 53 public OutputStream getOutputStream() throws IOException { 54 if (os.size() != 0) { 55 data = os.toByteArray(); 56 } 57 return new ByteArrayOutputStream(); 58 } // getOutputStream 59 } // class PlainTextDataSource