blob: c28a2b835087988263d12e7d37caf85863a4bcef [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.axiom.attachments;
import org.apache.axiom.attachments.utils.BAAInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import javax.activation.DataSource;
/**
* Stores the content of a MIME part in memory (in non-contiguous byte arrays). This implementation
* is used for smaller attachments to enhance performance.
*
* @see PartContentFactory
*/
class PartContentOnMemory extends PartContent {
private final ArrayList data; // Arrays of 4K buffers
private final int length; // total length of data
/**
* Constructor.
*
* @param data
* a list of 4K byte arrays
* @param length
* the total length of the data in bytes
*/
PartContentOnMemory(ArrayList data, int length) {
this.data = data;
this.length = length;
}
InputStream getInputStream() {
return new BAAInputStream(data, length);
}
DataSource getDataSource(String contentType) {
// Use a default implementation
return null;
}
void writeTo(OutputStream os) throws IOException {
new BAAInputStream(data, length).writeTo(os);
}
long getSize() {
return length;
}
void destroy() throws IOException {
data.clear();
}
}