All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.camel.StreamCache Maven / Gradle / Ivy

There is a newer version: 4.6.0
Show newest version
/**
 * 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.camel;

import java.io.IOException;
import java.io.OutputStream;

/**
 * Tagging interface to indicate that a type is capable of caching the underlying data stream.
 * 

* This is a useful feature for avoiding message re-readability issues. * This interface is mainly used by the {@link org.apache.camel.spi.StreamCachingStrategy} * for determining if/how to wrap a stream-based message. *

* The Camel routing engine uses the {@link org.apache.camel.processor.CamelInternalProcessor.StreamCachingAdvice} * to apply the stream cache during routing. *

* It is recommended in the {@link #copy(Exchange)} method to let the copied stream start from the start. If the implementation * does not support copy, then return null. * * @version */ public interface StreamCache { long DEFAULT_SPOOL_THRESHOLD = 128 * 1024; /** * Resets the StreamCache for a new stream consumption. */ void reset(); /** * Writes the stream to the given output * * @param os the destination to write to * @throws java.io.IOException is thrown if write fails */ void writeTo(OutputStream os) throws IOException; /** * Create a copy of the stream. If possible use the same cached data in the * copied instance. *

* This method is useful for parallel processing. *

* Implementations note: A copy of the stream is recommended to read from the start * of the stream. * * @param exchange exchange in which the stream cache object is used; * can be used to delete resources of the stream cache when the exchange is completed * @return a copy, or null if copy is not possible * @throws java.io.IOException is thrown if the copy fails */ StreamCache copy(Exchange exchange) throws IOException; /** * Whether this {@link StreamCache} is in memory only or * spooled to persistent storage such as files. */ boolean inMemory(); /** * Gets the length of the cached stream. *

* The implementation may return 0 in cases where the length * cannot be computed, or if the implementation does not support this. * * @return number of bytes in the cache. */ long length(); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy