1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache license, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the license for the specific language governing permissions and 15 * limitations under the license. 16 */ 17 package org.apache.logging.log4j.core.layout; 18 19 import java.nio.ByteBuffer; 20 21 /** 22 * ByteBufferDestination is the destination that {@link Encoder}s write binary data to. It encapsulates a 23 * {@code ByteBuffer} and a {@code drain()} method the producer can call when the {@code ByteBuffer} is full. 24 * <p> 25 * This interface allows a producer to write arbitrary amounts of data to a destination. 26 * </p> 27 * @since 2.6 28 */ 29 public interface ByteBufferDestination { 30 /** 31 * Returns the buffer to write to. 32 * 33 * @return the buffer to write to 34 */ 35 ByteBuffer getByteBuffer(); 36 37 /** 38 * Consumes the buffer content and returns a buffer with more {@linkplain ByteBuffer#remaining() available} space 39 * (which may or may not be the same instance). 40 * <p> 41 * Called by the producer when buffer becomes too full to write to. 42 * 43 * @param buf the buffer to drain 44 * @return a buffer with more available space (which may or may not be the same instance) 45 */ 46 ByteBuffer drain(ByteBuffer buf); 47 }